keras从入门到放弃(十)手写数字识别训练
【摘要】 导入手写数字识别
import keras
from keras import layers
import matplotlib.pyplot as plt
%matplotlib inline
import keras.datasets.mnist as mnist
(train_image, train_label), (test_image, test_labe...
导入手写数字识别
import keras
from keras import layers
import matplotlib.pyplot as plt
%matplotlib inline
import keras.datasets.mnist as mnist
(train_image, train_label), (test_image, test_label) = mnist.load_data()
train_image.shape
OUT:
(60000, 28, 28)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
即有60000张图片 28*28像素
用切片的方法去取出图片
plt.imshow(train_image[0])
train_label[0]
OUT:
0
- 1
- 2
- 3
- 4
模型训练
model = keras.Sequential()
model.add(layers.Flatten()) # (60000, 28, 28) ---> (60000, 28*28)
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10, activation='softmax'))
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['acc']
)
model.fit(train_image, train_label, epochs=50, batch_size=512)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
文章来源: maoli.blog.csdn.net,作者:刘润森!,版权归原作者所有,如需转载,请联系作者。
原文链接:maoli.blog.csdn.net/article/details/88872695
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)