TFJS 中的 GradCam 实现

GradCam Implementation in TFJS

我正在尝试实现 GradCam (https://arxiv.org/pdf/1610.02391.pdf) in tfjs, based on the following Keras Tutorial (http://www.hackevolve.com/where-cnn-is-looking-grad-cam/) and a simple image classification demo from tfjs, similar to (https://github.com/tensorflow/tfjs-examples/blob/master/webcam-transfer-learning/index.js),最后有一个简单的密集全连接层。

但是,我无法检索 gradcam 计算所需的梯度。我尝试了不同的方法来检索最后一个顺序层的渐变,但没有成功,因为来自相应层的 tf.LayerVariable 类型无法转换为相应类型的 tf.grads 或 tf.layerGrads。

有没有人已经成功地将渐变从顺序层获取到 tf.function 类对象?

我不知道实施的来龙去脉,但我认为大致如下:http://jlin.xyz/advis/ 是您要查找的内容吗?

此处提供源代码:https://github.com/jaxball/advis.js(不是我的!)

tfjs-examples 存储库中的这个官方示例应该接近(如果不是完全)您想要的:

https://github.com/tensorflow/tfjs-examples/blob/master/visualize-convnet/cam.js#L49