Tensorflow 用Python重塑图像和绘图
我正在研究mnist_时尚数据。mnist_数据中的图像为28x28像素。为了将数据输入神经网络(多层感知器),我将数据转换成(784,)形状 此外,我需要再次将其重塑为原始尺寸 为此,我使用了以下给定代码:-Tensorflow 用Python重塑图像和绘图,tensorflow,keras,deep-learning,neural-network,mnist,Tensorflow,Keras,Deep Learning,Neural Network,Mnist,我正在研究mnist_时尚数据。mnist_数据中的图像为28x28像素。为了将数据输入神经网络(多层感知器),我将数据转换成(784,)形状 此外,我需要再次将其重塑为原始尺寸 为此,我使用了以下给定代码:- from keras.datasets import fashion_mnist import numpy as np import matplotlib.pyplot as plt (train_imgs,train_lbls), (test_imgs, test_lbls) =
from keras.datasets import fashion_mnist
import numpy as np
import matplotlib.pyplot as plt
(train_imgs,train_lbls), (test_imgs, test_lbls) = fashion_mnist.load_data()
plt.imshow(test_imgs[0].reshape(28,28))
no_of_test_imgs = test_imgs.shape[0]
test_imgs_trans = test_imgs.reshape(test_imgs.shape[1]*test_imgs.shape[2], no_of_test_imgs).T
plt.imshow(test_imgs_trans[0].reshape(28,28))
不幸的是,我没有得到类似的图像。我无法理解为什么会发生这种情况
预期图像:
接收图像:
请帮助我解决此问题。在
测试\u imgs\u trans中展平图像时请注意。
(train_imgs,train_lbls), (test_imgs, test_lbls) = tf.keras.datasets.fashion_mnist.load_data()
plt.imshow(test_imgs[0].reshape(28,28))
no_of_test_imgs = test_imgs.shape[0]
test_imgs_trans = test_imgs.reshape(no_of_test_imgs, test_imgs.shape[1]*test_imgs.shape[2])
plt.imshow(test_imgs_trans[0].reshape(28,28))
别忘了接受答案并投票;-)谢谢。这就解决了问题。我真的不确定问题是否是由于我重新调整输入的方式造成的。