Hi I have problem in visualize the features from pretrained model. I loaded data from image not from loaders but it’s showing dimension error
‘’’# Visualize feature maps
activation = {}
def get_activation(name):
def hook(model, input, output):
activation[name] = output.detach()
return hook

model.features[0].register_forward_hook(get_activation(‘features[0]’))
img_path = ‘data/hymenoptera_data/test/terrorist/3.jpeg’
bgr_img = cv2.imread(img_path)
device = torch.device(“cuda:0” if torch.cuda.is_available() else “cpu”)
Normalise
data = bgr_img.astype(“float32”)/255
data=torch.from_numpy(data).float().to(device)
print(data.size())
print (data.size())
output = model(data.cpu())
act = activation[‘features[0]’].squeeze()
fig, axarr = plt.subplots(act.size(0))
for idx in range(act.size(0)):
axarr[idx].imshow(act[idx])
plt.show()
RuntimeError: Expected 4-dimensional input for 4-dimensional weight 64 3 3, but got 3-dimensional input of size [168, 300, 3] instead
Can anyone please help me?