pytorch-image-models icon indicating copy to clipboard operation
pytorch-image-models copied to clipboard

How to adjust the size of the image

Open ratom opened this issue 2 years ago • 0 comments

from torchvision.models.feature_extraction import create_feature_extractor import random import seaborn as sns import matplotlib.pyplot as plt

return_nodes = ['blocks.0', 'blocks.10', 'blocks.20', 'blocks.23']

feat_ext = create_feature_extractor(model, return_nodes=return_nodes)

with torch.no_grad(): out = feat_ext(inps[0])

fig, ax = plt.subplots(4, 5, figsize=(25, 20))

Pick 4 random feature maps from each layer

for i, layer in enumerate(return_nodes): feat_maps = out[layer].numpy().squeeze(0) feat_maps = random.sample(list(feat_maps), 4) ax[i][0].imshow(imgs[0]) ax[i][0].set_xticks([]) ax[i][0].set_yticks([]) for j, feat_map in enumerate(feat_maps): sns.heatmap(feat_map, ax=ax[i][j+1], cbar=False) ax[i][j+1].set_xticks([]) ax[i][j+1].set_yticks([]) ax[i][j+1].set_title(f'{layer}: ({feat_map.shape[0]} x {feat_map.shape[1]})')

Got this error

IndexError Traceback (most recent call last) in 21 ax[i][0].set_yticks([]) 22 for j, feat_map in enumerate(feat_maps): ---> 23 sns.heatmap(feat_map, ax=ax[i][j+1], cbar=False) 24 ax[i][j+1].set_xticks([]) 25 ax[i][j+1].set_yticks([])

3 frames /usr/local/lib/python3.8/dist-packages/numpy/ma/core.py in masked_where(condition, a, copy) 1927 (cshape, ashape) = (cond.shape, a.shape) 1928 if cshape and cshape != ashape: -> 1929 raise IndexError("Inconsistent shape between the condition and the input" 1930 " (got %s and %s)" % (cshape, ashape)) 1931 if hasattr(a, '_mask'):

IndexError: Inconsistent shape between the condition and the input (got (1024, 1) and (1024,))

ratom avatar Jan 05 '23 11:01 ratom