tensorflow手写数字识别

你离开我真会死。 提交于 2019-12-01 05:29:26
import tensorflow as tf
from keras.utils import np_utils

(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
SHAPE = 28 * 28
CLASSES = 10
x_train = x_train.reshape(x_train.shape[0], SHAPE)
x_test = x_test.reshape(x_test.shape[0], SHAPE)
y_train = np_utils.to_categorical(y_train, CLASSES)
y_test = np_utils.to_categorical(y_test, CLASSES)

model = tf.keras.models.Sequential([
    tf.keras.layers.Dense(32, activation='relu'),
    tf.keras.layers.Dense(32, activation='relu'),
    tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam',
              loss='binary_crossentropy',
              metrics=['accuracy'])
model.fit(x_train, y_train, batch_size=1000, epochs=50)
evaluate = model.evaluate(x_test, y_test)
print(evaluate)

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!