I have a MNIST Sign Language dataset with pixel values as columns.
当我尝试在其中一个索引处绘制图像时出现错误,如下所示:
#Training dataset
dfr = pd.read_csv("sign_mnist_train.csv")
X_train_orig = dfr.iloc[:,1:]
Y_train_orig = dfr['label']
#Testing dataset
dfe = pd.read_csv("sign_mnist_test.csv")
X_test_orig = dfe.iloc[:,1:]
Y_test_orig = dfe['label']
#shapes of dataset
print(dfr.shape) #(27455, 785)
print(dfe.shape) #(7172, 785)
#Example of a picture
index = 1
plt.imshow(X_train_orig.iloc[index])
#TypeError: Invalid shape (784,) for image data
发布于 2020-02-14 01:07:53
看起来您试图绘制的图像是一个与B,N对应的平面图,其中N是1x28x28,B是27455,这是您的图像大小(27455,784)。如果您想要将其馈送到784长向量的线性层,这是很好的。要绘制此图像,您必须将其重塑为对应于27455、1、28、28。你可以试试这个:
image = X_train_orig.iloc[index]
image = np.reshape(image.values, (28, 28))
plt.imshow(image)
https://stackoverflow.com/questions/60064887
复制相似问题