【问题标题】:Reshaping image and Plotting in Python在 Python 中重塑图像和绘图
【发布时间】:2020-10-05 13:42:47
【问题描述】:

我正在处理 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))

很遗憾,我没有得到类似的图像。我无法理解为什么会这样。

预期图片:

收到的图片:

请帮我解决问题。

【问题讨论】:

  • 别忘了接受答案并点赞 ;-)

标签: tensorflow keras deep-learning neural-network mnist


【解决方案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))

【讨论】:

  • 非常感谢。这解决了问题。我真的不确定问题是由于我重塑输入的方式造成的。
猜你喜欢
  • 2017-05-29
  • 2021-10-15
  • 1970-01-01
  • 1970-01-01
  • 2023-02-14
  • 2020-10-28
  • 2012-04-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多