Main Content

SeriesNetwork

深度学习系列网络

描述

系列网络是一个用于深度学习的神经网络,其层面是一个又一次安排的。它具有单个输入层和一个输出层。

Creation

There are several ways to create aSeriesNetworkobject:

Note

To learn about other pretrained networks, such asGooglenetandresnet50, seePretrained Deep Neural Networks

Properties

展开全部

This property is read-only.

Network layers, specified as aLayer大批。

This property is read-only.

Network input layer names, specified as a cell array of character vectors.

数据类型:细胞

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

数据类型:细胞

对象功能

activations 计算深度学习网络层激活
classify 使用经过训练的深度学习神经网络对数据进行分类
predict Predict responses using trained deep learning neural network
predictAndUpdateState 使用训练有素的复发神经网络预测响应,并更新网络状态
classifyAndUpDateState 使用训练有素的复发神经网络对数据进行分类,并更新网络状态
resetState Reset state parameters of neural network
阴谋 Plot neural network layer graph

例子

全部收缩

Load a pretrained AlexNet convolutional neural network and examine the layers and classes.

Load the pretrained AlexNet network usingalexnet。The outputnet是一个SeriesNetworkobject.

Net = Alexnet
net = SeriesNetwork with properties: Layers: [25×1 nnet.cnn.layer.Layer]

Using theLayersproperty, view the network architecture. The network comprises of 25 layers. There are 8 layers with learnable weights: 5 convolutional layers, and 3 fully connected layers.

net.Layers
ans = 25x1层阵列带有图层:1'数据'图像输入227x227x3图像,带有“ zerecenter”标准化2'Conv1'卷积96 11x11x3卷积,步幅[4 4]和Padding [0 0 0 0 0 0] 3'relu1'relu relu 4 relu 4 relu 4“ NORM1”跨通道归一化横向通道归一化,每元素5通道5'pool1'最大boming 3x3 max boming plid [2 2]和填充[0 0 0 0 0] 6'conv2'分组卷积2组128 5x5x48卷积,步幅[1 1]和填充[2 2 2] 7'RERU2'RELU 2'relu 8'norm2'跨通道横向通道横向通道归一化,每个元素9'pool2'最大池2'最大boming 3x3 max bol [2 2]和填充[0 0 0 0] 10'Conv3'卷积384 3X3X256大步[1 1]和填充[1 1 1 1] 11'RELU3'RELU3'RELU RELU RELU 12'CORV4'分组的卷积2组192 3x3x192卷积,横步[1 1]和填充[1 1 1 1] 13'relu4'relu relu 14'conv5'分组2组128 3x3x192卷积[1 1]和填充[1 1 1 1] 15'relu5'relu relu 16'pool5'最大池池3x3最大池,步幅[2 2]和填充[0 0 0 0 0] 17'fc6'FC6'完全连接4096完全连接第18层'relu6'relu 19'drop6'辍学50%辍学20'fc7'完全连接4096完全连接的层21'relu7'relu 22'relu 22'drop7 drop7 drop7'辍学50%辍学23'fc8 fc8完全连接1000完全连接的层24'Prob'SoftMax SoftMax 25“输出”分类'带有“ Tench”和999个其他类

You can view the names of the classes learned by the network by viewing theClasses分类输出层的属性(最后一层)。通过选择前10个元素查看前10个类。

net.layers(end).classes(1:10)
ans =10×1分类阵列Tench Goldfish Great White Shark Tiger Shark Hammerhead Electric Ray stingray公鸡母鸡鸵鸟

Specify the example file'digitsnet.prototxt'进口。

Protofile ='digitsnet.prototxt';

导入网络层。

layers = ImportCaffelayers(Protofile)
层=带有层的1x7层阵列:1'testdata'图像输入28x28x1图像2'conv1'卷积20 5x5x1卷积,步幅[1 1]和填充[0 0] 3'relu1'relu1'relu 4'relu 4'pool1 pool1 pool 1'max ploming 2x2 max max 2x2 max 2x2与步幅[2 2]合并[0 0] 5'IP1'完全连接10完全连接的第6层'损失'softmax softmax 7'输出'分类'分类'分类crossentropyex搭配'class1','class2'和其他8个类别

Load the data as anImageDatastoreobject.

digitDatasetPath = fullfile(matlabroot,'toolbox','nnet',。。。'nndemos','nndatasets',“ digitdataset”);imds = imageDatastore(digitDatasetPath,。。。'IncludeSubfolders',true,。。。'LabelSource','foldernames');

数据存储包含10,000个数字的合成图像,从0到9。图像是通过应用随机转换来创建不同字体的数字图像来生成的。每个数字图像为28乘28像素。数据存储包含每个类别的图像数量相等。

Display some of the images in the datastore.

figure numImages = 10000; perm = randperm(numImages,20);fori = 1:20 subplot(4,5,i); imshow(imds.Files{perm(i)}); drawnow;结尾

Figure contains 20 axes objects. Axes object 1 contains an object of type image. Axes object 2 contains an object of type image. Axes object 3 contains an object of type image. Axes object 4 contains an object of type image. Axes object 5 contains an object of type image. Axes object 6 contains an object of type image. Axes object 7 contains an object of type image. Axes object 8 contains an object of type image. Axes object 9 contains an object of type 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.

Divide the datastore so that each category in the training set has 750 images and the testing set has the remaining images from each label.

numTrainingFiles = 750; [imdsTrain,imdsTest] = splitEachLabel(imds,numTrainingFiles,'randomize');

SpliteachLabelsplits the image files indigitDatainto two new datastores,Imdsrainandimdstest

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

层= [。。。imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer maxPooling2dLayer(2,'Stride',2) fullyConnectedLayer(10) softmaxLayer classificationLayer];

Set the options to the default settings for the stochastic gradient descent with momentum. Set the maximum number of epochs at 20, and start the training with an initial learning rate of 0.0001.

options = trainingOptions('sgdm',。。。'MaxEpochs',20,。。。“初始删除”,1e-4,。。。“冗长”,false,。。。'Plots','training-progress');

Train the network.

net = trainNetwork(imdsTrain,layers,options);

Figure Training Progress (26-Feb-2022 11:32:00) contains 2 axes objects and another object of type uigridlayout. Axes object 1 contains 6 objects of type patch, text, line. Axes object 2 contains 6 objects of type patch, text, line.

Run the trained network on the test set, which was not used to train the network, and predict the image labels (digits).

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

计算准确性。精度是测试数据中真实标签数的比率,该标签与从classify对于测试数据中的图像数量。

accuracy = sum(YPred == YTest)/numel(YTest)
accuracy = 0.9404

Extended Capabilities

Version History

Introduced in R2016a