首页 > 解决方案 > 将 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 完全陌生,所以如果这个问题看起来非常愚蠢,请原谅我!

标签: pythonopencvtensorflowtensorflow-gradient

解决方案


推荐阅读