用Python重塑图像和绘图

问题描述 投票:0回答:1

我正在研究mnist_fashion数据。mnist_data中的图片是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) = 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))

不幸的是,我没有得到类似的图像。我无法理解为什么会发生这种情况。

期待的图像。enter image description here

收到的图像。enter image description here

请帮助我解决这个问题。

tensorflow keras deep-learning neural-network mnist
1个回答
1
投票

当你将图像平铺在 test_imgs_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))
© www.soinside.com 2019 - 2024. All rights reserved.