我试图可视化CNN模型的每个输出的Gradcam激活图,带有多个输出。问题是如何实现“损失函数”?我指的是这个代码
更清楚地说,问题是如何可视化output1、output2、output3的渐变图
范例 定义损失函数: 必须定义返回目标分数的损失函数。在这里,它返回相应的分数 金鱼,熊,突击步枪
# The `output` variable refer to the output of the model,
# so, in this case, `output` shape is `(3, 1000)` i.e., (samples, classes).
def loss(output):
return (output[0][1], output[1][294], output[2][413])
# 1 is the imagenet index corresponding to Goldfish, 294 to Bear and 413 to Assault Rifle.
这里,我将展示可用于获取多输出网络的类激活映射(CAM)的简单代码库。首先,我们将从MNIST创建一个多输出数据集。我将从here借用一些代码
资料
模型
建立CAM模型
让我们检查基础模型中的一些层
在这里,我们喜欢选择
block5_conv2
卷积层来获得特征图。让我们快速检查一下它的配置现在,让我们构建CAM模型,如下所示:
现在从该CAM模型中获得预测:
可视化凸轮
绘制图表
相关问题 更多 >
编程相关推荐