Clear Filters
Clear Filters

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

2 views (last 30 days)
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.

Answers (1)

Mahmoud Afifi
Mahmoud Afifi on 6 Jan 2020
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

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!