Network training, GPU out of memory

4 views (last 30 days)
Thomas Hyatt
Thomas Hyatt on 19 Oct 2021
I am trying to train a 3d convolutional network, but am running into memory issues with my gpu (GTX 3080, 10gb VRAM). My training dataset is 77.5 GB of 16x8x800 image sequences formatted as .mat files. I've already tried loweing the minibatchsize as low as it will go. I am currently trying to train with the cpu but it is painfully slow. Does anyone know how I can make this so that my GPU can run this?
clc
clear
imds = imageDatastore('filelocation','FileExtensions','.mat','LabelSource','none','ReadFcn',@matRead);
labels = load('filelocationLabels');
importLabels = labels.Labels;
imds.Labels = importLabels(1:length(dir('filelocationLabels'))-2);
[imds2,imds1] = splitEachLabel(imds,500,'randomized');
layers = [
image3dInputLayer([16 8 800 1],"Name","image3dinput","Normalization","none")
convolution3dLayer([3 3 3],32,"Name","conv3d")
convolution3dLayer([3 3 3],64,"Name","conv3d_1","Padding",[1 1 1;1 1 1])
maxPooling3dLayer([3 3 3],"Name","maxpool3d_1")
convolution3dLayer([3 3 3],64,"Name","conv3d_2","Padding",[1 1 1;1 1 1])
maxPooling3dLayer([3 3 3],"Name","maxpool3d_2")
fullyConnectedLayer(512,"Name","fc_1")
reluLayer("Name","relu_1")
fullyConnectedLayer(256,"Name","fc_2")
reluLayer("Name","relu_2")
fullyConnectedLayer(128,"Name","fc_3")
reluLayer("Name","relu_3")
fullyConnectedLayer(10,"Name","fc_4")
softmaxLayer("Name","softmax")
classificationLayer("Name","classoutput")];
options = trainingOptions('adam', ...
'InitialLearnRate',0.001, ...
'ExecutionEnvironment','gpu', ...
'ValidationData',imds2, ...
'ValidationFrequency',50, ...
'MiniBatchSize',1, ...
'MaxEpochs',8, ...
'GradientThreshold',2, ...
'Verbose',1, ...
'VerboseFrequency',1000,...
'Shuffle','every-epoch', ...
'Plots','training-progress');
HandyNet = trainNetwork(imds,layers,options);
%%
function data = matRead(filename)
inp = load(filename);
f = fields(inp);
data = inp.(f{1});
end
  1 Comment
Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh on 19 Oct 2021
your network is very heavy. so try to reduce number of filters in conv3d layers, i guess. you have 32 , 64 and 64 filters respectively. each are 3x3x3. for example start with 10 to see if it works.
also use stride in conv.
and also use bigger poolSize in maxpooling layer.
all above reduce data during training.

Sign in to comment.

Answers (0)

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!