【问题标题】:Error in training CNN for binary classification训练 CNN 进行二进制分类时出错
【发布时间】:2023-03-04 13:16:02
【问题描述】:

您好,为了熟悉 CNN,我准备了二进制分类飞机(760 幅图像)或非飞机(750)的代码。

这是我的 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 示例中获取的网络部分。我已将此文件和 getBatch 函数保存在 MatConvNet 示例文件夹中。 当我运行 cnn_train 时,我得到了这个输出和错误。

任何人,请帮我解决这个错误。 另外,我搜索了这个错误,我发现我需要检查 mex 文件并使用 vl_compilenn('verbose', 1) 进行编译。 我在编译时也遇到了错误:

使用 mex 时出错

LINK:致命错误 LNK1104:无法打开文件 'C:\Users\z5085693\Downloads\matconvnet-1.0-beta23\matconvnet-1.0-beta23\matlab\mex\vl_nnconv.mexw64'

vl_compilenn 中的错误>mex_link (line 547) mex(mopts{:}) ;

vl_compilenn 中的错误(第 498 行)mex_link(opts, objs, mex_dir, flags.mexlink) ;

【问题讨论】:

  • 你得到什么错误?

标签: deep-learning conv-neural-network matconvnet


【解决方案1】:

请检查您的网络,因为您的网络有 10 个输出,但您希望获得 2 个输出。

【讨论】:

    【解决方案2】:

    这种类型的消息“尝试将 SCRIPT “名称”作为函数执行”通常可以通过运行库的设置来解决。在运行 CNN 训练函数之前,请尝试运行 vl_setupnn 函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-25
      • 2017-07-18
      • 2017-06-02
      • 1970-01-01
      • 2019-01-20
      • 2020-09-16
      • 2019-05-17
      • 2021-04-26
      相关资源
      最近更新 更多