更新时间:2024-07-18 GMT+08:00
分享

创建和训练模型

命令如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# create model
model = keras.Sequential([
    keras.layers.Flatten(input_shape=(28, 28)),
    keras.layers.Dense(128, activation='relu'),
    keras.layers.Dense(10)
])
model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
              metrics=['accuracy'])
# training
model.fit(train_images, train_labels, epochs=10)

相关文档