当前位置:网站首页>TensorFlow 2:使用神经网络对Fashion MNIST分类并进行比较分析
TensorFlow 2:使用神经网络对Fashion MNIST分类并进行比较分析
2022-06-21 18:08:00 【WihauShe】
实验设置
本实验采用不同激活函数的神经网络对MNIST数据集进行分类,同时探究隐藏层数量对实验结果的影响。实验的隐藏层主要为1层和2层,而激活函数分别为ReLU、Laaky ReLU和Softmax,输出函数不变均为Softmax。实验数据集为Fashion MNIST数据集,主要用于手写识别的多分类。
代码及实验结果
隐藏层为1层时的不同激活函数表现
# TensorFlow and tf.keras
import tensorflow as tf
from tensorflow import keras
# Helper libraries
import numpy as np
# Fashion MNIST input data
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
# preprocess
train_images = train_images / 255.0
test_images = test_images / 255.0
# build model, loss, and train op
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(196, activation='relu'), # change the activation
keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(train_images, train_labels, epochs=10)
test_loss, test_acc = model.evaluate(test_images, test_labels)
print('\nTest Accuracy:', test_acc)
relu
elu
softmax
隐藏层为2层时不同激活函数的表现
# build model, loss, and train op
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(196, activation='relu'), # change activation
keras.layers.Dense(98, activation='relu'), # change activation
keras.layers.Dense(10, activation='softmax')
])
relu

elu

softmax

边栏推荐
- Nebula Graph入驻阿里云计算巢,助力企业打造云上超大规模图数据库
- Medical expense list can be entered at a second speed, and OCR recognition can help double the efficiency
- Flink 系例 之 TableAPI & SQL 與 示例模塊
- vivo 容器集群监控系统架构与实践
- 动态规划【一】(背包问题)
- 将图片背景设置为透明的方法介绍
- R language uses GLM function to build Poisson regression model, and coef function to obtain the coefficients of Poisson regression model and analyze the effects of various variables
- 2022 China eye Expo, Shandong Youth eye health exhibition, vision correction and rehabilitation Exhibition
- 2022年6月25日PMP考试通关宝典-4
- 【一起上水硕系列】Day One
猜你喜欢

使用uniapp框架搭建浙里办微应用(单点登录、埋点、适老化、RPC网关)

How to use devaxpress WPF to create the first MVVM application in winui?

W10 add system environment variable path

2022年下半年传统产品经理国际资格认证招生简章(NPDP)

gorm数据库是否需要设置外键

出院小结识别api接口-医疗票据OCR识别/出院诊断记录/电子病历/理赔服务
![Dynamic programming [II] (linear DP)](/img/c9/f4fbc78d24320e3bd915d99de5837b.jpg)
Dynamic programming [II] (linear DP)

将图片背景设置为透明的方法介绍

Kubernetes 跨 StorageClass 迁移 Persistent Volumes 完全指南
![婴儿名字[连通分量之邻接矩阵与DFS]](/img/60/83da6ce2fd2336fe1c4aead3260b77.png)
婴儿名字[连通分量之邻接矩阵与DFS]
随机推荐
【面试高频题】难度 1/5,难度较低的链表面试题
How does the easycvr intelligent edge gateway hardware set power on self start?
MFC界面库BCGControlBar v33.0 - 桌面警报窗口、网格控件升级
jvm造轮子
vivo 容器集群监控系统架构与实践
Alibaba cloud Yum source configuration
[high frequency interview questions] linked list interview questions with 1/5 difficulty and lower difficulty
yolov5训练自己的数据集报错记录
系统集成项目管理工程师(软考中级)怎么备考?
R语言使用epiDisplay包的followup.plot函数可视化多个ID(病例)监测指标的纵向随访图、使用line.col参数自定义曲线的颜色(色彩)
What is the process of futures account opening? Is it safe to open an account online
pnpm 中无法使用 patch-package 打补丁
出院小结识别api接口-医疗票据OCR识别/出院诊断记录/电子病历/理赔服务
The R language uses the follow up The plot function visualizes the longitudinal follow-up chart of multiple ID (case) monitoring indicators, and uses line Col parameter custom curve color (color)
Easy introduction to naturallanguageprocessing series topic 6 code practice -- spelling correction based on language model
Summary of the 13th week
SQL operation: with expression and its application
Dynamic programming [II] (linear DP)
如何使用DevExpress WPF在WinUI中创建第一个MVVM应用?
API de table & SQL et module d'échantillon pour le système Flink