当前位置:网站首页>1.一个神经网络示例
1.一个神经网络示例
2022-08-03 04:05:00 【好名字能更容易让朋友记住】
一个神经网络示例
加载 Keras 中的 MNIST 数据集
from keras.datasets import mnist (train_images, train_labels), (test_images, test_labels) = mnist.load_data()网络架构
from keras import models from keras import layers network = models.Sequential() network.add(layers.Dense(512, activation='relu', input_shape=(28*28,))) network.add(layers.Dense(10,activation='softmax'))编译步骤
编译步骤的三个参数
损失函数(loss function)
网络如何衡量在训练数据上的性能,即网络如何朝着正确方向前进。
优化器(optimizer)
基于训练数据和损失函数来更新网路的机制。
在训练和测试过程中需要监控的指标(metric)
本例只关心精度,即正确分类的图像所占比例。
network.complice(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])准备图像数据
将数据进行预处理,将其变换为网络要求的形状,并缩放放到所有值都在 [0, 1] 区间。
train_images = train_images.reshape((60000,28*28)) train_images = train_images.astype('float32') / 255 test_images = test_images.reshape((1000,28*28)) test_images = test_images.astype('float32') / 255准备标签
from keras.utils import to_categorical train_labels = to_categorical(train_labels) test_labels = to_categorical(test_labels)现在可以准备开始训练网络,在 Keras 中这一步通过调用网络的 fit 方法来完成的——在训练数据上拟合(fit)模型
>>>network.fit(train_image, train_labels, epochs=5, batch_size=128) Epoch 1/5 60000/60000 [==========================] - 9s - loss:0.2524 - acc: 0.9273 Epoch 2/5 51328/60000 [======================>...] - ETA: 1s - loss: 0.1035 - acc: 0.9692训练过程中显示了两个数字:
- 网络在训练数据上的损失(loss)
- 网络在训练数据上的精度(acc)
>>> test_loss, test_acc = network.evaluate(test_images, test_labels) >>> print('test_acc:', test_acc) test_acc: 0.9785
边栏推荐
- HI3521D 烧录128M nand flash文件系统过程-一定要注意flash的容量
- 多线程使用哈希表
- 浅谈用KUSTO查询语言(KQL)在Azure Synapse Analytics(Azure SQL DW)审计某DB账号的操作记录
- 中断系统需要解决的问题
- 正则表达式与绕过案例
- ESP8266-Arduino编程实例-MAX6675冷端补偿K热电偶数字转换器驱动
- Record some bugs encountered - when mapstruct and lombok are used at the same time, the problem of data loss when converting entity classes
- 计组错题集
- EssilorLuxottica借助Boomi的智能集成平台实现订单处理的现代化
- 关于#sql#的问题,如何解决?
猜你喜欢
随机推荐
解析,强势供应商的管理方法
log4j设置日志的时区
(2022杭电多校五)1010-Bragging Dice (思维)
Test drive: project management module - curd development project
基于flowable的upp(统一流程平台)运行性能优化(2)
正则表达式与绕过案例
path development介绍
基于Streamlit的YOLOv5ToX模型转换工具(适用YOLOv5训练出来的模型转化为任何格式)
How many moments have you experienced the collapse of electronic engineers?
Can Oracle EMCC be installed independently?Or does it have to be installed on the database server?
Senior ClickHouse -
SM30 表维护视图数据保存前 数据校验事件
视频中场的概念(1080I和1080P)和BT601/656/709/1120/2020/2077
(2022牛客多校五)G-KFC Crazy Thursday(二分+哈希)
mysql bool blind
LeetCode算法日记:面试题 03.04. 化栈为队
2022 Henan Mengxin League Game (4): Zhengzhou University of Light Industry E - Sleep Well
Base64编码原理
MediaRecorder录制屏幕时在部分机型上报错prepare failed:-22
Domino服务器SSL证书安装指南









