I followed the “Visualizing Decisions of Convolutional Neural Networks”, and it gives the correct output images when using vgg16 pretrained model. ThenI changed the network to ResNet50v2 with its pretrained model, but the output images looks abnormal, Some code snippet are as follow.
# ResNetV2 using gradcam's Conv2D and Activation net = ResNetV2(BottleneckV2, layers, channels, **kwargs) net.initialize(ctx=ctx) resnet50v2 = mx.gluon.model_zoo.vision.resnet50_v2() # load pretrain model resnet50v2.load_parameters('D:/Model/mxnet/models/resnet50_v2-ecdde353.params', ctx=ctx) params = resnet50v2.collect_params() for key in params: param = params[key] net.collect_params()[net.prefix + key.replace(resnet50v2.prefix, '')].set_data(param.data()) # ... last_conv_layer_name = net.features.conv3.name show_images(*visualize(network, "hummingbird.jpg", last_conv_layer_name))
The upper row uses resnet pretrained model, and the lower row uses vgg16 model
Update on 23th, Jan
I try to output the imggrad without recording gradient of conv layer, because the detail is recovered only using img grad, in this situation, only Activation layer(Relu) is rewritten. The result is correct when using vgg16, , but if using resnet, the imggrad is also unclear.