Load of Transfer Learning on GPU
3 次查看(过去 30 天)
显示 更早的评论
Hi Guys,
I've been trying the transfer learning examples provided by mathworks with my own datasete (105 different labels) on the pretrained models matlab provided.
When training, I noticed that the Training Progress window dows say 'Hardware Resourse : Single GPU' and I've seen the 'Cuda library needs to be recompiled...' warning which I guess that indicates matlab does see a gpu existence.
My problem is while transfer learning using alexnet or currently training using vgg-16
- takes 3 hours and beyond (Alexnet spent 4 hours)
- GPU load in task manager shows 5% maximum and sometimes even 0% (CPU load is around 20%)...
Is this normal for a single 2080Ti card or is it not trained on the gpu for some reasons?
Thanks in advance !
-----------------------------------------------------------------------
imds = imageDatastore('Train_single','IncludeSubfolders',true,'LabelSource','foldernames');
inputSize = [224 224];
imds.ReadFcn = @(loc)imresize(imread(loc),inputSize);
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomized');
net = vgg16();
layersTransfer = net.Layers(1:end-3);
numClasses = numel(categories(imdsTrain.Labels));
layers = [
layersTransfer
fullyConnectedLayer(numClasses,'WeightLearnRateFactor',10,'BiasLearnRateFactor',10)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm', ...
'MiniBatchSize',10, ...
'MaxEpochs',6, ...
'InitialLearnRate',1e-4, ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',3, ...
'Verbose',false, ...
'Plots','training-progress');
netTransfer = trainNetwork(imdsTrain,layers,options'Hㄍ);
YPred = classify(netTransfer,imdsValidation);
accuracy = mean(YPred == imdsValidation.Labels);
0 个评论
回答(1 个)
Joss Knight
2019-2-16
Your problem is this line:
imds.ReadFcn = @(loc)imresize(imread(loc),inputSize);
You should remove it and instead use an augmentedImageDatastore
imds = imageDatastore('Train_single','IncludeSubfolders',true,'LabelSource','foldernames');
inputSize = [224 224];
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomized');
augdsTrain = augmentedImageDatastore(inputSize, imdsTrain);
augdsValidation = augmentedImageDatastore(inputSize, imdsValidation);
net = vgg16();
layersTransfer = net.Layers(1:end-3);
numClasses = numel(categories(imdsTrain.Labels));
layers = [
layersTransfer
fullyConnectedLayer(numClasses,'WeightLearnRateFactor',10,'BiasLearnRateFactor',10)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm', ...
'MiniBatchSize',10, ...
'MaxEpochs',6, ...
'InitialLearnRate',1e-4, ...
'ValidationData',augdsValidation, ...
'ValidationFrequency',3, ...
'Verbose',false, ...
'Plots','training-progress');
netTransfer = trainNetwork(augdsTrain,layers,options);
YPred = classify(netTransfer,augdsValidation);
accuracy = mean(YPred == imdsValidation.Labels);
Using a ReadFcn forces ImageDatastore to load images sequentially and therefore file I/O becomes a big bottleneck.
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!