I’m trying to use GradCam (https://github.com/jacobgil/pytorch-grad-cam 2) on my Densenet121 model, but am running into a size mismatch error I do not understand how to resolve. I am a beginner, so I believe I’m just missing something marginal.
image903×268 134 KB
I’m using the pretrained Densenet121 model from torchvision. I did not have any problems running the code with the Resnet50 model that was provided, but I am unable to adapt the code to work with my model.
model = pretrainedmodels.__dict__['densenet121'](num_classes=1000,pretrained='imagenet')
            dim_feats = model.last_linear.in_features
            model.last_linear = nn.Sequential(nn.Linear(dim_feats, 3))
grad_cam = GradCam(model=model, feature_module=model.__dict__['_modules']['features'].denseblock4, target_layer_names=['denselayer16'], use_cuda=args.use_cuda)

Thanks in advance for any help.