这个keras是一个简单的keras模型,我使用relu来实现简单性和学习能力 也将mean_square视为损失,但模型不适合 我认为输出是数字[0-9],我没有使用to_categorical,这就是为什么只有输出神经元
from keras.datasets import mnist
(data, labels),(x_test,y_test) = mnist.load_data()
from keras.layers import Input, Dense, Flatten
from keras.models import Model
from keras.losses import mean_squared_error
# This returns a tensor
inputs = Input(shape=(28, 28,))
x = Flatten()(inputs)
x = Dense(64, activation='relu')(x)
x = Dense(64, activation='relu')(x)
predictions = Dense(1, activation='relu')(x)
model = Model(inputs=inputs, outputs=predictions)
model.compile(optimizer='rmsprop',
loss=mean_squared_error,
metrics=['accuracy'])
model.fit(data, labels, batch_size=10, epochs=10 ,
validation_data=(x_test, y_test)) # starts training