Tensorflow2.0 卷积神经网络可视化 (三)类激活热力图 (CAM,class activation map)

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在神经网络分别中,我们不仅想知道最终预测结果,还需要了解网络是凭借图像什么特征进行判断的。其中类激活热力图 (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=
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值