Main Content

SeriesNetwork

딥러닝을 위한 시리즈 신경망

설명

시리즈 신경망은 계층이 하나씩 차례대로 연결된 것으로 딥러닝을 위한 신경망입니다. 시리즈 신경망은 하나의 입력 계층과 하나의 출력 계층을 갖습니다.

생성

SeriesNetwork 객체를 만드는 방법에는 여러 가지가 있습니다.

참고

googlenet, resnet50과 같은 다른 사전 훈련된 신경망에 대해 자세히 알아보려면 사전 훈련된 심층 신경망 항목을 참조하십시오.

속성

모두 확장

읽기 전용 속성입니다.

신경망 계층으로, Layer 배열로 지정됩니다.

읽기 전용 속성입니다.

신경망 입력 계층 이름으로, 문자형 벡터로 구성된 셀형 배열로 지정됩니다.

데이터형: cell

신경망 출력 계층 이름으로, 문자형 벡터로 구성된 셀형 배열로 지정됩니다.

데이터형: cell

객체 함수

activations딥러닝 신경망 계층 활성화 계산
classify훈련된 딥러닝 신경망을 사용하여 데이터 분류
predict훈련된 딥러닝 신경망을 사용하여 응답 변수 예측
predictAndUpdateState훈련된 순환 신경망을 사용하여 응답 변수 예측 및 신경망 상태 업데이트
classifyAndUpdateState훈련된 순환 신경망을 사용하여 데이터 분류 및 신경망 상태 업데이트
resetState신경망의 상태 파라미터 재설정
plot신경망 아키텍처 플로팅

예제

모두 축소

사전 훈련된 AlexNet 컨벌루션 신경망을 불러와서 계층과 클래스를 살펴봅니다.

사전 훈련된 AlexNet 신경망을 alexnet을 사용하여 불러옵니다. 출력값 netSeriesNetwork 객체입니다.

net = alexnet
net = 
  SeriesNetwork with properties:

    Layers: [25×1 nnet.cnn.layer.Layer]

Layers 속성을 사용하여 신경망 아키텍처를 표시합니다. 이 신경망에는 25개의 계층이 있습니다. 학습 가능한 가중치를 갖는 계층은 8개로, 5개는 컨벌루션 계층이고, 3개는 완전 연결 계층입니다.

net.Layers
ans = 
  25x1 Layer array with layers:

     1   'data'     Image Input                   227x227x3 images with 'zerocenter' normalization
     2   'conv1'    Convolution                   96 11x11x3 convolutions with stride [4  4] and padding [0  0  0  0]
     3   'relu1'    ReLU                          ReLU
     4   'norm1'    Cross Channel Normalization   cross channel normalization with 5 channels per element
     5   'pool1'    Max Pooling                   3x3 max pooling with stride [2  2] and padding [0  0  0  0]
     6   'conv2'    Grouped Convolution           2 groups of 128 5x5x48 convolutions with stride [1  1] and padding [2  2  2  2]
     7   'relu2'    ReLU                          ReLU
     8   'norm2'    Cross Channel Normalization   cross channel normalization with 5 channels per element
     9   'pool2'    Max Pooling                   3x3 max pooling with stride [2  2] and padding [0  0  0  0]
    10   'conv3'    Convolution                   384 3x3x256 convolutions with stride [1  1] and padding [1  1  1  1]
    11   'relu3'    ReLU                          ReLU
    12   'conv4'    Grouped Convolution           2 groups of 192 3x3x192 convolutions with stride [1  1] and padding [1  1  1  1]
    13   'relu4'    ReLU                          ReLU
    14   'conv5'    Grouped Convolution           2 groups of 128 3x3x192 convolutions with stride [1  1] and padding [1  1  1  1]
    15   'relu5'    ReLU                          ReLU
    16   'pool5'    Max Pooling                   3x3 max pooling with stride [2  2] and padding [0  0  0  0]
    17   'fc6'      Fully Connected               4096 fully connected layer
    18   'relu6'    ReLU                          ReLU
    19   'drop6'    Dropout                       50% dropout
    20   'fc7'      Fully Connected               4096 fully connected layer
    21   'relu7'    ReLU                          ReLU
    22   'drop7'    Dropout                       50% dropout
    23   'fc8'      Fully Connected               1000 fully connected layer
    24   'prob'     Softmax                       softmax
    25   'output'   Classification Output         crossentropyex with 'tench' and 999 other classes

신경망에서 학습한 클래스의 이름을 보려면 분류 출력 계층(마지막 계층)의 Classes 속성을 보면 됩니다. 처음 10개의 요소를 선택하여 처음 10개의 클래스를 표시합니다.

net.Layers(end).Classes(1:10)
ans = 10×1 categorical array
     tench 
     goldfish 
     great white shark 
     tiger shark 
     hammerhead 
     electric ray 
     stingray 
     cock 
     hen 
     ostrich 

가져올 예제 파일 'digitsnet.prototxt'를 지정합니다.

protofile = 'digitsnet.prototxt';

신경망 계층을 가져옵니다.

layers = importCaffeLayers(protofile)
layers = 

  1x7 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'        Fully Connected         10 fully connected layer
     6   'loss'       Softmax                 softmax
     7   'output'     Classification Output   crossentropyex with 'class1', 'class2', and 8 other classes

데이터를 ImageDatastore 객체로서 불러옵니다.

digitDatasetPath = fullfile(matlabroot,'toolbox','nnet', ...
    'nndemos','nndatasets','DigitDataset');
imds = imageDatastore(digitDatasetPath, ...
    'IncludeSubfolders',true, ...
    'LabelSource','foldernames');

이 데이터저장소에는 0부터 9까지 숫자를 나타내는 합성 영상 10,000개가 있습니다. 이 영상은 서로 다른 글꼴로 만들어진 숫자 영상에 무작위 변환을 적용하여 생성됩니다. 각 숫자 영상은 28×28픽셀입니다. 이 데이터저장소에는 범주당 동일한 개수의 영상이 포함되어 있습니다.

데이터저장소의 영상 몇 개를 표시합니다.

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

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.

훈련 세트의 각 범주에 영상 750개가 포함되고 테스트 세트에 각 레이블의 나머지 영상이 포함되도록 데이터저장소를 분할합니다.

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

splitEachLabeldigitData의 영상 파일을 2개의 새 데이터저장소인 imdsTrainimdsTest로 분할합니다.

컨벌루션 신경망 아키텍처를 정의합니다.

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

옵션을 모멘텀을 사용한 확률적 경사하강법의 디폴트 설정으로 설정합니다. 최대 Epoch 횟수를 20으로 설정하고, 초기 학습률 0.0001로 훈련을 시작합니다.

options = trainingOptions('sgdm', ...
    'MaxEpochs',20,...
    'InitialLearnRate',1e-4, ...
    'Verbose',false, ...
    'Plots','training-progress');

신경망을 훈련시킵니다.

net = trainNetwork(imdsTrain,layers,options);

Figure Training Progress (30-Jan-2023 12:59:49) contains 2 axes objects and another object of type uigridlayout. Axes object 1 with xlabel Iteration, ylabel Loss contains 6 objects of type patch, text, line. Axes object 2 with xlabel Iteration, ylabel Accuracy (%) contains 6 objects of type patch, text, line.

이렇게 훈련된 신경망을 신경망 훈련에 사용하지 않은 테스트 세트에 대해 실행하고 영상 레이블(숫자)을 예측합니다.

YPred = classify(net,imdsTest);
YTest = imdsTest.Labels;

정확도를 계산합니다. 정확도는 테스트 데이터에 있는 영상의 개수 대비 테스트 데이터에서 classify의 분류와 일치하는 실제 레이블의 개수의 비율입니다.

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

확장 기능

버전 내역

R2016a에 개발됨