keras构建卷积神经网络

This article is aimed at people who want to learn or review how to build a basic Convolutional Neural Network in Keras. The dataset in which this article is based on is the Fashion-Mnist dataset.

本文针对想要学习或复习如何在Keras中构建基本卷积神经网络的人们。 本文所基于的数据集是Fashion-Mnist数据集 。

Along with this article, we will explain how:

与本文一起,我们将解释如何:

  1. To build a basic CNN in Keras.在Keras中建立基本的CNN。
  2. To run the neural networks.运行神经网络。
  3. To save and load checkpoints.保存和加载检查点。

数据集描述 (Dataset description)

Fashion-MNIST is a dataset of Zalando’s article images — consisting of a training set of 60,000 examples and a test set of 10,000 examples. Each example is a 28x28 grayscale image, associated with a label from 10 classes. We intend Fashion-MNIST to serve as a direct drop-in replacement for the original MNIST dataset for benchmarking machine learning algorithms. It shares the same image size and structure of training and testing splits.

Fashion-MNIST是Zalando文章图片的数据集-包含60,000个示例的训练集和10,000个示例的测试集。 每个示例都是一个28x28灰度图像,与来自10个类别的标签相关联。 我们打算将Fashion-MNIST用作直接替代MNIST原始数据集的基准机器学习算法。 它具有相同的图像大小以及训练和测试分割的结构。

加载数据 (Loading the data)

In order to run the code displayed below, it is necessary to download the following files. Once downloaded the data, you can load it using the following code.

为了运行下面显示的代码,必须下载以下文件 。 下载数据后,您可以使用以下代码加载数据。

数据标准化 (Data normalization)

Then, we rescale the images from 0–255 to 0–1 by dividing the data by 255.

然后,通过将数据除以255,我们将图像从0-255缩放到0-1。

前处理 (Pre-processing)

Before loading the data inside the neural network, it is necessary to reshape the images to the correct format that Keras requires. When using a 2D convolution as the first layer in a model, the default shape is (batch_size, height, width, channels); (no_data, 128, 128, 3) for 128x128 RGB pictures.

在将数据加载到神经网络内部之前,有必要将图像重塑为Keras所需的正确格式。 当使用2D卷积作为模型的第一层时,默认形状为(batch_size,height,width,channels); ( no_data,128,128,3 )用于128x128 RGB图片。

The images of our dataset are grayscale images, in which the value of each pixel is a single sample representing only an amount of light. Therefore, the shape of the training data has to be (no_data, 28, 28, 1).

我们的数据集的图像是灰度图像,其中每个像素的值是一个仅代表光量的单个样本。 因此,训练数据的形状必须为( no_data,28,28,1 )。

建立神经网络 (Building the neural network)

For this article, I built a neural network using two 2D convolutions layers and then two fully connected layers. When declaring the 2D convolutional layers, it is possible/necessary to indicate some parameters. Also, remember to recheck the input_shape. Most errors come from not declaring it right.

对于本文,我使用两个2D卷积层以及两个完全连接的层构建了一个神经网络。 在声明2D卷积层时,有可能/有必要指出一些参数。 另外,请记住要重新检查input_shape。 大多数错误来自未正确声明。

Arguments:

参数:

  • filters: Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution).

    过滤器 :整数,输出空间的维数(即卷积中输出过滤器的数量)。

  • kernel_size: An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.

    kernel_size :一个整数或2个整数的元组/列表,指定2D卷积窗口的高度和宽度。 可以是单个整数,以为所有空间尺寸指定相同的值。

  • activation: Activation function to use. The typical activations used for all the layers but the last one is ‘relu’ activation. For the last layer, the most used activation is the ‘softmax’ activation.

    activation :要使用的激活功能。 除最后一层外,所有层都使用的典型激活是“ relu”激活。 对于最后一层,最常用的激活是“ softmax”激活。

  • pool_size: integer or tuple of 2 integers, window size over which to take the maximum. (2, 2) will take the max value over a 2x2 pooling window. If only one integer is specified, the same window length will be used for both dimensions.

    pool_size :2个整数的整数或元组,最大的窗口大小。 (2, 2)将采用2x2合并窗口中的最大值。 如果仅指定一个整数,则两个尺寸将使用相同的窗口长度。

This is the architecture of the built neural network.

这是内置神经网络的体系结构。

训练神经网络 (Training the neural network)

For training the neural network, you can run the following code. Apart from training and evaluating the validation set, it will also save logs that can be afterward loaded into Tensorboard.

为了训练神经网络,您可以运行以下代码。 除了训练和评估验证集外,它还将保存日志,然后可以将其加载到Tensorboard中。

Besides, this code will save (1) the weights of the model for each epoch, and (2) the weights of the model with maximum accuracy.

此外,此代码还将节省(1)每个时期的模型权重,以及(2)以最大精度保存的模型权重。

Saving the best model is interesting because the last epoch is not always that one that performed best (e.g., the model is overfitting).

保存最佳模型很有趣,因为最后一个时期并不总是表现最好的那个时期(例如,模型过度拟合)。

加载并重新运行模型 (Loading and re-running the model)

Since we saved the models in the step before, now it is possible to load it and keep training the neural network.

由于我们在之前的步骤中保存了模型,因此现在可以加载模型并继续训练神经网络。

The code to load the model is the following.

下面是加载模型的代码。

To keep training the neural network from the point we left it before, just run the following code after loading the model.

为了从之前离开的地方继续训练神经网络,只需在加载模型后运行以下代码即可。

绘制结果 (Plotting the results)

The results are displayed in the following figures.

结果显示在下图中。

First training (15 epochs)
第一次训练(15个纪元)
Whole training, after loading and rerunning the model (30 epochs)
加载并重新运行模型后进行整体培训(30个纪元)

The classification results are displayed in the following table.

分类结果显示在下表中。

翻译自: https://medium.com/swlh/building-loading-and-saving-a-convolutional-neural-network-in-keras-2b06b1f76887

keras构建卷积神经网络


http://www.taodudu.cc/news/show-863673.html

相关文章:

  • 深度学习背后的数学_深度学习背后的简单数学
  • 深度学习:在图像上找到手势_使用深度学习的人类情绪和手势检测器:第1部分
  • 单光子探测技术应用_我如何最终在光学/光子学应用程序中使用机器学习作为博士学位
  • 基于深度学习的病理_组织病理学的深度学习(第二部分)
  • ai无法启动产品_启动AI启动的三个关键教训
  • 达尔文进化奖_使用Kydavra GeneticAlgorithmSelector将达尔文进化应用于特征选择
  • 变异函数 python_使用Python进行变异测试
  • 信号处理深度学习机器学习_机器学习与信号处理
  • PinnerSage模型
  • 零信任模型_关于信任模型
  • 乐器演奏_深度强化学习代理演奏的蛇
  • 深度学习模型建立过程_所有深度学习都是统计模型的建立
  • 使用TensorFlow进行鬼写
  • 使用OpenCV和Python从图像中提取形状
  • NLP的特征工程
  • 无监督学习 k-means_无监督学习-第1部分
  • keras时间序列数据预测_使用Keras的时间序列数据中的异常检测
  • 端口停止使用_我停止使用
  • opencv 分割边界_电影观众:场景边界分割
  • 监督学习无监督学习_无监督学习简介
  • kusto使用_Python查找具有数据重复问题的Kusto表
  • 使用GridSearchCV和RandomizedSearchCV进行超参数调整
  • rust面向对象_面向初学者的Rust操作员综合教程
  • 深度学习术语_您应该意识到这些(通用)深度学习术语和术语
  • 问题解决方案_问题
  • airflow使用_使用AirFlow,SAS Viya和Docker像Pro一样自动化ML模型
  • 迁移学习 nlp_NLP的发展-第3部分-使用ULMFit进行迁移学习
  • 情感分析朴素贝叶斯_朴素贝叶斯推文的情感分析
  • 梯度下降优化方法'原理_优化梯度下降的新方法
  • DengAI —数据预处理

keras构建卷积神经网络_在Keras中构建,加载和保存卷积神经网络相关推荐

  1. outlook 加载配置项_如何在Outlook中启用加载项和连接器

    outlook 加载配置项 There are a lot of third-party add-ins and connectors available for Outlook. What's th ...

  2. web高德地图怎么加载离线地图_基于 QGIS 在内网中离线加载卫星地图的方法

    1. 概述 我们之前为大家分享过在三维地球开源平台离线加载卫星影像的方法,主要包括基于桌面端的OsgEarth开源三维地球和基于Web端的Cesium开源三维地球等平台的局域网离线影像加载. 另外,也 ...

  3. Android中WebView加载sdcard中的html时提示:ERR_FILE_NOT_FOUND和ERR_ACCESS_DENIED

    场景 Android中WebView加载sdcard中的html显示: Android中WebView加载sdcard中的html显示_BADAO_LIUMANG_QIZHI的博客-CSDN博客 在实 ...

  4. js后退页面不重新加载_快应用:支持加载单独JS文件的规范思考

    当前快应用的项目中,支持加载其它JS文件(通过:require('./foo.js')),然后通过webpack工具处理依赖,最终完成页面JS的构建,其中页面JS包含了引入的所有JS内容: 本文讨论的 ...

  5. ArcGIS Image Server简介以及OL2中的加载

    概述: 本文讲述Arcgis Image Server相关以及在OL2中如何加载Arcgis Server发布的影像服务. ImageService简介: ArcGIS Image Server为用户 ...

  6. HTML基础和JSP了解及JSP中代码加载顺序

    HTML入门基础教程 html是什么,什么是html通俗解答: html是hypertext markup language的缩写,即超文本标记语言.html是用于创建可从一个平台移植到另一平台的超文 ...

  7. html页面判断其他div为空,将外部html加载到div中 - 页面加载然后变为空白

    我确信这将会变成一件愚蠢的事情,但是自从我成为JavaScript noob以来,这里就变成了一件愚蠢的事情.将外部html加载到div中 - 页面加载然后变为空白 我想外部HTML内容加载到我的索引 ...

  8. @PropertySource读取外部配置文件中的k-v保存到运行的环境变量中,加载完微博的配置文件以后使用${}取配置文件中的键值

    @PropertySource读取外部配置文件中的k-v保存到运行的环境变量中,加载完微博的配置文件以后使用${}取配置文件中的键值 该注解value={},可以使用String数组形式,读取多个配置 ...

  9. JDBC中驱动加载的过程分析

    JDBC中驱动加载的过程分析 作者:kenty  来源:博客园  发布时间:2007-08-20 15:01  阅读:1100 次  原文链接   [收藏]    本篇从java.sql.Driver ...

最新文章

  1. python中内建函数isinstance的用法
  2. sql 汉字转首字母拼音
  3. 010-ThreadGroup线程组
  4. excel打开csv错误换行_「乱吐槽·乱学习」excel高手捷径:一招鲜,吃遍天③
  5. caffe,deeplab,对Interp(差值)层的理解
  6. ROS仿真-记一次错误 gazebo-2 process has died exit code 2
  7. 喜马拉雅音频下载+x2m文件转换
  8. SpringBoot中发送QQ邮件
  9. 从零开始学centos(一)
  10. 度数秒分在线计算机,秒换算(时分秒换算器)
  11. JUCE框架教程(6)——通过AudioProcessorValuetTeeState链接数据和UI
  12. 今天,腾讯云总裁邱跃鹏表示,云计算发展要迈过三道关……
  13. [已解决] idea插件下载不了
  14. 墨卡托坐标转GPS坐标
  15. c语言之良好的编程习惯(一)
  16. 服务器使用固态硬盘的优缺点
  17. 中国老百姓一生要交多少税?
  18. GaussDB(for MySQL)近数据处理(NDP)解锁查询新姿势
  19. ObjectARXWizards AutoCAD .NET Wizards 下载地址
  20. How To Install GLPI 9.5 On CentOS7

热门文章

  1. 用友企业互联网服务产品闪亮2016中国互联网大会
  2. LoRa创始成员“叛逃” NB-IoT要一统物联网?
  3. TiDB 分布式数据库(一)
  4. bat批量删.svn
  5. iOS开发必备指南合集之游戏接入GameCenter 指南
  6. MSSQL 如何实现 MySQL 的 limit 查询方式【转存】
  7. 批处理--创建当前日期的文件夹
  8. 了解恶意软件和插件!
  9. [导入]常用26句生活用语[英语]
  10. java 系统音量案例_android 实现手机音量的控制 实例源码