主要内容

SeriesNetwork

深度学习系列网络

描述

系列网络是一种用于深度学习的神经网络,它的层次依次排列。它有一个输入层和一个输出层。

创建

有几种方法可以创建SeriesNetwork对象:

请注意

了解其他预先训练过的网络,比如googlenet而且resnet50,请参阅预训练深度神经网络

属性

全部展开

此属性是只读的。

网络层,指定为数组中。

此属性是只读的。

网络输入层名称,指定为字符向量的单元格数组。

数据类型:细胞

网络输出层名称,指定为字符向量的单元格数组。

数据类型:细胞

对象的功能

激活 计算深度学习网络层激活
分类 利用训练过的深度学习神经网络对数据进行分类
预测 使用训练过的深度学习神经网络预测响应
predictAndUpdateState 使用训练过的循环神经网络预测响应并更新网络状态
classifyAndUpdateState 使用训练过的循环神经网络对数据进行分类并更新网络状态
resetState 重置神经网络状态参数
情节 图神经网络结构

例子

全部折叠

加载一个预先训练的AlexNet卷积神经网络,并检查层和类。

加载预先训练的AlexNet网络使用alexnet.输出是一个SeriesNetwork对象。

网= alexnet
图层:[25×1 nnet. cn.layer .layer]

使用属性,查看网络架构。该网络由25层组成。有8个具有可学习权值的层:5个卷积层和3个完全连接层。

网层
带有图层的图层数组:227 x227x3数据的图像输入图像的zerocenter正常化2 conv1卷积96年11 x11x3旋转步[4 4]和填充[0 0 0 0]3‘relu1 ReLU ReLU 4 norm1的横通道正常化横通道正常化与5频道/元素5“pool1”马克斯池3 x3马克斯池步(2 - 2)和填充[0 0 0 0]6“conv2”分组卷积2组128 5 x5x48旋转步[1]和填充(2 2 2 2)7的relu2 ReLU ReLU 8 norm2交叉道标准化交叉道正常化与5频道/元素9“pool2”马克斯池3 x3马克斯池步[2 2]和填充[0 0 0 0]10 conv3卷积384 3 x3x256旋转步[1]和填充[1 1 1 1]11的relu3 ReLU ReLU 12“conv4”分组卷积2组192 3 x3x192旋转步[1]和填充[1 1 1 1]13的relu4 ReLU ReLU 14“conv5”分组卷积2组128 3 x3x192旋转步[1]和填充(1 1 1)15'relu5' ReLU ReLU 16 'pool5' Max Pooling 3x3 Max Pooling with stride [2 2] and padding [0 000] 17 'fc6'全连接4096全连接层18 'relu6' ReLU ReLU 19 'drop6' Dropout 50% Dropout 20 'fc7'全连接4096全连接层21 'relu7' ReLU ReLU 22 'drop7' Dropout 50% Dropout 23 'fc8'全连接1000全连接层24 'prob' Softmax Softmax 25 'output'分类输出crossentropyex与'tench'和999其他类

可以查看网络学习到的类的名称属性的分类输出层(最后一层)。通过选择前10个元素来查看前10个类。

net.Layers(结束). class (1:10)
ans =10×1分类数组Tench金鱼大白鲨虎鲨锤头鲨电鳐黄貂鱼公鸡母鸡鸵鸟

指定示例文件“digitsnet.prototxt”进口。

protofile =“digitsnet.prototxt”

导入网络层。

层= importCaffeLayers (protofile)
Layer array with layers: 1' testdata' Image Input 28x28x1 images 2' conv1' Convolution 20 5x5x1 convolutions with stride [1 1] and padding [0 0] 3 'relu1' ReLU ReLU 4 'pool1' Max Pooling 2x2 Max Pooling with stride [2 2] and padding [0 0] 5 'ip1' full Connected 10 full Connected Layer 6 'loss' Softmax Softmax 7 'output' Classification output crossentropyex with 'class1', 'class2', and 8 other classes

将数据加载为ImageDatastore对象。

digitDatasetPath = fullfile (matlabroot,“工具箱”“nnet”...“nndemos”“nndatasets”“DigitDataset”);imd = imageDatastore (digitDatasetPath,...“IncludeSubfolders”,真的,...“LabelSource”“foldernames”);

该数据存储包含10,000个合成的数字图像,从0到9。这些图像是通过对用不同字体创建的数字图像进行随机转换而生成的。每张数字图像是28 × 28像素。每个类别的数据存储包含相同数量的图像。

显示数据存储中的一些图像。

figure numImages = 10000;烫= randperm (numImages 20);I = 1:20 subplot(4,5, I);imshow (imds.Files{烫发(i)});drawnow;结束

图中包含20个轴对象。坐标轴对象1包含一个image类型的对象。Axes对象2包含一个image类型的对象。Axes对象3包含一个image类型的对象。Axes对象4包含一个image类型的对象。Axes对象5包含一个image类型的对象。Axes对象6包含一个image类型的对象。Axes对象7包含一个image类型的对象。Axes对象8包含一个image类型的对象。Axes对象9包含一个image类型的对象。 Axes object 10 contains an object of type image. Axes object 11 contains an object of type image. Axes object 12 contains an object of type image. Axes object 13 contains an object of type image. Axes object 14 contains an object of type image. Axes object 15 contains an object of type image. Axes object 16 contains an object of type image. Axes object 17 contains an object of type image. Axes object 18 contains an object of type image. Axes object 19 contains an object of type image. Axes object 20 contains an object of type image.

划分数据存储,使训练集中的每个类别都有750个图像,而测试集中有来自每个标签的剩余图像。

numTrainingFiles = 750;[imdsTrain, imdsTest] = splitEachLabel (imd, numTrainingFiles“随机”);

splitEachLabel分割图像文件digitData到两个新的数据存储中,imdsTrain而且imdsTest

定义卷积神经网络体系结构。

层= [...imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer maxPooling2dLayer(2,“步”2) fullyConnectedLayer(10) softmaxLayer classificationLayer];

将选项设置为带有动量的随机梯度下降的默认设置。设置最大课时数为20,以初始学习率0.0001开始训练。

选择= trainingOptions (“个”...“MaxEpochs”, 20岁,...“InitialLearnRate”1的军医,...“详细”假的,...“阴谋”“训练进步”);

培训网络。

网= trainNetwork (imdsTrain层,选项);

{

在没有用于训练网络的测试集中运行训练过的网络,并预测图像标签(数字)。

YPred =分类(净,imdsTest);欧美= imdsTest.Labels;

计算的准确性。准确率是测试数据中与分类匹配的真实标签的数量之比分类到测试数据中的图像数量。

精度= sum(YPred == YTest)/numel(YTest)
精度= 0.9408

扩展功能

版本历史

介绍了R2016a

Baidu
map