2017-01-19 56 views
1

您好只是爲了熟悉我已經準備了二元分類飛機(760個圖像)或非飛機(750)的代碼的CNN。錯誤在訓練CNN的二元分類

這是我的MATLAB代碼

Npos = numel(possitive_regions); 
Nneg = numel(negative_regions); 

Npos_train = floor(0.25* Npos); 
Npos_val = floor(0.25*Npos); 
Npos_test = floor(0.50*Npos); 

Nneg_train = floor(0.25*Nneg); 
Nneg_val = floor(0.25*Nneg); 
Nneg_test = floor(0.50*Nneg); 

for i=1:Npos 
    im= imresize (single(possitive_regions{i,:}),[50,50]); 
    imdb.images.data(:,:,:, i) = im; 
    imdb.images.labels(i) = 1; 

     if i <= Npos_train 
      imdb.images.set(i) = 1; 
     elseif i <= Npos_train+Npos_val 
      imdb.images.set(i) = 2; 
     else 
      imdb.images.set(i) = 3; 
     end 
end 

% for negative samples 
for i=1:Nneg 
    im= imresize (single(negative_regions{i,:}),[50,50]); 
    imdb.images.data(:,:,:, i+Npos) = im; 
    imdb.images.labels(i+Npos) = 0; 

     if i <= Nneg_train 
      imdb.images.set(Npos+i) = 1; 
     elseif i <= Nneg_train+Nneg_val 
       imdb.images.set(Npos+i) = 2; 
     else 
       imdb.images.set(Npos+i) = 3;      
     end 
end 
imdb.meta.sets = {'train', 'val', 'test'} ; 
%% Network 
opts.inputSize = [50 50 3] ; 
opts.train.batchSize = 50; 
opts.train.numEpochs = 10; 
opts.train.continue = true; 
% opts.train.useGpu = false; 
opts.train.learningRate = 0.01; 
% opts = vl_argparse(opts, []); 
f = 0.01; 

f=1/100 ; 
net.layers = {} ; 
net.layers{end+1} = struct('type', 'conv','weights', {{f*randn(5,5,3,20, 'single'), zeros(1, 20, 'single')}},'stride', 1,'pad', 0); 
net.layers{end+1} = struct('type', 'pool','method', 'max', 'pool', [2 2], 'stride', 2, 'pad', 0) ; 
net.layers{end+1} = struct('type', 'conv', 'weights', {{f*randn(5,5,20,50, 'single'),zeros(1,50,'single')}}, 'stride', 1, 'pad', 0) ; 
net.layers{end+1} = struct('type', 'pool', 'method', 'max', 'pool', [2 2], 'stride', 2, 'pad', 0) ; 
net.layers{end+1} = struct('type', 'conv', 'weights', {{f*randn(4,4,50,500, 'single'), zeros(1,500,'single')}}, 'stride', 1, 'pad', 0) ; 
net.layers{end+1} = struct('type', 'relu') ; 
net.layers{end+1} = struct('type', 'conv', 'weights', {{f*randn(1,1,500,10, 'single'), zeros(1,10,'single')}}, 'stride', 1, 'pad', 0) ; 
net.layers{end+1} = struct('type', 'softmaxloss') ; 
disp('Net is Ok.'); 
% [net, info] = trainfn(net, imdb, getBatch(opts), 'expDir', opts.expDir, net.meta.trainOpts, opts.train, 'val', find(imdb.images.set == 3)) ; 

[net, info] = cnn_train(net, imdb, @getBatch, opts.train, 'val', find(imdb.images.set == 2)) ; 

網絡部分我把它從MINST例子。我在MatConvNet示例文件夾中保存了該文件和getBatch函數。 當我運行cnn_train我得到這個輸出和錯誤。

enter image description here 任何人,請幫我解決這個錯誤。 另外,我搜索了這個錯誤,我發現我需要檢查mex文件,並使用vl_compilenn('verbose',1)進行編譯。 我也編制,進行了一個錯誤:

使用錯誤MEX

LINK:致命錯誤LNK1104:無法打開文件 「C:\ Users \用戶z5085693 \下載\ matconvnet-1.0-beta23 \ matconvnet -1.0-beta23 \ MATLAB \ MEX \ vl_nnconv.mexw64'

錯誤vl_compilenn> mex_link(線547)MEX(mopts {:});

vl_compilenn錯誤(第498行)mex_link(opts,objs,mex_dir, flags.mexlink);

+0

你會得到什麼錯誤? – rpd

+0

請立即檢查 – Addee

回答

1

請檢查您的網絡,因爲您的網絡有10個輸出,但您希望獲得2個輸出。

0

這種類型的消息「嘗試執行腳本‘名稱’作爲函數」通常會得到通過運行庫的設置來解決。在運行CNN火車功能之前,嘗試運行vl_setupnn函數。

相關問題