Error using trainNetwork for image classification
19 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!