深度学习DNN

https://keras.io/api/datasets/

https://archive.ics.uci.edu/

DNN--全连接神经网络

fashion_mnist玩具集

import tensorflow as tf

import numpy as np

import matplotlib.pyplot as plt

import tensorflow.keras as ks

fm=ks.datasets.fashion_mnist# 德国时装多分类

#6万个训练数据,1万个测试数据,每个样本形状28*28

(train_imgs,train_lbs),(test_imgs,test_lbs)=fm.load_data()

plt.figure()

plt.imshow(train_imgs[0])

plt.colorbar()

plt.show()

plt.figure(figsize=(10,10))

for i in range(25):

#分成5行5列的子视图

plt.subplot(5,5,i+1)

#不显示轴

# plt.axis('off')

#不显示刻度

plt.xticks([])

plt.yticks([])

plt.imshow(train_imgs[i],cmap=plt.cm.binary)

plt.xlabel(names[train_lbs[i]])

train_imgs=train_imgs/255.0

test_imgs=test_imgs/255.0

#神经网络堆层

model=ks.Sequential([

#输入图片形状是(28x28),也可以写成(28*28,)因为图片是

#被摊平的

ks.layers.Flatten(input_shape=(28,28)),

#128个神经元,激活函数relu,隐藏层

ks.layers.Dense(128,activation='relu'),

#因为目标分类是10种,所以目标层神经元10个

ks.layers.Dense(10,activation='softmax')

])

model.summary()#28*28,(784+1)*128,(128+1)*10

#one-hot编码

from keras.utils import to_categorical

#能把标签处理成机器容易识别的行式,one-hot编码

train_lbs=to_categorical(train_lbs)

test_lbs=to_categorical(test_lbs)

#编译模型,SparseCategoricalCrossentropy能做onehot编码处理

model.compile(optimizer='adam',loss=ks.losses.SparseCategoricalCrossentropy(

from_logits=True),metrics=['accuracy'])

#batch_size=128小批量的丢进去

model.fit(train_imgs,train_lbs,epochs=10,batch_size=128)

#sigm=lambda x:1/(1+np.exp(-x))

#sigm(5.757487 )

#误差,准确率,评估

test_loss,test_acc=model.evaluate(test_imgs,test_lbs,verbose=2)

display(type(test_loss),type(test_acc),test_loss,test_acc)

#这个是线性值Z

np.set_printoptions(suppress=True)

a=model.predict(test_imgs)

display(a[0],test_lbs[0])

相关推荐
梦梦代码精几秒前
从工程视角拆解 BuildingAI:一个企业级开源智能体平台的架构设计与实现
人工智能·gitee·开源·github
supericeice1 分钟前
复杂项目管理如何用好大模型:RAG、知识图谱与AI编排的落地框架
人工智能·知识图谱
AI机器学习算法5 小时前
深度学习模型演进:6个里程碑式CNN架构
人工智能·深度学习·cnn·大模型·ai学习路线
Ztopcloud极拓云视角6 小时前
从 OpenRouter 数据看中美 AI 调用量反转:统计口径、模型路由与多云应对方案
人工智能·阿里云·大模型·token·中美ai
AI医影跨模态组学6 小时前
如何将深度学习MTSR与膀胱癌ITGB8/TGF-β/WNT机制建立关联,并进一步解释其与患者预后及肿瘤侵袭、免疫抑制的生物学联系
人工智能·深度学习·论文·医学影像
搬砖的前端6 小时前
AI编辑器开源主模型搭配本地模型辅助对标GPT5.2/GPT5.4/Claude4.6(前端开发专属)
人工智能·开源·claude·mcp·trae·qwen3.6·ops4.6
Python私教7 小时前
Hermes Agent 安全加固与生态扩展:2026-04-23 更新解析
人工智能
饼干哥哥7 小时前
Kimi K2.6 干成了Claude Design国产版,一句话生成电影级的动态品牌网站
人工智能
肖有米XTKF86467 小时前
带货者精品优选模式系统的平台解析
人工智能·信息可视化·团队开发·csdn开发云
天天进步20157 小时前
打破沙盒限制:OpenWork 如何通过权限模型实现安全的系统级调用?
人工智能·安全