您的位置:首页 > 编程语言 > Python开发

keras 入门 --手写数字识别

2017-11-20 22:37 302 查看
深度学习keras库中的helloworld:

#
#搭建一个简单的全连接神经网络,用于手写数字识别
#

from keras.layers import Input,Dense
from keras.models import Model
from keras.datasets import mnist
from keras.utils import np_utils

(X_train,y_train),(X_test,y_test) = mnist.load_data()
X_train = X_train.reshape(X_train.shape[0],784).astype('float32')
X_test = X_test.reshape(X_test.shape[0],784).astype('float32')
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)

input = Input(shape=(784,))
x = Dense(64, activation='relu')(input)
x = Dense(64, activation='relu')(x)
output = Dense(10, activation='softmax')(x)

model = Model(inputs=input, outputs=output)
model.compile(optimizer='rmsprop', loss='categorical_crossentropy',
metrics=['accuracy'])
model.fit(X_train, y_train)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 深度学习