Error using nnet.cnn.L​ayerGraph>​iValidateL​ayerName (line 654) Layer 'Classific​ationLayer​_predictio​ns' does not exist. Error in nnet.cnn.L​ayerGraph/​replaceLay​er (line 397)

clc
clear all
outputFolder=fullfile('recycle101');
rootFolder=fullfile(outputFolder,'recycle');
categories={'Aluminium Can','PET Bottles','Drink Carton Box'};
imds=imageDatastore(fullfile(rootFolder,categories),'LabelSource','foldernames');
tbl=countEachLabel(imds)
minSetCount=min(tbl{:,2});
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomized');
countEachLabel(imds);
%randomly choose file for aluminium can, PET bottles, and drink carton box
AluminiumCan=find(imds.Labels=='Aluminium Can',1);
PETBottles=find(imds.Labels=='PET Bottles',1);
DrinkCartonBox=find(imds.Labels=='Drink Carton Box',1);
%plot image that was pick randomly
figure
subplot(2,2,1);
imshow(readimage(imds,AluminiumCan));
subplot(2,2,2);
imshow(readimage(imds,PETBottles));
subplot(2,2,3);
imshow(readimage(imds,DrinkCartonBox));
%Load pre-trained network
net = resnet50;
analyzeNetwork(net)
numClasses = numel(categories(imdsTrain.Labels));
lgraph = layerGraph(net);
%Replace the classification layers for new task
newFCLayer = fullyConnectedLayer(3,'Name','new_fc','WeightLearnRateFactor',10,'BiasLearnRateFactor',10);
lgraph = replaceLayer(lgraph,'fc1000',newFCLayer);
newClassLayer = classificationLayer('Name','new_classoutput');
lgraph = replaceLayer(lgraph,'ClassificationLayer_predictions',newClassLayer);

 采纳的回答

may be use
lgraph = replaceLayer(lgraph,'ClassificationLayer_fc1000',newClassLayer);

6 个评论

Owhh is works!!
Thank you so much!
May I know what is the different between ClassificationLayer_fc1000 and ClassificationLayer_predictions?
yes,sir,when we see the layers,we can find the Classification Output name,such as
net = resnet50('Weights','none');
lys = net.Layers;
lys(end-3:end)
ans =
4×1 Layer array with layers: 1 'avg_pool' 2-D Global Average Pooling 2-D global average pooling 2 'fc1000' Fully Connected 1000 fully connected layer 3 'fc1000_softmax' Softmax softmax 4 'ClassificationLayer_fc1000' Classification Output crossentropyex
Can I email my coding for you to check and give me some advice?
yes,sir,may be send me the file and some information to do analysis,the email address is
cvdeeplearning@qq.com

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Deep Learning Toolbox 的更多信息

产品

版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by