python - 将 Softmax 的输出捕获到 Tensorflow 中的图像中
问题描述
在 TensorFlow 图像处理方面需要一些帮助。
我正在探索 kovid 上的一个开源项目 - https://github.com/lindawangg/COVID-Net
我能够成功下载模型并成功运行预测。因此,当我inference.py
在示例中运行时,它会生成完美的输出。
然而,我试图实现的是,从完成的匹配中生成热图,如图所示。尽管尝试了许多可能性,但我对实现这一点一无所知。
这些是我的理解,他们使用带有 logit 函数的 Softmax 来找出匹配的概率。有了这个假设,我写了一个类似的代码
x = process_image_file(img, 0.08, 480)
x = x.astype('float32') / 255.0
pred = sess.run(pred_tensor, feed_dict={
image_tensor: np.expand_dims(x, axis=0)
})
g1 = tf.gradients(pred_tensor, image_tensor)
sess.run(g1)
在哪里
g1 = tf.gradients(pred_tensor, image_tensor)
sess.run(g1)
这是我为生成梯度输出添加的代码,但是这会失败并出现类似的错误
[2020-05-24 00:06:39,922] ERROR in app: Exception on /predict/ [POST]
Traceback (most recent call last):
File "/mnt/g/TS/covid/COVID-Net/venv/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1365, in _do_call
return fn(*args)
File "/mnt/g/TS/covid/COVID-Net/venv/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1350, in _run_fn
target_list, run_metadata)
File "/mnt/g/TS/covid/COVID-Net/venv/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1443, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'input_1' with dtype float and shape [?,480,480,3]
[[{{node input_1}}]]
请帮忙.. 我对 ML、Tensorflow 和 python 完全陌生,所以如果这个问题看起来非常愚蠢,请原谅我!
解决方案
推荐阅读
- azure-active-directory - 将自定义角色分配给 Azure Active Directory System 托管标识
- docker - 无法将 docker_module playbook 运行到 Jenkins 管道中的远程服务器
- python - 我一直在用我自己的例子在 python 中练习星搜索算法,但是我的算法的答案是错误的
- bash - Gnome-terminal:-e 和 -- 之间的区别?
- node.js - 与 Node 在生产中不工作的反应
- ruby - 在 ImageMagick / RMagick 中检测不透明像素的最有效方法
- sql - 使用参数限制 Microsoft Access 中返回的行数
- python-3.x - 如何使用beautifulsoup从加载了javascript的站点中获取数据
- presto - 从旧版本 Presto 中的日期开始的周开始日期
- amazon-web-services - Codedeploy 代理巨大的内存消耗