Convolutional Neural Networks and GPU GTX960m
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a question on GPU performance improvement. I am using GTX 960m GPU and have a 3 layer CNN. I am getting the gpu out of memory error down to a mini batch size of 4. The GPU has a 2 GB RAM and 8 GB shared memory (although I am not sure how that benefits) on a 16GB ram alienware laptop. What are your recommendations. I am using medical images that are 512 x 512 x 3 in size. I am thinking about reducing the image size but are there any other ways I could get rid of the error? Thanks ---Ish Here is my code, btw.: clc clear all % Train Network for Image Classification %Load the data as an ImageDatastore object. digitDatasetPath = fullfile('C:','Users','ihbercha', ... 'Desktop','Machine Learning','Proj_F','Img_Data'); imds = imageDatastore(digitDatasetPath, ... 'IncludeSubfolders',true, ... 'LabelSource','foldernames'); % The training set has 150 % images and the testing set has the remaining images from each %label % (260 x 2 total images) . numTrainingFiles =150; [imdsTrain,imdsTest] = splitEachLabel(imds,numTrainingFiles,'randomize'); % Define the convolutional neural network architecture. layers = [ ... imageInputLayer([512 512 3]) convolution2dLayer(3,8,'Padding',1) reluLayer maxPooling2dLayer(3,'Stride',3) convolution2dLayer(3,16,'Padding',1) reluLayer maxPooling2dLayer(3,'Stride',3) convolution2dLayer(3,32,'Padding',1) reluLayer maxPooling2dLayer(3,'Stride',3) fullyConnectedLayer(2) softmaxLayer classificationLayer]; %% % Set the options to the default settings for the stochastic gradient descent % with momentum. Set the maximum number of epochs at 20, and start the training % with an initial learning rate of 0.01. options = trainingOptions('sgdm', ... 'MaxEpochs',12,... 'InitialLearnRate',1e-2, ... 'Verbose',0, ... 'Plots','training-progress','MiniBatchSize',4, 'ExecutionEnvironment','gpu'); % Train the network. net = trainNetwork(imdsTrain,layers,options); % Run the trained network on the test set, which was not used to train the % network, and predict the image labels (digits). YPred = classify(net,imdsTest); YTest = imdsTest.Labels; cf = confusionmat(YTest, YPred) % Calculate the accuracy. Accuracy is the ratio of the number of true labels % in the test data matching the classifications from classify, to the number % of images in the test data. accuracy = sum(YPred == YTest)/numel(YTest)
1 个评论
Helena Cuesta
2018-6-10
Hello Ishtiaq, Did you find a solution? I am having the same exactly problem as you
回答(1 个)
JESUS DAVID ARIZA ROYETH
2018-5-1
I recommend that you change the size of the images, since it is not necessary to have a very large size, the convolutional neural networks work well with small images. Another option is to remove layers of "MaxPooling2dLayer" however you will not get as many benefits as resizing your images
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!