在神经网络分别中,我们不仅想知道最终预测结果,还需要了解网络是凭借图像什么特征进行判断的。其中类激活热力图 (CAM,class activation map)就是一种很好的呈现方式。
目录标题
类激活热力图 (CAM,class activation map)
导入ImageNet VGG16网络
导入基础包
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
导入ImageNet VGG16网络
VGG16_model = tf.keras.applications.VGG16(include_top=True)
VGG16_model.summary()
加载任一图片
随便网上找一张图,比如使用率最高的猫星人

加载对应网络的图像处理方法,以及类别解码表
读取本地图片
from tensorflow.keras.applications.vgg16 import preprocess_input, decode_predictions
def prepocess(x):
x = tf.io.read_file(x)
x = tf.image.decode_jpeg(x, channels=3)
x = tf.image.resize(x, [224,224])
x =tf.expand_dims(x, 0) # 扩维
x = preprocess_input(x)
return x
img_path='cat.jpg'
img=prepocess

本文介绍了如何使用Tensorflow2.0进行类激活热力图(CAM)的实现,通过VGG16网络对图像进行预测并可视化网络关注的特征。实验表明,网络在识别埃及猫、虎斑猫和Tabby猫时,关注的特征分别是耳朵、眼部和嘴及斑纹。
最低0.47元/天 解锁文章
2444





