pytorch-grad-cam icon indicating copy to clipboard operation
pytorch-grad-cam copied to clipboard

How to use gradcam for Retinanet

Open Monk5088 opened this issue 2 years ago • 0 comments
trafficstars

Hey Jacob, I have been trying to use your notebook of Rcnn for the object detection model (Retinanet in my case). Here is the implementation that I use(FASTAI):


backbone = "ResNet50" #["ResNet18", "ResNet34", "ResNet50", "ResNet101", "ResNet150"]

backbone_model = models.resnet18
if backbone == "ResNet34":
    backbone_model = models.resnet34
if backbone == "ResNet50":
    backbone_model = models.resnet50
if backbone == "ResNet101":
    backbone_model = models.resnet101
if backbone == "ResNet150":
    backbone_model = models.resnet150

pre_trained_on_imagenet = False
encoder = create_body(models.resnet50, pre_trained_on_imagenet, -2)


loss_function = "FocalLoss" 

if loss_function == "FocalLoss":
    crit = RetinaNetFocalLoss(anchors)


channels = 128 


final_bias = -4 


n_conv = 3 
model3 = RetinaNet(encoder, n_classes=data.train_ds.c, 
                  n_anchors=len(scales) * len(ratios), 
                  sizes=[size[0] for size in sizes], 
                  chs=channels, # number of hidden layers for the classification head
                  final_bias=final_bias,
                  n_conv=n_conv # Number of hidden layers
                  )
learn3 = Learner(data, model3, loss_func=crit, 
                callback_fns=[BBMetrics,ShowGraph,CSVLogger,partial(GradientClipping, clip=2.0)],metrics=[voc]) 

I have a model saved in the form .pth file, now how can I implement your gradcam on it? Thanks and regards, Harshit

Monk5088 avatar Feb 07 '23 05:02 Monk5088