首页 > 其他 > 详细

tensorflow手写数字识别

时间:2019-10-12 10:50:58      阅读:99      评论:0      收藏:0      [点我收藏+]
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)

 

tensorflow手写数字识别

原文:https://www.cnblogs.com/yytxdy/p/11660033.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!