Error using trainNetwork for image classification

조회 수: 16 (최근 30일)
Sibi Isac
Sibi Isac 2018년 1월 5일
댓글: Joss Knight 2018년 1월 9일
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
Sibi Isac
Sibi Isac 2018년 1월 5일
can i run this on the cpu?
Joss Knight
Joss Knight 2018년 1월 9일
Yes, just add 'ExecutionEnvironment', 'cpu' to the trainingOptions.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by