Load of Transfer Learning on GPU

조회 수: 5 (최근 30일)
Johnny Yeng
Johnny Yeng 2019년 2월 16일
답변: Joss Knight 2019년 2월 16일
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);
taskmanager
TransferLearning_Alexnet

답변 (1개)

Joss Knight
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.

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by