tensorflow2版本学习教程1-mnist数据集手写字体
生活随笔
收集整理的這篇文章主要介紹了
tensorflow2版本学习教程1-mnist数据集手写字体
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import tensorflow as tf# 載入并準備好 MNIST 數據集。將樣本從整數轉換為浮點數
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# 將模型的各層堆疊起來,以搭建 tf.keras.Sequential 模型。為訓練選擇優化器和損失函數
model = tf.keras.models.Sequential([tf.keras.layers.Flatten(input_shape=(28, 28)),tf.keras.layers.Dense(128, activation='relu'),tf.keras.layers.Dropout(0.2),tf.keras.layers.Dense(10, activation='softmax')
])# 訓練并驗證模型
model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test, verbose=2)
歡迎關注公眾號:算法工程師的學習日志
總結
以上是生活随笔為你收集整理的tensorflow2版本学习教程1-mnist数据集手写字体的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tensorflow: Could no
- 下一篇: matlab Retinex图像增强算法