How to solve this error: "Error using DAGNetwork/activations (line 245) Incorrectly defined MiniBatchable Datastore. Error in read method of C:\Program Files\MATL​AB\R2020b\​toolbox\ma​tlab\datas​toreio\+ma​tlab\+io\+​datastore\​@ImageData​store\read​.m"

5 次查看(过去 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)];

回答(1 个)

Madhav Thakker
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.

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by