Is it possible to use pretrained network like alexnet with a new dataset that has different category?

3 次查看(过去 30 天)
I used alexnet with a dataset which it is categores {1-50,51-100, 101- ...}. is this possible?
if yes, why I get this error?
Error using trainNetwork (line 150)
Training and validation data must have the same labels.
Error in AlexNet_ex_density (line 114)
netTransfer = trainNetwork(augimdsTrain,layers,options);
Caused by:
Error using trainNetwork>iAssertClassNamesAreTheSame (line 376)
Training and validation data must have the same labels.
I used
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomized');
% Create augmentedImageDatastore from training and test sets to resize
% images in imds to the size required by the network.
imageSize = net.Layers(1).InputSize;
augmentedTrainingSet = augmentedImageDatastore(imageSize, imdsTrain, 'ColorPreprocessing',...
'gray2rgb','DataAugmentation',imageAugmenter);
augmentedTestSet = augmentedImageDatastore(imageSize, imdsTest, 'ColorPreprocessing', 'gray2rgb',...
'DataAugmentation',imageAugmenter);
augimdsValidation = augmentedImageDatastore(imageSize, imdsValidation, 'ColorPreprocessing',...
'gray2rgb','DataAugmentation',imageAugmenter);
and in options of the network I used
'ValidationData',augimdsValidation, ...
'ValidationFrequency',3, ...
then I uesd
netTransfer = trainNetwork(augimdsTrain,layers,options);
I got the error in above sentince.

回答(1 个)

Mahmoud Afifi
Mahmoud Afifi 2020-1-6
You need to change the last fully connected layer of Alexnet with a new one with the same number of expected output (either for regression or number of classes for classification).
https://www.mathworks.com/help/deeplearning/examples/transfer-learning-using-alexnet.html;jsessionid=82bda7d7b633139e3e0a8f6e685d

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by