Error using trainNetwork for image classification
Show older comments
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
on 5 Jan 2018
It looks like your GPU and/or NVIDIA driver is not properly set up with your system. You should contact support who can take you through some basic steps to make sure everything is configured correctly.
A trivial first step would be to install the latest driver for your card by visiting the NVIDIA drivers download page.
Sibi Isac
on 5 Jan 2018
Joss Knight
on 9 Jan 2018
Yes, just add 'ExecutionEnvironment', 'cpu' to the trainingOptions.
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!