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!