tensorflow - 在 Python 中重塑图像和绘图
问题描述
我正在处理 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))
不幸的是,我没有得到类似的图像。我无法理解为什么会这样。
请帮助我解决问题。
解决方案
将图像展平时请注意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))
推荐阅读
- element - 闭合轮廓的定向区域,由线段(曲线)组成
- excel - VBA在联合中选择多列
- angular - Angular ng-bootstrap ngbNav 组件选项卡内容未显示在导航选项卡上单击
- javascript - 从对象数组中删除重复项并在 JavaScript 中添加新值(例如数量)
- javascript - 如何将 int 从 html 文件(模板)传递给 py 文件(flask)?
- react-native - React Navigation Stack 导航转换
- python - 如何获取子列表中某个单词的索引?
- c - 在函数中释放内存与在同一范围内
- java - 无法使用 Retrofit2 获取数据
- java - 如何用用户数据填充导航抽屉