mnist手写数字识别python代码
时间: 2023-09-16 13:11:25 浏览: 83
mnist.rar_MNIST_Python 深度学习_python深度学习_tensorflow实现首先数字识别_手写数字识别
5星 · 资源好评率100%
当然可以,以下是一个简单的 mnist 手写数字识别的 Python 代码:
```
import tensorflow as tf
from tensorflow import keras
mnist = keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = keras.models.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(128, activation='relu'),
keras.layers.Dropout(0.2),
keras.layers.Dense(10)
])
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
model.compile(optimizer='adam',
loss=loss_fn,
metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test, verbose=2)
```
希望能够帮到您!
阅读全文