【发布时间】: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