Reputation: 53
Please I need help on using CNN on image training. I am using the 'practical-cnn-2015a' demo.
Below is an excerpt of the codes as applied to my work, and the errors I encountered. Please help. Thank you
%% Load image dataset
imgFolder1 = fullfile('C:\Users\Jay\Desktop\practical-cnn-2015a\NairaNotes');
trainingSet = imageSet(imgFolder1, 'recursive');
%%
for digit = 1:numel(trainingSet)
numImages = trainingSet(digit).Count;
for i = 1:numImages img = read(trainingSet(digit), i);
im = rgb2gray(im2single(read(trainingSet(digit), i)));
end
labels = repmat(trainingSet(digit).Description, numImages, 1);
end
%% Visualize some of the data
figure(10) ; clf ; colormap gray ;
subplot(1,2,1) ; vl_imarraysc(img) ;
axis image off ; title('training chars for ''a''') ; subplot(1,2,2) ;
vl_imarraysc(img); axis image off ;
title('validation chars for ''a''') ;
%% ------------------------------------------------------------------------- % Part 4.2: initialize a CNN architecture % -------------------------------------------------------------------------
net = initializeCharacterCNN() ;
%% % -------------------------------------------------------------------------
% Part 4.3: train and evaluate the CNN % -------------------------------------------------------------------------
trainOpts.batchSize = 100 ;
trainOpts.numEpochs = 15 ;
trainOpts.continue = true ;
trainOpts.useGpu = false ;
trainOpts.learningRate = 0.001 ;
trainOpts.expDir = (img) ;
%% ----------------------------------------------------------
%% i have errors in this section:
(attempt to execute SCRIPT varagin.m as a function)
trainOpts = vl_argparse(trainOpts, varargin(:));
%% --------------------------------------------
%% Take the average image out
imdb = img ;
imageMean = mean(imdb(:)) ;
imdb = imdb - imageMean ;
%% Convert to a GPU array if needed
if trainOpts.useGpu
imdb = gpuArray(imdb) ;
end
%% pending: Call training function in MatConvNet
[net,info] = cnn_train(net, imdb, @getBatch, trainOpts) ;
Error using fullfile (line 61) An unknown error occurred in FULLFILE while constructing the file specification.
Error in cnn_train (line 92) modelFigPath = fullfile(opts.expDir, 'net-train.pdf') ;
Error in trainCNN2 (line 72) [net,info] = cnn_train(net, imdb, @getBatch, trainOpts) ; Caused by:
Error using horzcat Dimensions of matrices being concatenated are not consistent.
Upvotes: 0
Views: 415
Reputation: 19981
You've written
trainOps.expDir = (img);
which appears to be assigning an image to something that the code expects to be a directory name. So then it breaks when trying to construct a filename out of expDir
and 'net-train.pdf'
.
Upvotes: 1