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"
3 次查看(过去 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!