【发布时间】:2020-06-16 04:55:38
【问题描述】:
我将 [Kaggle 数据集][1] 用于 mnist 手语。总共有 785 列,包括带有 CSV 数据集标签的一列。将 CSV 用于图像而不是真实图像也是一个好主意
以下代码运行良好,直到 mode.fit() 出错
"""CSV_MODEL.ipynb
Automatically generated by Collaboratory.
The original file is located at
https://colab.research.google.com/drive/1u8GDJe-sWtz12YO7YusClJR9UeDJ852Y
"""
from google.colab import files
uploaded = files.upload()
from keras.models import Sequential
from keras.layers import Dense
import numpy
numpy.random.seed(23)
import csv
import numpy
filename = 'sign_mnist_train.csv'
raw_data = open(filename, 'rt')
reader = csv.reader(raw_data, delimiter=',', quoting=csv.QUOTE_NONE)
x = list(reader)
data = numpy.array(x).astype('float')
print(data.shape)
print(data.shape[1])
X = data[:,0:784]
Y = data[:,784]
print(X.shape[1])
print(X)
model = Sequential()
model.add(Dense(512,input_dim = 784,activation='relu'))
model.add(Dense(24,activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
model.fit(X,Y,epochs=100,batch_size=20)```
它给出了这样的错误
ValueError: Error when checking target: expected dense_34 to have shape (24,) but got array with shape (1,)
[1]: https://www.kaggle.com/datamunge/sign-language-mnist
【问题讨论】:
标签: python numpy csv keras deep-learning