在学习Mnist手写数据集的时候,遇到这种问题。使用Tensorflow2.2-gpu版本
plt.figure(figsize=(20, 4))
for i in range(1, n):
ax = plt.subplot(2, n, i)
plt.imshow(x_test[i].reshape(28, 28))
ax = plt.subplot(2, n, i + n)
plt.imshow(decode_test[i].reshape(28, 28))
出现这种问题:
AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'reshape'
解决办法:用Numpy库读取一下再reshape。
n = 10
plt.figure(figsize=(20, 4))
for i in range(1, n):
ax = plt.subplot(2, n, i)
plt.imshow(np.array(x_test[i]).reshape(28, 28))
ax = plt.subplot(2, n, i + n)
plt.imshow(np.array(decode_test[i]).reshape(28, 28))
输出:



