【发布时间】:2016-05-31 08:16:44
【问题描述】:
我有一个一维 numpy 数组。在 TensorFlow 中执行计算后,我得到一个 tf.Tensor 作为输出。我正在尝试将其重塑为二维数组并将其显示为图像。
如果它是一个 numpy ndarray,我会知道如何将其绘制为图像。但它现在是张量!
虽然我尝试tensor.eval() 将其转换为 numpy 数组,但我收到一条错误消息“无默认会话”。
谁能教我如何将张量显示为图像?
... ...
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
# training
for i in range(1):
sess.run(train_step, feed_dict={x: x_data.T, y_: y_data.T})
# testing
probability = tf.argmax(y,1);
sess.run(probability, feed_dict={x: x_test.T})
#show result
img_res = tf.reshape(probability,[len_y,len_x])
fig, ax = plt.subplots(ncols = 1)
# It is the the following line that I do not know how to make it work...
ax.imshow(np.asarray(img_res.eval())) #how to plot a tensor ?#
plt.show()
... ...
【问题讨论】:
-
欢迎使用 stackoverflow。您可以发布您的尝试吗?
-
请用良好的缩进更新问题。见stackoverflow.com/help/how-to-ask 会更容易得到答案
-
对不起,不熟悉这个..刚刚更新
标签: python arrays image numpy tensorflow