0
私は桁認識器をコードしようとしています。私は、60000 * 28 * 28の画像のピクセルデータを含むデータセットを持っています。ここで60000は画像の数で、28はピクセルの幅と高さです。モデルに適合しません
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train= x_train.reshape(60000, 28, 28, 1).astype('float32')
x_test= x_test.reshape(10000, 28, 28, 1).astype('float32')
from keras.models import Sequential
from keras.layers import Convolution2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense
classifier= Sequential()
classifier.add(Convolution2D(32, 3, 3, input_shape= (28, 28, 1), activation= 'relu'))
classifier.add(MaxPooling2D(pool_size= (2, 2)))
classifier.add(Flatten())
classifier.add(Dense(output_dim = 128, activation= 'relu'))
classifier.add(Dense(output_dim = 10, activation= 'softmax'))
classifier.compile(optimizer= 'adam', loss='binary_crossentropy', metrics = ['accuracy'])
classifier.fit(x_train, y_train, validation_data= (x_test, y_test), nb_epoch= 15, verbose= 2, batch_size= 100)
次のエラーが発生しています。
classifier.fit(x_train, y_train, validation_data= (x_test, y_test), nb_epoch= 15, verbose= 2, batch_size= 100)
Traceback (most recent call last):
File "<ipython-input-4-9425b6d029dc>", line 1, in <module>
classifier.fit(x_train, y_train, validation_data= (x_test, y_test), nb_epoch= 15, verbose= 2, batch_size= 100)
File "C:\Users\SHUBHAM\Anaconda3\lib\site-packages\keras\models.py", line 672, in fit
initial_epoch=initial_epoch)
File "C:\Users\SHUBHAM\Anaconda3\lib\site-packages\keras\engine\training.py", line 1117, in fit
batch_size=batch_size)
File "C:\Users\SHUBHAM\Anaconda3\lib\site-packages\keras\engine\training.py", line 1034, in _standardize_user_data
exception_prefix='model target')
File "C:\Users\SHUBHAM\Anaconda3\lib\site-packages\keras\engine\training.py", line 124, in standardize_input_data
str(array.shape))
ValueError: Error when checking model target: expected dense_2 to have shape (None, 10) but got array with shape (60000, 1)
私は何が問題かを知りません。助けてください。
Thanxアレックス。実行はさらに進んでいます。 –