Main Content

SeriesNetwork

(권장되지 않음) 딥러닝을 위한 시리즈 신경망

SeriesNetwork 객체는 권장되지 않습니다. 대신 dlnetwork 객체를 사용하십시오. 자세한 내용은 버전 내역을 참조하십시오.

설명

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

생성

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

참고

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

속성

모두 확장

읽기 전용 속성입니다.

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

읽기 전용 속성입니다.

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

데이터형: cell

읽기 전용 속성입니다.

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

데이터형: cell

객체 함수

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

예제

모두 축소

영상 분류를 위해 신경망을 훈련시킵니다.

데이터를 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 (15-Aug-2023 20:45:20) 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.9416

확장 기능

버전 내역

R2016a에 개발됨

모두 축소

R2024a: 권장되지 않음

R2024a부터 SeriesNetwork 객체는 권장되지 않습니다. 대신 dlnetwork 객체를 사용하십시오.

SeriesNetwork 객체에 대한 지원을 제거할 계획은 없습니다. 하지만 다음과 같은 이점이 있는 dlnetwork 객체가 대신 권장됩니다.

  • dlnetwork 객체는 신경망 구축, 예측, 기본 제공 훈련, 시각화, 압축, 검증 및 사용자 지정 훈련 루프를 지원하는 통합 데이터형입니다.

  • dlnetwork 객체는 외부 플랫폼에서 만들거나 가져올 수 있는 더 넓은 범위의 신경망 아키텍처를 지원합니다.

  • dlnetwork 객체는 trainnet 함수에서 지원되기 때문에 손실 함수를 쉽게 지정할 수 있습니다. 내장 손실 함수 중에서 선택하거나 사용자 지정 손실 함수를 지정할 수 있습니다.

  • 일반적으로 dlnetwork 객체를 사용한 훈련과 예측이 LayerGraphtrainNetwork를 사용하는 워크플로보다 더 빠릅니다.

훈련된 SeriesNetwork 객체를 dlnetwork 객체로 변환하려면 dag2dlnetwork 함수를 사용하십시오.

다음 표에서는 SeriesNetwork 객체의 몇 가지 일반적인 사용법과 dlnetwork 객체 함수를 대신 사용하도록 코드를 업데이트하는 방법을 보여줍니다.

권장되지 않음권장됨
Y = predict(net,X);
Y = minibatchpredict(net,X);
Y = classify(net,X);
scores = minibatchpredict(net,X);
Y = scores2label(scores,classNames);
plot(net);
plot(net);
Y = activations(net,X,layerName);
Y = predict(net,X,Outputs=layerName);
[net,Y] = predictAndUpdateState(net,X);
[Y,state] = predict(net,X);
net.State = state;
[net,Y] = classifyAndUpdateState(net,X);
[scores,state] = predict(net,X);
Y = scores2label(scores,classNames);
net.State = state;