Error using trainNetwork for image classification

18 views (last 30 days)
I have following error from a classification.
Error using parallel.gpu.CUDADevice.hBuild An unexpected error occurred trying to retrieve CUDA device properties. The CUDA error was: CUDA_ERROR_UNKNOWN
Error in parallel.gpu.GPUDevice.getDevice (line 76) d = parallel.gpu.CUDADevice.hBuild( idx );
Error in parallel.gpu.GPUDevice.isAvailable (line 146) device = parallel.gpu.GPUDevice.getDevice( index );
Error in nnet.internal.cnn.util.isGPUCompatible (line 9) if(iCanUsePCT() && parallel.gpu.GPUDevice.isAvailable())
Error in nnet.internal.cnn.util.GPUShouldBeUsed (line 17) tf = nnet.internal.cnn.util.isGPUCompatible();
Error in trainNetwork>iSetupExecutionEnvironment (line 357) GPUShouldBeUsed = nnet.internal.cnn.util.GPUShouldBeUsed( ...
Error in trainNetwork (line 77) executionSettings = iSetupExecutionEnvironment( opts );
Error in imageClassification (line 34) myNet = trainNetwork(trainingImages, layers, opts); Here is the code i was trying, I couldn't figure out the reason behind the error.
clear;
close all;
clc;
% Import Training Data
trainFolder = 'Train';
testFolder = 'C:\Users\user\Google Drive\Sibi\Project\Data\test';
trainingImages = imageDatastore(trainFolder,'IncludeSubfolders',true,'FileExtensions',...
{'.jpg','.tif'} ,'LabelSource','foldernames');
testImages = imageDatastore(testFolder,'FileExtensions',{'.jpg','.tif'});
% Prepare Training Sets
% minSetCount = min([trainingImages.Count]);
% trainingSets = partition(imageSets, minSetCount, 'randomize');
% [trainingImages, testImages] = splitEachLabel(images, 0.8, 'randomize');
net = alexnet;
layers = net.Layers;
layers(23) = fullyConnectedLayer(10); % change this based on # of classes
layers(25) = classificationLayer;
miniBatchSize = 64;
numIterationsPerEpoch = floor(numel(trainingImages.Labels)/miniBatchSize);
% functions = { ...
% @plotTrainingAccuracy, ...
% @(info) stopTrainingAtThreshold(info,95)};
opts = trainingOptions('sgdm',...
'verbose',true,...
'verboseFrequency', 1,...
'InitialLearnRate', 0.001,...
'OutputFcn',@plotTrainingAccuracy);
trainingImages.ReadFcn = @readImageFunction;
myNet = trainNetwork(trainingImages, layers, opts);
print -djpeg 'TrainingProgress.jpg';
testImages.ReadFcn = @readImageFunction;
save myNet myNet;
matobj = matfile('myNet.mat');%load the pre-trained net
predictedLabels = classify(matobj.myNet, testImages);
accuracy = mean(predictedLabels == testImages.Labels);
save accuracy accuracy;
function plotTrainingAccuracy(info)
persistent plotObj
if info.State == "start"
plotObj = animatedline;
xlabel("Iteration")
ylabel("Training Accuracy")
elseif info.State == "iteration"
addpoints(plotObj,info.Iteration,info.TrainingAccuracy)
drawnow limitrate nocallbacks
end
end
I am using 2016a version of Matlab, can anyone help me sort out this problem?
>>
  3 Comments
Joss Knight
Joss Knight on 9 Jan 2018
Yes, just add 'ExecutionEnvironment', 'cpu' to the trainingOptions.

Sign in to comment.

Answers (0)

Categories

Find more on Deep Learning Toolbox 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!