【问题标题】:How can I print feature map image in tensorflow?如何在张量流中打印特征图图像?
【发布时间】:2019-05-09 05:29:01
【问题描述】:

我是一名学习深度学习的学生,使用tensorflow进行分类。

我只有一个问题。如何打印特征图图像?

我成功将张量类型数据转换为numpy.ndarray类型数据。

LIKE THIS -> C8: Tensor("C8:0", shape=(0, 7, 7, 0), dtype=float32) 转换为数组。)

但是,我无法显示此特征图。

第一种方式:使用 matplotlib.pyplot 模块

ep, temp_array, weight_1 = sess.run([tf.argmax(result, 1), c8, wfc1], feed_dict={X: ex, istraining.name: False, keep_prob: 1.0})

print(type(temp_array), temp_array.shape, "\n", temp_array[0, :, :, 0])

img = plt.imread(temp_array[0, :, :, 0])
plt.imshow(img)
plt.show()

特征图在 temp_array 变量中。它(ndarray 类型)就像那个图像一样打印出来。

我有错误消息。

Traceback (most recent call last):
  File "D:/3Laaaaab/DC/hand_recog_demo_1.py", line 352, in <module>
    img = plt.imread(temp_array[0, :, :, 0])
  File "c:\users\administrator\appdata\local\programs\python\python36\lib\site-packages\matplotlib\pyplot.py", line 2152, in imread
    return matplotlib.image.imread(fname, format)
  File "c:\users\administrator\appdata\local\programs\python\python36\lib\site-packages\matplotlib\image.py", line 1369, in imread
    return handler(fname)
TypeError: Object does not appear to be an 8-bit string path or a Python file-like object

第二种方式:使用cv2模块

ep, temp_array, weight_1 = sess.run([tf.argmax(result, 1), c8, wfc1], feed_dict={X: ex, istraining.name: False, keep_prob: 1.0})

print(type(temp_array), temp_array.shape, "\n", temp_array[0, :, :, 0])

cv2.imshow("windows", temp_array[0, :, :, 0])
cv2.waitKey(1)

是的,这个来源运行良好,但我有一个问题。

也就是说,生成的图像太小了。所以我看不到。

如何才能完美地看到特征图?

【问题讨论】:

    标签: python tensorflow matplotlib deep-learning


    【解决方案1】:

    plt.imread() is to read a picture file from the disk (for ex a jpg or png file).

    错误清楚地表明是该指令引发了错误,并且该函数需要路径(作为字符串)或类似文件的对象,而不是您尝试执行的数组。

    由于您的数组已经在内存中,您不需要使用该指令。好像

    ep, temp_array, weight_1 = sess.run([tf.argmax(result, 1), c8, wfc1], feed_dict={X: ex, istraining.name: False, keep_prob: 1.0})
    plt.imshow(temp_array[0, :, :, 0])
    plt.show()
    

    应该够了吗?

    【讨论】:

      猜你喜欢
      • 2021-04-11
      • 2019-07-01
      • 2018-05-03
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      • 1970-01-01
      • 2014-09-12
      • 2021-02-18
      相关资源
      最近更新 更多