haofanwang / Score-CAM

Official implementation of Score-CAM in PyTorch
MIT License
399 stars 66 forks source link

How to visualize my own model? #2

Closed alwayslj closed 3 years ago

haofanwang commented 4 years ago

Hi @alwayslj, you can refer to basecam.py. If your model is not in torchvision.models, you may need to modify the find_layer function to suit your own model. Please let me know if you have any trouble.

I will add an example to support self-defined model soon.

abhigoku10 commented 4 years ago

@haofanwang for a models like Faster RCNN and MaskRCNN which layer_name should be passed ??

haofanwang commented 4 years ago

Hi, @abhigoku10, you are free to select a feature layer, for example, the last conv layer. You can directly print the model and get the name of a specific layer.

abhigoku10 commented 4 years ago

@haofanwang does this principle work even for object detection architectures ?? there should be some modifications for this right

haofanwang commented 4 years ago

@abhigoku10 As far as I know, detection model usually has a classification branch. So you can use the middle feature as the activation map, and the classification score as weight. You can treat it as a self-defined model, the only thing you need to modify is to hook the activation output (this file).

abhigoku10 commented 4 years ago

@haofanwang thanks for the response I was able to hardcode the layer which i required and was able to get the activation map from it but to pass the classification score as weight how to do it since mine is detection/segmentation model I directly get the probability scores should I pass these values as weight

haofanwang commented 4 years ago

@abhigoku10 Yes, you can try to use the probability score as weight, but I'm not sure whether it works well.