How to solve this error: "Error using DAGNetwork/activations (line 245) Incorrectly defined MiniBatchable Datastore. Error in read method of C:\Program Files\MATLAB\R2020b\toolbox\matlab\datastoreio\+matlab\+io\+datastore\@ImageDatastore\read.m"
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I have the following code to extract the features from certain layer of ResNet101 deep learning model. However, after training the network, I am unable to extract the features from the layer specified below.
imds=imageDatastore('C:\Users\Manisha\Test', 'IncludeSubfolders', true, 'LabelSource','foldernames'); % There are two subfolders
tbl = countEachLabel(imds);
minSetCount = min(tbl{:,2});
imds = splitEachLabel(imds, minSetCount, 'randomize');
tbl = countEachLabel(imds)
[imdsTrain, imdsTest] = splitEachLabel(imds, 0.75, 'randomize');
net = resnet101;
numClasses = numel(categories(imds.Labels));
lgraph = layerGraph(net);
newFCLayer = fullyConnectedLayer(numClasses,'Name','new_fc','WeightLearnRateFactor',15,'BiasLearnRateFactor',15);
lgraph = replaceLayer(lgraph,'fc1000',newFCLayer);
newClassLayer = classificationLayer('Name','new_classoutput');
lgraph = replaceLayer(lgraph,'ClassificationLayer_predictions',newClassLayer);
lgraph = replaceLayer(lgraph,'ClassificationLayer_fc1000',newClassLayer);
tbl1 = countEachLabel(imdsTrain)
tbl2 = countEachLabel(imdsTest)
inputSize = net.Layers(1).InputSize;
augimdsTrain = augmentedImageDatastore(inputSize(1:2),imdsTrain);%'DataAugmentation',imageAugmenter);
imageAugmenter = imageDataAugmenter('RandRotation',[-90,90])
augimdsTest = augmentedImageDatastore(inputSize(1:2),imdsTest, 'DataAugmentation',imageAugmenter);
options = trainingOptions('adam', ...
'ExecutionEnvironment','gpu',...
'MiniBatchSize',12, ...
'MaxEpochs',20, ...
'InitialLearnRate',1e-4, ...
'Shuffle','every-epoch', ...
'ValidationFrequency',10, ...
'Verbose',true, ...
'Plots','training-progress');
trainedNet = trainNetwork(augimdsTrain,lgraph,options);
featureLayer = 'pool5'
trainingFeatures = activations(trainedNet, augimdsTrain, featureLayer, ...
'MiniBatchSize', 12, 'OutputAs', 'rows'); % error in this line
label_train = [zeros(tbl1.Count(1),1); ones(tbl1.Count(1),1)];
testFeatures = activations(trainedNet, augimdsTest, featureLayer, ...
'MiniBatchSize', 12, 'OutputAs', 'rows');
label_test = [zeros(tbl2.Count(1),1); ones(tbl2.Count(2),1)];
댓글 수: 0
답변 (1개)
Madhav Thakker
2021년 5월 18일
Hi Manisha,
If you want your custom datastore to be MiniBatchable, the read function MUST output a 2 column table, as noted in this documentation link. https://in.mathworks.com/help/deeplearning/ug/develop-custom-mini-batch-datastore.html#mw_1fbbfc62-d6e2-4e7c-843f-67b467135050
Hope this helps.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!