【实例简介】人工智能算法实现mnist手写数字识别
【实例截图】
【源码目录】
mnist实验报告
├── ML_MNIST
│ ├── CNN.py
│ ├── FCN.py
│ └── RNN.py
└── mnist实验报告.doc
1 directory, 4 files
【核心代码】
mnist = tf.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
print("x_train.shape", x_train.shape)
x_train = x_train.reshape(x_train.shape[0], 28, 28, 1) #给数据增加一个维度,使数据和网络结构匹配x_test = x_test.reshape(x_test.shape[0], 28, 28, 1)
print("x_train.shape", x_train.shape)
2.设置模型参数model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Den