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)
原文:https://www.cnblogs.com/yytxdy/p/11660033.html