python keras minst手写数字识别示例代码

代码语言:python

所属分类:其他

代码描述:python keras minst手写数字识别示例代码

代码标签: python keras minst 手写 识别 数字 示例代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

#!/usr/local/python3/bin/python3
# -*- coding: utf-8 -*
from tensorflow.keras.datasets import mnist
from  tensorflow.keras import models
from  tensorflow.keras import layers
from tensorflow.keras.callbacks import ModelCheckpoint
from  tensorflow.keras.utils import to_categorical
from PIL import Image
import matplotlib.pyplot as plt

(train_images,train_labels),(test_images,test_labels) = mnist.load_data()

plt.imsave('/data/wwwroot/default/Data/shouxiewenzi.jpg', test_images[0])
# img = Image.fromarray(test_images[:1]) # 将array转化成图片
# img_save_path = f"/data/wwwroot/default/Data/shouxiewenzi.jpg" # 图片保存路径
# img.save(img_save_path)

network = models.Sequential()
network.add(layers.Dense(512,activation='relu',input_shape=(28*28,)))
network.add(layers.Dense(10,activation='softmax'))

network.compile(optimizer='rmsprop',
                loss='categorical_crossentropy',
                metrics=['accuracy'])

train_images .........完整代码请登录后点击上方下载按钮下载查看

网友评论0