MNISTとは?
Mixed National Institute of Standards and Technology database
手書き60000枚とテスト画像10000枚の画像データセット
MNISTのデータDL
http://yann.lecun.com/exdb/mnist/
import keras from keras.datasets import mnist from keras.models import Sequential from keras.layers import Dense, Dropout, InputLayer from keras.optimizers import RMSprop (x_train, y_train),(x_test,y_test) = mnist.load_data() x_train = x_train.reshape(60000, 748) x_test = x_test.reshape(10000, 784) x_train = x_train.astype('float32') x_test = x_test.astype('float32') x_train /= 255 x_test /= 255 y_train = keras.utils.to_categorical(y_train, 10) y_test = keras.utils.to_categorical(y_test, 10) model = Sequential() model.add(InputLayer(input_shape=(784,))) model.add(Dense(10, activation='softmax')) model.compile(loss='categorical_crossentropy',optimizer='rmsprop', metrics=['accuracy']) epochs = 20 batch_size = 128 history = model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, verbose=1, validation_data=(x_test, y_test)) score = model.evaluate(x_test, y_test, verbose=1) print() print('Test loss:', score[0]) print('Test accuracy:', score[1])
MNISTのデータは縦28ピクセル x 横28ピクセル = 計748ピクセル
各ピクセルRGBは 0 – 255 の256種類の整数値