I used forward hook like this:
# dataset_root = dset.ImageFolder('E:........', transform=Compose([Resize((224,224)),ToTensor(), transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])]))

class_names = dataset_root.class_to_idx
print(dict(Counter(dataset_root.targets)))

A_dset = Subset(dataset_root,   range(0, 826))
classA_loader = DataLoader(A_dset, batch_size=1, shuffle = False)

def get_activation(name):
    def hook(model, input, output):
        activation[name] = output.detach()
    return hook

trained_model.classifier[6] = nn.Linear(trained_model.classifier[6].in_features, 1)
trained_model.classifier[6].register_forward_hook(get_activation('fc3'))

# placeholders
PREDS = []

# loop through batches
for idx, inputs in enumerate(glioma_tumor_loader):

    # move to device
    inputs = inputs.to(device)
       
    # forward pass [with feature extraction]
    preds = trained_model(inputs)
    
    # add feats and preds to lists
    PREDS.append(preds.detach().cpu().numpy())

##### INSPECT FEATURES

PREDS = np.concatenate(PREDS)
print('- preds shape:', PREDS.shape)


I follow the link here. since I interested in the last layer I used PREDS.
Does the code above right when you said using hook method
when I run the code I got this error
  # move to device
---> 17     inputs = inputs.to(device)
     18 
     19     # forward pass [with feature extraction]

AttributeError: 'list' object has no attribute 'to'