이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
how to validate data trainned
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi all,
Anyone know how to validate the data trainned?
Because before this, I just trainned what I labelled using groundTruthLabeler. Then how to validate data (in red rectangle) that we have??
채택된 답변
yanqi liu
2022년 1월 8일
yes,sir,may be set options,such as
options = trainingOptions('sgdm', ...
'MaxEpochs',100, ...
'GradientThreshold',1, ...
'Verbose',false, ...
'ValidationData',{XVal, YVal},...
'LearnRateDropFactor',0.2,...
'LearnRateDropPeriod',5,...
'Plots','training-progress');
댓글 수: 11
mohd akmal masud
2022년 1월 9일
sir, this is my code. Then where shoud I put your code suggestion?
%% first, read the image data and labelled images
clc
clear all
dataSetDir = fullfile('C:\Users\Akmal\Desktop\I-131 256 28.02.2020\I-131 SPECT NEMA VALIDATION 01112019 256X256 26.09.2021 petang');
imageDir = fullfile(dataSetDir,'Image');
labelDir = fullfile(dataSetDir,'PixelLabelData');
imds = imageDatastore(imageDir);
% view data set images origional
figure
for i = 1:23
subplot(5,5,i)
I = readimage(imds,i);
imshow(I)
title('training labels')
end
%% train the data. if network already, then just drag it into command window
classNames = ["foreground" "background"];
labelIDs = [1 2];
pxds = pixelLabelDatastore(labelDir, classNames, labelIDs);
imds1 = imageDatastore(labelDir);
% figure
% for i = 1:5
% subplot(3,3,i)
% I = readimage(imds1,i);
% imshow(I)
% title('training labels')
% end
ds = pixelLabelImageDatastore(imds,pxds);
tbl = countEachLabel(pxds)
totalNumberOfPixels = sum(tbl.PixelCount);
frequency = tbl.PixelCount / totalNumberOfPixels;
inverseFrequency = 1./frequency
% layerf = pixelClassificationLayer(...
% 'Classes',tbl.Name,'ClassWeights',inverseFrequency)
%
layerf=pixelClassificationLayer("Name","Segmentation-Layer")
lgraph = layerGraph();
tempLayers = [
imageInputLayer([512/2 512/2 1],"Name","ImageInputLayer")
convolution2dLayer([4 4],64,"Name","Encoder-Stage-1-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-1-ReLU-1")
convolution2dLayer([4 4],64,"Name","Encoder-Stage-1-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-1-ReLU-2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
maxPooling2dLayer([2 2],"Name","Encoder-Stage-1-MaxPool","Stride",[4 4])
convolution2dLayer([4 4],128,"Name","Encoder-Stage-2-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-2-ReLU-1")
convolution2dLayer([4 4],128,"Name","Encoder-Stage-2-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-2-ReLU-2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
maxPooling2dLayer([2 2],"Name","Encoder-Stage-2-MaxPool","Stride",[4 4])
convolution2dLayer([4 4],256,"Name","Encoder-Stage-3-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-3-ReLU-1")
convolution2dLayer([4 4],256,"Name","Encoder-Stage-3-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-3-ReLU-2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
dropoutLayer(0.5,"Name","Encoder-Stage-3-DropOut")
maxPooling2dLayer([2 2],"Name","Encoder-Stage-3-MaxPool","Stride",[4 4])
convolution2dLayer([4 4],512,"Name","Bridge-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Bridge-ReLU-1")
convolution2dLayer([4 4],512,"Name","Bridge-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Bridge-ReLU-2")
dropoutLayer(0.5,"Name","Bridge-DropOut")
transposedConv2dLayer([2 2],256,"Name","Decoder-Stage-1-UpConv","BiasLearnRateFactor",2,"Stride",[4 4],"WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-1-UpReLU")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","Decoder-Stage-1-DepthConcatenation")
convolution2dLayer([4 4],256,"Name","Decoder-Stage-1-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-1-ReLU-1")
convolution2dLayer([4 4],256,"Name","Decoder-Stage-1-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-1-ReLU-2")
transposedConv2dLayer([2 2],128,"Name","Decoder-Stage-2-UpConv","BiasLearnRateFactor",2,"Stride",[4 4],"WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-2-UpReLU")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","Decoder-Stage-2-DepthConcatenation")
convolution2dLayer([4 4],128,"Name","Decoder-Stage-2-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-2-ReLU-1")
convolution2dLayer([4 4],128,"Name","Decoder-Stage-2-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-2-ReLU-2")
transposedConv2dLayer([2 2],64,"Name","Decoder-Stage-3-UpConv","BiasLearnRateFactor",2,"Stride",[4 4],"WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-3-UpReLU")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","Decoder-Stage-3-DepthConcatenation")
convolution2dLayer([4 4],64,"Name","Decoder-Stage-3-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-3-ReLU-1")
convolution2dLayer([4 4],64,"Name","Decoder-Stage-3-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-3-ReLU-2")
convolution2dLayer([1 1],3,"Name","Final-ConvolutionLayer","Padding","same","WeightsInitializer","he")
softmaxLayer("Name","Softmax-Layer")
pixelClassificationLayer("Name","Segmentation-Layer")
];
lgraph = addLayers(lgraph,tempLayers);
% clean up helper variable
clear tempLayers;
lgraph = connectLayers(lgraph,"Encoder-Stage-1-ReLU-2","Encoder-Stage-1-MaxPool");
lgraph = connectLayers(lgraph,"Encoder-Stage-1-ReLU-2","Decoder-Stage-3-DepthConcatenation/in2");
lgraph = connectLayers(lgraph,"Encoder-Stage-2-ReLU-2","Encoder-Stage-2-MaxPool");
lgraph = connectLayers(lgraph,"Encoder-Stage-2-ReLU-2","Decoder-Stage-2-DepthConcatenation/in2");
lgraph = connectLayers(lgraph,"Encoder-Stage-3-ReLU-2","Encoder-Stage-3-DropOut");
lgraph = connectLayers(lgraph,"Encoder-Stage-3-ReLU-2","Decoder-Stage-1-DepthConcatenation/in2");
lgraph = connectLayers(lgraph,"Decoder-Stage-1-UpReLU","Decoder-Stage-1-DepthConcatenation/in1");
lgraph = connectLayers(lgraph,"Decoder-Stage-2-UpReLU","Decoder-Stage-2-DepthConcatenation/in1");
lgraph = connectLayers(lgraph,"Decoder-Stage-3-UpReLU","Decoder-Stage-3-DepthConcatenation/in1");
% lgraph = connectLayers(lgraph,'relu12','skipConv1');
% lgraph = connectLayers(lgraph,'Encoder-Stage-2-Conv-2','add22/in2');
% lgraph = connectLayers(lgraph,'relu22','');
% Plot Layers
figure,plot(lgraph);
imageSize = [256 256 1];
numClasses = 2;
encoderDepth = 3;
lgraph = unetLayers(imageSize,numClasses,'EncoderDepth',encoderDepth)
options1 = trainingOptions('adam', ...
'InitialLearnRate',1e-3, ...
'MaxEpochs',100, ...
'LearnRateDropFactor',5e-1, ...
'LearnRateDropPeriod',10, ...
'LearnRateSchedule','piecewise', ...
'MiniBatchSize',4,'Plots','training-progress');
net1 = trainNetwork(ds,lgraph,options1);
yanqi liu
2022년 1월 10일
%% first, read the image data and labelled images
clc
clear all
dataSetDir = fullfile('C:\Users\Akmal\Desktop\I-131 256 28.02.2020\I-131 SPECT NEMA VALIDATION 01112019 256X256 26.09.2021 petang');
imageDir = fullfile(dataSetDir,'Image');
labelDir = fullfile(dataSetDir,'PixelLabelData');
imds = imageDatastore(imageDir);
% view data set images origional
figure
for i = 1:23
subplot(5,5,i)
I = readimage(imds,i);
imshow(I)
title('training labels')
end
%% train the data. if network already, then just drag it into command window
classNames = ["foreground" "background"];
labelIDs = [1 2];
pxds = pixelLabelDatastore(labelDir, classNames, labelIDs);
imds1 = imageDatastore(labelDir);
% figure
% for i = 1:5
% subplot(3,3,i)
% I = readimage(imds1,i);
% imshow(I)
% title('training labels')
% end
ds = pixelLabelImageDatastore(imds,pxds);
tbl = countEachLabel(pxds)
totalNumberOfPixels = sum(tbl.PixelCount);
frequency = tbl.PixelCount / totalNumberOfPixels;
inverseFrequency = 1./frequency
% layerf = pixelClassificationLayer(...
% 'Classes',tbl.Name,'ClassWeights',inverseFrequency)
%
layerf=pixelClassificationLayer("Name","Segmentation-Layer")
lgraph = layerGraph();
tempLayers = [
imageInputLayer([512/2 512/2 1],"Name","ImageInputLayer")
convolution2dLayer([4 4],64,"Name","Encoder-Stage-1-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-1-ReLU-1")
convolution2dLayer([4 4],64,"Name","Encoder-Stage-1-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-1-ReLU-2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
maxPooling2dLayer([2 2],"Name","Encoder-Stage-1-MaxPool","Stride",[4 4])
convolution2dLayer([4 4],128,"Name","Encoder-Stage-2-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-2-ReLU-1")
convolution2dLayer([4 4],128,"Name","Encoder-Stage-2-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-2-ReLU-2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
maxPooling2dLayer([2 2],"Name","Encoder-Stage-2-MaxPool","Stride",[4 4])
convolution2dLayer([4 4],256,"Name","Encoder-Stage-3-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-3-ReLU-1")
convolution2dLayer([4 4],256,"Name","Encoder-Stage-3-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-3-ReLU-2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
dropoutLayer(0.5,"Name","Encoder-Stage-3-DropOut")
maxPooling2dLayer([2 2],"Name","Encoder-Stage-3-MaxPool","Stride",[4 4])
convolution2dLayer([4 4],512,"Name","Bridge-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Bridge-ReLU-1")
convolution2dLayer([4 4],512,"Name","Bridge-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Bridge-ReLU-2")
dropoutLayer(0.5,"Name","Bridge-DropOut")
transposedConv2dLayer([2 2],256,"Name","Decoder-Stage-1-UpConv","BiasLearnRateFactor",2,"Stride",[4 4],"WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-1-UpReLU")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","Decoder-Stage-1-DepthConcatenation")
convolution2dLayer([4 4],256,"Name","Decoder-Stage-1-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-1-ReLU-1")
convolution2dLayer([4 4],256,"Name","Decoder-Stage-1-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-1-ReLU-2")
transposedConv2dLayer([2 2],128,"Name","Decoder-Stage-2-UpConv","BiasLearnRateFactor",2,"Stride",[4 4],"WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-2-UpReLU")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","Decoder-Stage-2-DepthConcatenation")
convolution2dLayer([4 4],128,"Name","Decoder-Stage-2-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-2-ReLU-1")
convolution2dLayer([4 4],128,"Name","Decoder-Stage-2-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-2-ReLU-2")
transposedConv2dLayer([2 2],64,"Name","Decoder-Stage-3-UpConv","BiasLearnRateFactor",2,"Stride",[4 4],"WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-3-UpReLU")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","Decoder-Stage-3-DepthConcatenation")
convolution2dLayer([4 4],64,"Name","Decoder-Stage-3-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-3-ReLU-1")
convolution2dLayer([4 4],64,"Name","Decoder-Stage-3-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-3-ReLU-2")
convolution2dLayer([1 1],3,"Name","Final-ConvolutionLayer","Padding","same","WeightsInitializer","he")
softmaxLayer("Name","Softmax-Layer")
pixelClassificationLayer("Name","Segmentation-Layer")
];
lgraph = addLayers(lgraph,tempLayers);
% clean up helper variable
clear tempLayers;
lgraph = connectLayers(lgraph,"Encoder-Stage-1-ReLU-2","Encoder-Stage-1-MaxPool");
lgraph = connectLayers(lgraph,"Encoder-Stage-1-ReLU-2","Decoder-Stage-3-DepthConcatenation/in2");
lgraph = connectLayers(lgraph,"Encoder-Stage-2-ReLU-2","Encoder-Stage-2-MaxPool");
lgraph = connectLayers(lgraph,"Encoder-Stage-2-ReLU-2","Decoder-Stage-2-DepthConcatenation/in2");
lgraph = connectLayers(lgraph,"Encoder-Stage-3-ReLU-2","Encoder-Stage-3-DropOut");
lgraph = connectLayers(lgraph,"Encoder-Stage-3-ReLU-2","Decoder-Stage-1-DepthConcatenation/in2");
lgraph = connectLayers(lgraph,"Decoder-Stage-1-UpReLU","Decoder-Stage-1-DepthConcatenation/in1");
lgraph = connectLayers(lgraph,"Decoder-Stage-2-UpReLU","Decoder-Stage-2-DepthConcatenation/in1");
lgraph = connectLayers(lgraph,"Decoder-Stage-3-UpReLU","Decoder-Stage-3-DepthConcatenation/in1");
% lgraph = connectLayers(lgraph,'relu12','skipConv1');
% lgraph = connectLayers(lgraph,'Encoder-Stage-2-Conv-2','add22/in2');
% lgraph = connectLayers(lgraph,'relu22','');
% Plot Layers
figure,plot(lgraph);
imageSize = [256 256 1];
numClasses = 2;
encoderDepth = 3;
lgraph = unetLayers(imageSize,numClasses,'EncoderDepth',encoderDepth)
% split data
[imdsTrain, imdsVal, imdsTest, pxdsTrain, pxdsVal, pxdsTest] = partitionCamVidData(imds,pxds);
pximds = pixelLabelImageDatastore(imdsTrain,pxdsTrain, ...
'DataAugmentation',augmenter);
pximdsVal = pixelLabelImageDatastore(imdsVal,pxdsVal);
options1 = trainingOptions('adam', ...
'InitialLearnRate',1e-3, ...
'MaxEpochs',100, ...
'LearnRateDropFactor',5e-1, ...
'LearnRateDropPeriod',10, ...
'ValidationData',pximdsVal,...
'LearnRateSchedule','piecewise', ...
'MiniBatchSize',4,'Plots','training-progress');
net1 = trainNetwork(pximds,lgraph,options1);
mohd akmal masud
2022년 1월 10일
'partitionCamVidData' is used in Train and Deploy Fully Convolutional Networks for
Semantic Segmentation.
Got error
What is the meaning of this sir? Is it need to install?
mohd akmal masud
2022년 1월 10일
I haved put this partionCamVidData.m as attached in same folder. But got error below
Error using partitionCamVidData
Too many output arguments.
yanqi liu
2022년 1월 10일
yes,sir,can you upload zip file “I-131 SPECT NEMA VALIDATION 01112019 256X256 26.09.2021 petang”,so we can debug
mohd akmal masud
2022년 1월 10일
yanqi liu
2022년 1월 11일
%% first, read the image data and labelled images
clc
clear all; close all;
dataSetDir = fullfile('C:\Users\Akmal\Desktop\I-131 256 28.02.2020\I-131 SPECT NEMA VALIDATION 01112019 256X256 26.09.2021 petang');
imageDir = fullfile(dataSetDir,'Image');
labelDir = fullfile(dataSetDir,'PixelLabelData');
imds = imageDatastore(imageDir);
% view data set images origional
% figure
% for i = 1:23
% subplot(5,5,i)
% I = readimage(imds,i);
% imshow(I)
% title('training labels')
% end
%% train the data. if network already, then just drag it into command window
classNames = ["foreground" "background"];
labelIDs = [1 2];
pxds = pixelLabelDatastore(labelDir, classNames, labelIDs);
imds1 = imageDatastore(labelDir);
% figure
% for i = 1:5
% subplot(3,3,i)
% I = readimage(imds1,i);
% imshow(I)
% title('training labels')
% end
ds = pixelLabelImageDatastore(imds,pxds);
tbl = countEachLabel(pxds)
totalNumberOfPixels = sum(tbl.PixelCount);
frequency = tbl.PixelCount / totalNumberOfPixels;
inverseFrequency = 1./frequency
% layerf = pixelClassificationLayer(...
% 'Classes',tbl.Name,'ClassWeights',inverseFrequency)
%
layerf=pixelClassificationLayer("Name","Segmentation-Layer")
lgraph = layerGraph();
tempLayers = [
imageInputLayer([512/2 512/2 1],"Name","ImageInputLayer")
convolution2dLayer([4 4],64,"Name","Encoder-Stage-1-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-1-ReLU-1")
convolution2dLayer([4 4],64,"Name","Encoder-Stage-1-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-1-ReLU-2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
maxPooling2dLayer([2 2],"Name","Encoder-Stage-1-MaxPool","Stride",[4 4])
convolution2dLayer([4 4],128,"Name","Encoder-Stage-2-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-2-ReLU-1")
convolution2dLayer([4 4],128,"Name","Encoder-Stage-2-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-2-ReLU-2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
maxPooling2dLayer([2 2],"Name","Encoder-Stage-2-MaxPool","Stride",[4 4])
convolution2dLayer([4 4],256,"Name","Encoder-Stage-3-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-3-ReLU-1")
convolution2dLayer([4 4],256,"Name","Encoder-Stage-3-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-3-ReLU-2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
dropoutLayer(0.5,"Name","Encoder-Stage-3-DropOut")
maxPooling2dLayer([2 2],"Name","Encoder-Stage-3-MaxPool","Stride",[4 4])
convolution2dLayer([4 4],512,"Name","Bridge-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Bridge-ReLU-1")
convolution2dLayer([4 4],512,"Name","Bridge-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Bridge-ReLU-2")
dropoutLayer(0.5,"Name","Bridge-DropOut")
transposedConv2dLayer([2 2],256,"Name","Decoder-Stage-1-UpConv","BiasLearnRateFactor",2,"Stride",[4 4],"WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-1-UpReLU")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","Decoder-Stage-1-DepthConcatenation")
convolution2dLayer([4 4],256,"Name","Decoder-Stage-1-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-1-ReLU-1")
convolution2dLayer([4 4],256,"Name","Decoder-Stage-1-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-1-ReLU-2")
transposedConv2dLayer([2 2],128,"Name","Decoder-Stage-2-UpConv","BiasLearnRateFactor",2,"Stride",[4 4],"WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-2-UpReLU")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","Decoder-Stage-2-DepthConcatenation")
convolution2dLayer([4 4],128,"Name","Decoder-Stage-2-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-2-ReLU-1")
convolution2dLayer([4 4],128,"Name","Decoder-Stage-2-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-2-ReLU-2")
transposedConv2dLayer([2 2],64,"Name","Decoder-Stage-3-UpConv","BiasLearnRateFactor",2,"Stride",[4 4],"WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-3-UpReLU")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","Decoder-Stage-3-DepthConcatenation")
convolution2dLayer([4 4],64,"Name","Decoder-Stage-3-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-3-ReLU-1")
convolution2dLayer([4 4],64,"Name","Decoder-Stage-3-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-3-ReLU-2")
convolution2dLayer([1 1],3,"Name","Final-ConvolutionLayer","Padding","same","WeightsInitializer","he")
softmaxLayer("Name","Softmax-Layer")
pixelClassificationLayer("Name","Segmentation-Layer")
];
lgraph = addLayers(lgraph,tempLayers);
% clean up helper variable
clear tempLayers;
lgraph = connectLayers(lgraph,"Encoder-Stage-1-ReLU-2","Encoder-Stage-1-MaxPool");
lgraph = connectLayers(lgraph,"Encoder-Stage-1-ReLU-2","Decoder-Stage-3-DepthConcatenation/in2");
lgraph = connectLayers(lgraph,"Encoder-Stage-2-ReLU-2","Encoder-Stage-2-MaxPool");
lgraph = connectLayers(lgraph,"Encoder-Stage-2-ReLU-2","Decoder-Stage-2-DepthConcatenation/in2");
lgraph = connectLayers(lgraph,"Encoder-Stage-3-ReLU-2","Encoder-Stage-3-DropOut");
lgraph = connectLayers(lgraph,"Encoder-Stage-3-ReLU-2","Decoder-Stage-1-DepthConcatenation/in2");
lgraph = connectLayers(lgraph,"Decoder-Stage-1-UpReLU","Decoder-Stage-1-DepthConcatenation/in1");
lgraph = connectLayers(lgraph,"Decoder-Stage-2-UpReLU","Decoder-Stage-2-DepthConcatenation/in1");
lgraph = connectLayers(lgraph,"Decoder-Stage-3-UpReLU","Decoder-Stage-3-DepthConcatenation/in1");
% lgraph = connectLayers(lgraph,'relu12','skipConv1');
% lgraph = connectLayers(lgraph,'Encoder-Stage-2-Conv-2','add22/in2');
% lgraph = connectLayers(lgraph,'relu22','');
% Plot Layers
figure,plot(lgraph);
imageSize = [256 256 1];
numClasses = 2;
encoderDepth = 3;
lgraph = unetLayers(imageSize,numClasses,'EncoderDepth',encoderDepth)
% split data
[imdsTrain, imdsVal, pxdsTrain, pxdsVal] = partitionCamVidData2(imds,pxds);
pximds = pixelLabelImageDatastore(imdsTrain,pxdsTrain);
pximdsVal = pixelLabelImageDatastore(imdsVal,pxdsVal);
options1 = trainingOptions('adam', ...
'InitialLearnRate',1e-3, ...
'MaxEpochs',100, ...
'LearnRateDropFactor',5e-1, ...
'LearnRateDropPeriod',10, ...
'ValidationData',pximdsVal,...
'ValidationFrequency',3, ...
'LearnRateSchedule','piecewise', ...
'MiniBatchSize',4,'Plots','training-progress');
net1 = trainNetwork(pximds,lgraph,options1);
function [imdsTrain, imdsTest, pxdsTrain, pxdsTest] = partitionCamVidData2(imds,pxds)
% Partition CamVid data by randomly selecting 60% of the data for training. The
% rest is used for testing.
% Set initial random state for example reproducibility.
rng(0);
numFiles = numel(imds.Files);
shuffledIndices = randperm(numFiles);
% Use 60% of the images for training.
N = round(0.60 * numFiles);
trainingIdx = shuffledIndices(1:N);
% Use the rest for testing.
testIdx = shuffledIndices(N+1:end);
% Create image datastores for training and test.
trainingImages = imds.Files(trainingIdx);
testImages = imds.Files(testIdx);
imdsTrain = imageDatastore(trainingImages);
imdsTest = imageDatastore(testImages);
% Extract class and label IDs info.
classes = pxds.ClassNames;
labelIDs = 1:numel(pxds.ClassNames);
% Create pixel label datastores for training and test.
trainingLabels = pxds.Files(trainingIdx);
testLabels = pxds.Files(testIdx);
pxdsTrain = pixelLabelDatastore(trainingLabels, classes, labelIDs);
pxdsTest = pixelLabelDatastore(testLabels, classes, labelIDs);
end
mohd akmal masud
2022년 1월 11일
Hi sir. Thank you very much for coding validation.
The trained completed. But got some error
function [imdsTrain, imdsTest, pxdsTrain, pxdsTest] = partitionCamVidData2(imds,pxds)
↑
Error: Function definition are not supported in this context. Functions can only be
created as local or nested functions in code files.
Actually what is the meaning of this?
mohd akmal masud
2022년 5월 29일
Dear yanqi,
can help me how to Compare Ground Truth Against Network Prediction
%% first, read the image data and labelled images
clc
clear all; close all;
dataSetDir = fullfile('C:\Users\Akmal\Desktop\I-131 256 28.02.2020\I-131 SPECT NEMA VALIDATION 01112019 256X256 26.09.2021 petang');
imageDir = fullfile(dataSetDir,'Image');
labelDir = fullfile(dataSetDir,'PixelLabelData');
imds = imageDatastore(imageDir);
% view data set images origional
% figure
% for i = 1:23
% subplot(5,5,i)
% I = readimage(imds,i);
% imshow(I)
% title('training labels')
% end
%% train the data. if network already, then just drag it into command window
classNames = ["foreground" "background"];
labelIDs = [1 2];
pxds = pixelLabelDatastore(labelDir, classNames, labelIDs);
imds1 = imageDatastore(labelDir);
% figure
% for i = 1:5
% subplot(3,3,i)
% I = readimage(imds1,i);
% imshow(I)
% title('training labels')
% end
ds = pixelLabelImageDatastore(imds,pxds);
tbl = countEachLabel(pxds)
totalNumberOfPixels = sum(tbl.PixelCount);
frequency = tbl.PixelCount / totalNumberOfPixels;
inverseFrequency = 1./frequency
% layerf = pixelClassificationLayer(...
% 'Classes',tbl.Name,'ClassWeights',inverseFrequency)
%
layerf=pixelClassificationLayer("Name","Segmentation-Layer")
lgraph = layerGraph();
tempLayers = [
imageInputLayer([512/2 512/2 1],"Name","ImageInputLayer")
convolution2dLayer([4 4],64,"Name","Encoder-Stage-1-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-1-ReLU-1")
convolution2dLayer([4 4],64,"Name","Encoder-Stage-1-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-1-ReLU-2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
maxPooling2dLayer([2 2],"Name","Encoder-Stage-1-MaxPool","Stride",[4 4])
convolution2dLayer([4 4],128,"Name","Encoder-Stage-2-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-2-ReLU-1")
convolution2dLayer([4 4],128,"Name","Encoder-Stage-2-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-2-ReLU-2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
maxPooling2dLayer([2 2],"Name","Encoder-Stage-2-MaxPool","Stride",[4 4])
convolution2dLayer([4 4],256,"Name","Encoder-Stage-3-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-3-ReLU-1")
convolution2dLayer([4 4],256,"Name","Encoder-Stage-3-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Encoder-Stage-3-ReLU-2")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
dropoutLayer(0.5,"Name","Encoder-Stage-3-DropOut")
maxPooling2dLayer([2 2],"Name","Encoder-Stage-3-MaxPool","Stride",[4 4])
convolution2dLayer([4 4],512,"Name","Bridge-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Bridge-ReLU-1")
convolution2dLayer([4 4],512,"Name","Bridge-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Bridge-ReLU-2")
dropoutLayer(0.5,"Name","Bridge-DropOut")
transposedConv2dLayer([2 2],256,"Name","Decoder-Stage-1-UpConv","BiasLearnRateFactor",2,"Stride",[4 4],"WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-1-UpReLU")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","Decoder-Stage-1-DepthConcatenation")
convolution2dLayer([4 4],256,"Name","Decoder-Stage-1-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-1-ReLU-1")
convolution2dLayer([4 4],256,"Name","Decoder-Stage-1-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-1-ReLU-2")
transposedConv2dLayer([2 2],128,"Name","Decoder-Stage-2-UpConv","BiasLearnRateFactor",2,"Stride",[4 4],"WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-2-UpReLU")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","Decoder-Stage-2-DepthConcatenation")
convolution2dLayer([4 4],128,"Name","Decoder-Stage-2-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-2-ReLU-1")
convolution2dLayer([4 4],128,"Name","Decoder-Stage-2-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-2-ReLU-2")
transposedConv2dLayer([2 2],64,"Name","Decoder-Stage-3-UpConv","BiasLearnRateFactor",2,"Stride",[4 4],"WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-3-UpReLU")];
lgraph = addLayers(lgraph,tempLayers);
tempLayers = [
depthConcatenationLayer(2,"Name","Decoder-Stage-3-DepthConcatenation")
convolution2dLayer([4 4],64,"Name","Decoder-Stage-3-Conv-1","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-3-ReLU-1")
convolution2dLayer([4 4],64,"Name","Decoder-Stage-3-Conv-2","Padding","same","WeightsInitializer","he")
reluLayer("Name","Decoder-Stage-3-ReLU-2")
convolution2dLayer([1 1],3,"Name","Final-ConvolutionLayer","Padding","same","WeightsInitializer","he")
softmaxLayer("Name","Softmax-Layer")
pixelClassificationLayer("Name","Segmentation-Layer")
];
lgraph = addLayers(lgraph,tempLayers);
% clean up helper variable
clear tempLayers;
lgraph = connectLayers(lgraph,"Encoder-Stage-1-ReLU-2","Encoder-Stage-1-MaxPool");
lgraph = connectLayers(lgraph,"Encoder-Stage-1-ReLU-2","Decoder-Stage-3-DepthConcatenation/in2");
lgraph = connectLayers(lgraph,"Encoder-Stage-2-ReLU-2","Encoder-Stage-2-MaxPool");
lgraph = connectLayers(lgraph,"Encoder-Stage-2-ReLU-2","Decoder-Stage-2-DepthConcatenation/in2");
lgraph = connectLayers(lgraph,"Encoder-Stage-3-ReLU-2","Encoder-Stage-3-DropOut");
lgraph = connectLayers(lgraph,"Encoder-Stage-3-ReLU-2","Decoder-Stage-1-DepthConcatenation/in2");
lgraph = connectLayers(lgraph,"Decoder-Stage-1-UpReLU","Decoder-Stage-1-DepthConcatenation/in1");
lgraph = connectLayers(lgraph,"Decoder-Stage-2-UpReLU","Decoder-Stage-2-DepthConcatenation/in1");
lgraph = connectLayers(lgraph,"Decoder-Stage-3-UpReLU","Decoder-Stage-3-DepthConcatenation/in1");
% lgraph = connectLayers(lgraph,'relu12','skipConv1');
% lgraph = connectLayers(lgraph,'Encoder-Stage-2-Conv-2','add22/in2');
% lgraph = connectLayers(lgraph,'relu22','');
% Plot Layers
figure,plot(lgraph);
imageSize = [256 256 1];
numClasses = 2;
encoderDepth = 3;
lgraph = unetLayers(imageSize,numClasses,'EncoderDepth',encoderDepth)
% split data
[imdsTrain, imdsVal, pxdsTrain, pxdsVal] = partitionCamVidData2(imds,pxds);
pximds = pixelLabelImageDatastore(imdsTrain,pxdsTrain);
pximdsVal = pixelLabelImageDatastore(imdsVal,pxdsVal);
options1 = trainingOptions('adam', ...
'InitialLearnRate',1e-3, ...
'MaxEpochs',100, ...
'LearnRateDropFactor',5e-1, ...
'LearnRateDropPeriod',10, ...
'ValidationData',pximdsVal,...
'ValidationFrequency',3, ...
'LearnRateSchedule','piecewise', ...
'MiniBatchSize',4,'Plots','training-progress');
net1 = trainNetwork(pximds,lgraph,options1);
function [imdsTrain, imdsTest, pxdsTrain, pxdsTest] = partitionCamVidData2(imds,pxds)
% Partition CamVid data by randomly selecting 60% of the data for training. The
% rest is used for testing.
% Set initial random state for example reproducibility.
rng(0);
numFiles = numel(imds.Files);
shuffledIndices = randperm(numFiles);
% Use 60% of the images for training.
N = round(0.60 * numFiles);
trainingIdx = shuffledIndices(1:N);
% Use the rest for testing.
testIdx = shuffledIndices(N+1:end);
% Create image datastores for training and test.
trainingImages = imds.Files(trainingIdx);
testImages = imds.Files(testIdx);
imdsTrain = imageDatastore(trainingImages);
imdsTest = imageDatastore(testImages);
% Extract class and label IDs info.
classes = pxds.ClassNames;
labelIDs = 1:numel(pxds.ClassNames);
% Create pixel label datastores for training and test.
trainingLabels = pxds.Files(trainingIdx);
testLabels = pxds.Files(testIdx);
pxdsTrain = pixelLabelDatastore(trainingLabels, classes, labelIDs);
pxdsTest = pixelLabelDatastore(testLabels, classes, labelIDs);
end
추가 답변 (0개)
참고 항목
태그
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)