<jupyter_start><jupyter_text>Interpreting ResNet Model With GradCAM Interpretations of the predictions are generated and visualized using Gradient CAM algorithm, specifically the `GradCAMInterpreter` class.<jupyter_code>from PIL import Image
import paddle
import interpretdl as it
from interpretdl.data_processor.readers import read_image
# load from paddle.vision

from paddle.vision.models import resnet50
paddle_model = resnet50(pretrained=True)<jupyter_output>/Users/yuantingyi/opt/anaconda3/envs/paddle2/lib/python3.7/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)<jupyter_text>Initialize the `GradCAMInterpreter`.<jupyter_code>gradcam = it.GradCAMInterpreter(paddle_model, use_cuda=False)<jupyter_output><empty_output><jupyter_text>Before interpreting the image, we first take a look at the original image.<jupyter_code>img_path = 'assets/catdog.png'
x = Image.fromarray(read_image(img_path)[0])
x<jupyter_output><empty_output><jupyter_text>Then, let Gradient CAM method helps us `interpret` the image with respect to the predicted label, which is bull mastiff. We choose the last layer as the target layer.  show feature_map name<jupyter_code>layers_name = []
for n, v in paddle_model.named_sublayers():
    layers_name.append(n)
print(layers_name)
heatmap = gradcam.interpret(
        img_path,
        'layer4.2.conv3',
        label=None,
        visual=True,
        save_path=None)<jupyter_output>/Users/yuantingyi/opt/anaconda3/envs/paddle2/lib/python3.7/site-packages/paddle/fluid/dygraph/varbase_patch_methods.py:379: UserWarning: [93m
Warning:
tensor.grad will return the tensor value of the gradient. [0m
  warnings.warn(warning_msg)<jupyter_text>Let's see what happens if our target label is 282 (tiger cat.)<jupyter_code>heatmap = gradcam.interpret(
        img_path,
        'layer4.2.conv3',
        label=282,
        visual=True,
        save_path=None)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08584474885844749, 'fraction_numerical': 0.016894977168949773, 'mean_word_length': 5.63939393939394, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '448034', 'license': 'Apache-2.0', 'n_tokens_mistral': 737, 'n_tokens_neox': 701, 'n_words': 170, 'path': 'tutorials/grad_cam_tutorial_cv.ipynb', 'repo_name': 'Wgm-Inspur/InterpretDL', 'size': '2190'}