These are my full code, in case you don’t want to go to Colab.
!wget https://download.pytorch.org/tutorial/hymenoptera_data.zip
!unzip -q hymenoptera_data.zip

data_transforms = transforms.Compose([
                             transforms.RandomResizedCrop(224),
                             transforms.ToTensor()])
data_dir = 'hymenoptera_data//train'
image_datasets = datasets.ImageFolder(os.path.join(data_dir), transform=data_transforms)
dataloaders = torch.utils.data.DataLoader(image_datasets, batch_size=4, num_workers=4)

model_ft = models.resnet18(pretrained=True)
model_ft.fc = nn.Linear(model_ft.fc.in_features, 2) #  size of each output is set to 2

dat, lab = next(iter(dataloaders))


total_feat_out = []

def hook_fn_forward(module, input, output):
    total_feat_out.append(output) 
    print(output.shape)

modules = model_ft.named_children()
for name, module in modules:
    module.register_forward_hook(hook_fn_forward)

model_ft.eval() 
with torch.no_grad():
    pred = model_ft(dat)