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

相关推荐
16_one8 分钟前
autoDL安装Open-WebUi+Rag本地知识库问答+Function Calling
人工智能·后端·算法
智能交通技术11 分钟前
iTSTech:自动驾驶技术综述报告 2025
人工智能·机器学习·自动驾驶
清云逸仙35 分钟前
AI Prompt 工程最佳实践:打造结构化的Prompt
人工智能·经验分享·深度学习·ai·ai编程
todoitbo40 分钟前
基于Rokid CXR-M SDK实现AR智能助手应用:让AI大模型走进AR眼镜
人工智能·ai·ar·ar眼镜·rokid
hacker7071 小时前
openGauss 在K12教育场景的数据处理测评:CASE WHEN 实现高效分类
人工智能·分类·数据挖掘
暖光资讯1 小时前
前行者获2025抖音最具影响力品牌奖,亮相上海ZFX装备前线展,引领外设行业“文化科技”新浪潮
人工智能·科技
guslegend1 小时前
第3章:SpringAI进阶之会话记忆实战
人工智能
陈橘又青2 小时前
100% AI 写的开源项目三周多已获得 800 star 了
人工智能·后端·ai·restful·数据
松岛雾奈.2302 小时前
深度学习--TensorFlow框架使用
深度学习·tensorflow·neo4j
中杯可乐多加冰2 小时前
逻辑控制案例详解|基于smardaten实现OA一体化办公系统逻辑交互
人工智能·深度学习·低代码·oa办公·无代码·一体化平台·逻辑控制