getting an error in deep learning code

12 vues (au cours des 30 derniers jours)
rachel strongman
rachel strongman le 28 Juil 2019
Commenté : Walter Roberson le 28 Juil 2019
I am getting following error while running code for transfer deep learning:
Error using load
Cannot read file C:\Users\HP\AppData\Local\Temp\imagenet-caffe-alex.mat.
Error in helperImportMatConvNet (line 19)
matconvnet = load(matfile);
Error in tranfdeeplearning (line 18)
net = helperImportMatConvNet(cnnMatFile);
%% Load Image Data
location = 'C:\Users\HP\Desktop\data';
imds = imageDatastore(location,'IncludeSubfolders',1,...
'LabelSource','foldernames');
tbl = countEachLabel(imds);
%% SeriesNetwork object can be used to inspect the network architecture,
% classify new data, and extract network activations from specific layers.
% Location of pre-trained "AlexNet"
cnnURL = 'http://www.vlfeat.org/matconvnet/models/beta16/imagenet-caffe-alex.mat';
% tempdir = 'C:\Users\HP\Desktop\imagenet-caffe-alex.mat';
cnnMatFile = fullfile(tempdir, 'imagenet-caffe-alex.mat');
if ~exist(cnnMatFile, 'file')
disp('Downloading pre-trained CNN model...');
websave(cnnMatFile, cnnURL);
end
net = helperImportMatConvNet(cnnMatFile);
%% Look at structure of pre-trained network
% Notice the last layer performs 1000 object classification
net.Layers
%% Perform net surgery
layers = net.Layers(1:end-3);
% %optional, Add new fully connected layer for 2 categories.
layers(end+1) = fullyConnectedLayer(64, 'Name', 'special_2');
layers(end+1) = reluLayer;
% introduce another layer : adding non-linearity
% improving the network's ability to handle data
% Not enough training 1.2 million (total)
layers(end+1) = fullyConnectedLayer(height(tbl), 'Name', 'fc8_2')
% Add the softmax layer and the classification layer which make up the
% remaining portion of the networks classification layers.
layers(end+1) = softmaxLayer
layers(end+1) = classificationLayer()
% Modify image layer to add randcrop data augmentation. This increases the
% diversity of training images. The size of the input images is set to the
% original networks input size.
layers(1) = imageInputLayer([227 227 3]);
%% Setup learning rates for fine-tuning
% fc 8 - bump up learning rate for last layers
layers(end-2).WeightLearnRateFactor = 10;
layers(end-2).WeightL2Factor = 1;
layers(end-2).BiasLearnRateFactor = 20;
layers(end-2).BiasL2Factor = 0;
%% Equalize number of images of each class in training set
minSetCount = min(tbl{:,2});
%Use splitEachLabel method to trim the set.
imds = splitEachLabel(imds, minSetCount);
% Notice that each set now has exactly the same number of images.
countEachLabel(imds)
[trainingDS, testDS] = splitEachLabel(imds, 0.7,'randomize');
% Convert labels to categoricals
trainingDS.Labels = categorical(trainingDS.Labels);
trainingDS.ReadFcn = @readFunctionTrain;
% % Setup test data for validation
% testDS.Labels = categorical(testDS.Labels);
% testDS.ReadFcn = @readFunctionValidation;
%% Fine-tune the Network
miniBatchSize = 50; % lower this if your GPU runs out of memory.
numImages = numel(trainingDS.Files);
% Run training for 5000 iterations. Convert 20000 iterations into the
% number of epochs this will be.
maxEpochs = 20;
lr = 0.0001;
opts = trainingOptions('sgdm', ...
'LearnRateSchedule', 'none',...
'InitialLearnRate', lr,...
'MaxEpochs', maxEpochs, ...
'MiniBatchSize', miniBatchSize);
net = trainNetwork(trainingDS, layers, opts);
save('trainedNet.mat','net')
save('testDS.mat','testDS')
return
  3 commentaires
rachel strongman
rachel strongman le 28 Juil 2019
Modifié(e) : rachel strongman le 28 Juil 2019
I had tried with another system as well now I am getting this error:
Error using websave (line 104)
Unable to open output file: 'C:\Users\HP\Desktop\imagenet-caffe-alex.mat\imagenet-caffe-alex.mat' for writing. Common
reasons include that the file exists and does not have write permission or the folder does not have write permissions.
Error in tranfdeeplearning (line 16)
websave(cnnMatFile, cnnURL);
Please suggest way out of this
Walter Roberson
Walter Roberson le 28 Juil 2019
Notice that the imagenet-caffe-alex.mat part is repeated in the file name,
Desktop\imagenet-caffe-alex.mat\imagenet-caffe-alex.mat
Do not use
tempdir = 'C:\Users\HP\Desktop\imagenet-caffe-alex.mat';
but you can use
tempdir = 'C:\Users\HP\Desktop';

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Deep Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by