<jupyter_start><jupyter_text>Interpreting ResNet Model With Smooth Gradients This notebook loads the pretrained ResNet model given by [PaddleClas](https://github.com/PaddlePaddle/PaddleClas/tree/release/2.0) and performs image classification on selected images. Interpretations of the predictions are generated and visualized using Consensus algorithm, specifically the `ConsensusInterpreter` class.<jupyter_code>import paddle
import interpretdl as it<jupyter_output><empty_output><jupyter_text>Before interpreting the image, we first take a look at the original image.<jupyter_code>from PIL import Image
from interpretdl.data_processor.readers import read_image

img_path = 'assets/deer.png'
x = Image.fromarray(read_image(img_path)[0])
x
import interpretdl as it
from paddle.vision.models import resnet34, resnet50, resnet101, mobilenet_v2

# Here we use four models to give an illustration. Using more models shows more impressive results.
list_models = {
    'resnet34': resnet34(pretrained=True), 
    'resnet50': resnet50(pretrained=True),
    'resnet101': resnet101(pretrained=True), 
    'mobilenet_v2': mobilenet_v2(pretrained=True)
}
consensus = it.ConsensusInterpreter(it.SmoothGradInterpreter, list_models.values(), device='gpu:0')
img_path = '/root/codespace/InterpretDL/tutorials/assets/deer.png'
exp = consensus.interpret(img_path)
import numpy as np
import matplotlib.pyplot as plt

cols = len(list_models) + 1
psize = 4
fig, ax = plt.subplots(1, cols, figsize=(cols*psize, 1*psize))

for axis in ax:
    axis.axis('off')

for i in range(len(list_models)):
    ax[i].imshow(np.abs(exp[i]).sum(0))
    ax[i].set_title(list(list_models.keys())[i])

ax[-1].imshow(np.abs(exp).sum(1).mean(0))
ax[-1].set_title('Consensus')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11224489795918367, 'fraction_numerical': 0.020975056689342405, 'mean_word_length': 6.384937238493724, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '265430', 'license': 'Apache-2.0', 'n_tokens_mistral': 614, 'n_tokens_neox': 590, 'n_words': 143, 'path': 'tutorials/consensus_tutorial_cv.ipynb', 'repo_name': 'Wgm-Inspur/InterpretDL', 'size': '1764'}