CNN培训出错

时间:2016-04-15 17:13:11

标签: matlab conv-neural-network

在图像培训上使用CNN时,我需要帮助。我正在使用' practical-cnn-2015a'演示。

以下是适用于我的工作的代码的摘录,以及我遇到的错误。请帮忙。谢谢

%% 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) ; 
  

使用fullfile时出错(第61行)构造文件规范时FULLFILE中发生未知错误。

     

cnn_train中的错误(第92行)modelFigPath = fullfile(opts.expDir,' net-train.pdf');

     

trainCNN2中的错误(第72行)[net,info] = cnn_train(net,imdb,@ getBatch,trainOpts);引起:

     

使用horzcat时出错连接矩阵的维数不一致。

1 个答案:

答案 0 :(得分:1)

你写过

trainOps.expDir = (img);

似乎是将图像分配给代码期望为目录名的内容。因此,在尝试使用expDir'net-train.pdf'构建文件名时会中断。