深度学习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_imgs0)

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_imgsi,cmap=plt.cm.binary)

plt.xlabel(namestrain_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(a0,test_lbs0)

相关推荐
ting94520003 小时前
Humalike X Hermes 深度技术剖析:单指令注入群聊社交智能的底层架构、算法与跨 IM 平台实现
人工智能·算法·架构
涤生大数据3 小时前
一次“没有运行日志”的DolphinScheduler任务失败排查
大数据·数据库·人工智能·状态模式
东风破_3 小时前
Vibe Coding 上头之后,我开始用 SDD 给 AI 编程加一张“施工图”
人工智能·程序员
weixin_403810134 小时前
AI智能体写安卓自动化脚本教程:Cursor/Trae+CLI 实战,自然语言生成代码
android·人工智能·自动化·跨境电商·安卓自动化脚本·多账户运营
深圳雨林凯AI4 小时前
雨林凯AI四方连图介质适配原理:像素密度、纱线纹理与颜色管理怎么协调
人工智能
ZGIAI4 小时前
ZGI 混合检索:汇集候选并统一重排
人工智能·架构
ZGIAI4 小时前
ZGI 运行日志:还原任务与节点状态
人工智能·架构
Scott9999HH5 小时前
2026 中小企业如何破局 AI 搜索?轻量化 GEO 优化系统架构设计与 Python 实战落地
人工智能
玩转单片机与嵌入式5 小时前
深入浅出TinyML 16:FFT、频带能量和MFCC分别适合什么任务?
stm32·深度学习·tinyml
甲维斯5 小时前
opencode的“恶果”来了,吃掉100G空间!
人工智能