手写数字识别
from keras.datasets import mnist from keras import models from keras import layers from keras.utils import to_categorical import numpy as np def loadData(path="mnist.npz"): f = np.load(path) x_train, y_train = f['x_train'], f['y_train'] x_test, y_test = f['x_test'], f['y_test'] f.close() return (x_train, y_train), (x_test, y_test) (train_images, train_lables),(test_images,test_labels) = loadData() 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 = train_images.reshape((60000,28*28)) train_images=train_images.astype('float32')/255 test_images=test_images.reshape((10000,28*28)) test_images=test_images.astype('float32')/255 train_lables=to_categorical(train_lables)#对标签进行分类编码,one hot编码 test_labels=to_categorical(test_labels) network.fit(train_images,train_lables, epochs=5,batch_size=128)
出现了一个问题:https://blog.csdn.net/ouening/article/details/85065709
后来发现是标签分类编码那里写错了。。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· 单线程的Redis速度为什么快?
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码