2

나는 그 예제 라이브러리와 함께 제공 cnn_train 기능을 사용하여 매우 간단한 1D 예를 들어 작은 네트워크를 구축 MatConvNet을 사용했다MatConvNet에서 데이터와 파생물의 형식이 일치하지 않는다고 말하는 이유는 무엇입니까?

문제 설명.

Error using vl_nnconv 
DATA and DEROUTPUT do not have compatible formats. 

Error in vl_simplenn (line 397) 
      [res(i).dzdx, dzdw{1}, dzdw{2}] = vl_nnconv(res(i).x, l.weights{1}, 
      l.weights{2}, res(i+1).dzdx) 

Error in cnn_train>process_epoch (line 323) 
    res = vl_simplenn(net, im, dzdy, res, ... 

Error in cnn_train (line 139) 
    [net,stats.train,prof] = process_epoch(opts, getBatch, epoch, train, learningRate, 
    imdb, net) ; 

Error in main_1D_1layer_hard_coded_example (line 64) 
net = cnn_train(net, imdb, @getBatch, trainOpts) ; 

누군가에 무슨 일이 일어나고 있는지 알고 않습니다

clc;clear;clc;clear; 
%% prepare Data 
M = 32; %batch size 
X_train = zeros(1,1,1,M); % (1 1 1 2) = (1 1 1 M) 
for m=1:M, 
    X_train(:,:,:,m) = m; %training example value 
end 
Y_test = 10*X_train; 
split = ones(1,M); 
split(floor(M*0.75):end) = 2; 
% load image dadabase (imgdb) 
imdb.images.data = X_train; 
imdb.images.label = Y_test; 
imdb.images.set = split; 
%% prepare parameters 
L1=3; 
w1 = randn(1,1,1,L1); %1st layer weights 
w2 = randn(1,1,1,L1); %2nd layer weights 
b1 = randn(1,1,1,L1); %1st layer biases 
b2 = randn(1,1,1,L1); %2nd layer biases 
G1 = ones(1,1,1,L1); % (1 1 1 3) = (1 1 1 L1) BN scale, one per dimension 
B1 = zeros(1,1,1,L1); % (1 1 1 3) = (1 1 1 L1) BN shift, one per dimension 
EPS = 1e-4; 
%% make CNN layers: conv, BN, relu, conv, pdist, l2-loss 
net.layers = {} ; 
net.layers{end+1} = struct('type', 'conv', ... 
          'name', 'conv1', ... 
          'weights', {{w1, b1}}, ... 
          'pad', 0) ; 
net.layers{end+1} = struct('type', 'bnorm', ... 
          'weights', {{G1, B1}}, ... 
          'EPSILON', EPS, ... 
          'learningRate', [1 1 0.05], ... 
          'weightDecay', [0 0]) ;      
net.layers{end+1} = struct('type', 'relu', ... 
          'name', 'relu1') ; 
net.layers{end+1} = struct('type', 'conv', ... 
          'name', 'conv2', ... 
          'weights', {{w2, b2}}, ... 
          'pad', 0) ; 
net.layers{end+1} = struct('type', 'pdist', ... 
          'name', 'averageing1', ... 
          'class', 0, ... 
          'p', 1) ; 
%% add L2-loss     
fwfun = @l2LossForward; 
bwfun = @l2LossBackward; 
net = addCustomLossLayer(net, fwfun, bwfun) ; 
net.layers{end}.class = Y_test; % its the test set 
net = vl_simplenn_tidy(net) ; 
res = vl_simplenn(net, X_train); 
%% prepare train options 
trainOpts.expDir = 'results/' ; %save results/trained cnn 
trainOpts.gpus = [] ; 
trainOpts.batchSize = 2 ; 
trainOpts.learningRate = 0.02 ; 
trainOpts.plotDiagnostics = false ; 
%trainOpts.plotDiagnostics = true ; % Uncomment to plot diagnostics 
trainOpts.numEpochs = 20 ; % number of training epochs 
trainOpts.errorFunction = 'none' ; 
%% CNN TRAIN 
vl_simplenn_display(net) ; 
net = cnn_train(net, imdb, @getBatch, trainOpts) ; 

내가 예제를 실행 할 때마다 나는이 the example they provided에 따라 나는 오류가 만든 다음과 같이 자신의 예를 따라 난 작은 CNN 예를 구축 ? 이 예제는 실제로 단순한 것으로 가정되어서 나에게 혼동을 줄 수 있습니다. 사물의


보충 제는 내가 본를 해결하기 위해 시도했습니다.

자세한 내용은이 문제를 해결하기 위해 시도해 보았습니다.

case 'conv' 
     size(res(i).x) 
     size(res(i+1).dzdx) 
     size(l.weights{1}) 
     size(l.weights{2}) 
     [res(i).dzdx, dzdw{1}, dzdw{2}] = vl_nnconv(res(i).x, l.weights{1}, l.weights{2}, res(i+1).dzdx) 
    [res(i).dzdx, dzdw{1}, dzdw{2}] = ... 
     vl_nnconv(res(i).x, l.weights{1}, l.weights{2}, res(i+1).dzdx, ... 
     'pad', l.pad, ... 
     'stride', l.stride, ... 
     l.opts{:}, ... 
     cudnn{:}) ; 

:

는 내가 감각을 만들어 그 모두가 그 점에 괜찮 보인다 인수를 포기했다 있는지 확인하는 함수에 입력 오류의 원인이 파일의 해당 행에 가서 인쇄 인쇄물 :

ans = 

    1  1  3 16 


ans = 

    1  1  3 16 


ans = 

    1  1  1  3 


ans = 

    1  1  1  3 

예상했던 것.

심지어 앞서 수동으로 하드 네트워크가 계산해야 파생 상품의 사슬 해당 파일이 잘 작동하는 것 같다 무엇으로 구분했다 : 나는에 모든 것이 가정 줄 수 있도록

clc;clear;clc;clear; 
%% prepare Data 
M = 3; 
x = zeros(1,1,1,M); % (1 1 1 2) = (1 1 1 M) 
for m=1:M, 
    x(:,:,:,m) = m; 
end 
Y = 5; 
r=Y; 
%% parameters 
L1 = 3; 
w1 = randn(1,1,1,L1); % (1 1 1 L1) = (1 1 1 3) 
b1 = ones(1,L1); 
w2 = randn(1,1,1,L1); % (1 1 1 L1) = (1 1 1 3) 
b2 = ones(1,L1); 
G1 = ones(1,1,1,L1); % (1 1 1 3) = (1 1 1 L1) BN scale, one per dimension 
B1 = zeros(1,1,1,L1); % (1 1 1 3) = (1 1 1 L1) BN shift, one per dimension 
EPS = 1e-4; 
%% Forward Pass 
z1 = vl_nnconv(x,w1,b1); % (1 1 3 2) = (1 1 L1 M) 
%bn1 = z1; 
bn1 = vl_nnbnorm(z1,G1,B1,'EPSILON',EPS); % (1 1 3 2) = (1 1 L1 M) 
a1 = vl_nnrelu(bn1); % (1 1 3 2) = (1 1 L1 M) 
z2 = vl_nnconv(a1,w2,b2); 
y1 = vl_nnpdist(z2, 0, 1); 
loss_forward = l2LossForward(y1,Y); 
%% 
net.layers = {} ; 
net.layers{end+1} = struct('type', 'conv', ... 
          'name', 'conv1', ... 
          'weights', {{w1, b1}}, ... 
          'pad', 0) ; 
net.layers{end+1} = struct('type', 'bnorm', ... 
          'weights', {{G1, B1}}, ... 
          'EPSILON', EPS, ... 
          'learningRate', [1 1 0.05], ... 
          'weightDecay', [0 0]) ;      
net.layers{end+1} = struct('type', 'relu', ... 
          'name', 'relu1') ; 
net.layers{end+1} = struct('type', 'conv', ... 
          'name', 'conv2', ... 
          'weights', {{w2, b2}}, ... 
          'pad', 0) ; 
net.layers{end+1} = struct('type', 'pdist', ... 
          'name', 'averageing1', ... 
          'class', 0, ... 
          'p', 1) ; 
fwfun = @l2LossForward; 
bwfun = @l2LossBackward; 
net = addCustomLossLayer(net, fwfun, bwfun) ; 
net.layers{end}.class = Y; 
net = vl_simplenn_tidy(net) ; 
res = vl_simplenn(net, x); 
%% 
loss_forward = squeeze(loss_forward) % (1 1) 
loss_res = squeeze(res(end).x) % (1 1) 
%% Backward Pass 
p = 1; 
dldx = l2LossBackward(y1,r,p); 
dy1dx = vl_nnpdist(z2, 0, 1, dldx); 
[dz2dx, dz2dw2] = vl_nnconv(a1, w2, b2, dy1dx); 
da1dx = vl_nnrelu(bn1, dz2dx); 
[dbn1dx,dbn1dG1,dbn1dB1] = vl_nnbnorm(z1,G1,B1,da1dx); 
[dz1dx, dz1dw1] = vl_nnconv(x, w1, b1, dbn1dx); 
%% 
dzdy = 1; 
res = vl_simplenn(net, x, dzdy, res); 
%% 
% func = @(x) proj(p, forward(x, x0)) ; 
% err = checkDerivativeNumerically(f, x, dx) 
% %% 
dz1dx = squeeze(dz1dx) 
dz1dx_vl_simplenn = squeeze(res(1).dzdx) 

파생 상품

수학에 보인다 그 파일이 작동합니다. 오류가 발생하지 않기 때문에 실행되지 않는다는 사실은 나 혼란 스럽다. 누구나 무슨 일이 벌어지고 있는지 알아?


내 CNN을로드하는 방법은 the example file을 기반으로하며이 튜토리얼에서 제공합니다. 그 파일의 중요한 측면에 대한 요약을 붙여 넣을 것입니다 (광산이 아닌 동안에는 cnn_train 함수로 잘 돌아갑니다).

setup() ; 
% setup('useGpu', true); % Uncomment to initialise with a GPU support 
%% Part 3.1: Prepare the data 
% Load a database of blurred images to train from 
imdb = load('data/text_imdb.mat') ; 

%% Part 3.2: Create a network architecture 

net = initializeSmallCNN() ; 
%net = initializeLargeCNN() ; 
% Display network 
vl_simplenn_display(net) ; 

%% Part 3.3: learn the model 
% Add a loss (using a custom layer) 
net = addCustomLossLayer(net, @l2LossForward, @l2LossBackward) ; 

% Train 
trainOpts.expDir = 'data/text-small' ; 
trainOpts.gpus = [] ; 
% Uncomment for GPU training: 
%trainOpts.expDir = 'data/text-small-gpu' ; 
%trainOpts.gpus = [1] ; 
trainOpts.batchSize = 16 ; 
trainOpts.learningRate = 0.02 ; 
trainOpts.plotDiagnostics = false ; 
%trainOpts.plotDiagnostics = true ; % Uncomment to plot diagnostics 
trainOpts.numEpochs = 20 ; 
trainOpts.errorFunction = 'none' ; 

net = cnn_train(net, imdb, @getBatch, trainOpts) ; 
+2

덜 비범 한 예를 생각해 낼 수 있습니까? * non * -minimal? –

+0

@AndrasDeak 확실히, 당신은 복잡한 것을 의미합니까? 그것은 단순한 네트워크라고 가정하고 나는 그것을 고치려고 노력한 것들 중 일부를 제공했습니다. – Pinocchio

+0

나는 그 간단한 것을 납득시키기 위해 더 많은 예제를 주석으로 써 보았습니다. 희망이 도움이됩니다. – Pinocchio

답변

3

w2의 크기는 1x1x3x3이어야합니다.

또한 보통 하나의 차원 (가중치에 대해서는 1x1x3xN, 해당 편향에 대해서는 1xN, N은 필터 수임) 만 있기 때문에 바이어스는 1x3으로 주어지며 B1과 B1에 대해서도 마찬가지입니다. G1 (여기서 1xM, M은 이전 계층의 필터 수). 그러나 어느 쪽이든 작동 할 수 있습니다.

예에서 x의 크기는 첫 번째 컨볼 루션 이후 1x1x3x16입니다. 즉, 각 요소의 너비와 높이가 1이고 깊이가 3 인 16 개의 요소가 하나의 배치에 있음을 의미합니다. 깊이 3은 첫 번째 컨볼 루션이 3 개의 필터 (w1은 1x1x1x3 크기)로 이루어 졌기 때문입니다.

예제의 w2 크기는 너비, 높이 및 깊이 1의 3 개의 필터를 나타내는 1x1x1x3 크기입니다. 따라서 필터의 깊이가 입력의 깊이와 일치하지 않습니다.

+0

2 개의 코멘트, 1) w2 1x1x3x3을 만들었지 만 여전히 불행하게도 실행되지 않았습니다. 2) 당신의 논리가 논리적 인 의미를 갖지만, 여전히 나에게 당황스러워하는 점은, 당신의 주장이 맞다면 그 모델에서 성공적으로 순회를 할 수있는 이유는 무엇입니까? 내가 작성한 코드에서 모델을 평가하고 놀랍게 실제로 실행되는'res = vl_simplenn (net, X_train); 행이 있습니다. 치수의 불일치가있는 경우 왜 앞으로 패스가 실행됩니까? 아직 모르겠지만 백 패스가 오류 출력의 문제인 것처럼 보입니다. 나는 확인하려고 노력할 것이다. – Pinocchio

+1

나는 그것을 간파 했음에 틀림 없다. 이상하다. 어쩌면 다음 며칠 동안 자신의 코드를 직접 시험해 볼 시간이있을 것입니다. – Wiseful

0

사용자 지정 레이어를 만들어 동일한 문제가 발생했습니다. 마침내 matconvnet 구현을 추적하여 해결책을 찾았습니다. 나중에 다른 도움이되기를 바랍니다.

즉, 두 데이터가 비어 있지 않고 null이 아니고 동일한 장치 유형 (GPU 또는 CPU)과 동일한 데이터 유형 (float, single 또는 char)을 가지고 있는지 확인해야합니다.

필자의 경우 두 데이터 모두 'gpuArray'와 'single'이 같아야합니다. 첫째

====== 세부 사항 ================== ,

DATA and FILTERS do not have compatible formats

DATA and BIASES do not have compatible formats

DATA and DEROUTPUT do not have compatible formats

정확히 두 변수가없는 것을 말하는 오류 호환 가능한 형식. Matconvnet은 '호환 가능한 형식'을 의미합니까? 그것은 선 269 ~ 278

/* check for GPU/data class consistency */ 


if (hasFilters && ! vl::areCompatible(data, filters)) { 
    vlmxError(VLMXE_IllegalArgument, "DATA and FILTERS do not have compatible formats.") ; 
    } 
    if (hasBiases && ! vl::areCompatible(data, biases)) { 
    vlmxError(VLMXE_IllegalArgument, "DATA and BIASES do not have compatible formats.") ; 
    } 
    if (backMode && ! vl::areCompatible(data, derOutput)) { 
    vlmxError(VLMXE_IllegalArgument, "DATA and DEROUTPUT do not have compatible formats.") ; 
    } 

오류가

그래서
inline bool areCompatible(Tensor const & a, Tensor const & b) 
    { 
    return 
    (a.isEmpty() || a.isNull()) || 
    (b.isEmpty() || b.isNull()) || 
    ((a.getDeviceType() == b.getDeviceType()) & (a.getDataType() == b.getDataType())) ; 
    } 

로서 구현되는 기능 VL :: areCompatible 온, vl_nnconv.cu 구현되고, 기본적으로, 임의의 입력이 있는지 확인 비어 있거나 널 (null)로 지정하고 두 입력이 모두 동일한 데이터 유형 (double, single, vs char) 및 디바이스 유형 (GPU, CPU)을 갖는지 확인합니다.

/// Type of device: CPU or GPU 
    enum DeviceType { 
    VLDT_CPU = 0, 
    VLDT_GPU 
    } ; 

    /// Type of data (char, float, double, ...) 
    enum DataType { 
    VLDT_Char, 
    VLDT_Float, 
    VLDT_Double 
    } ; 
관련 문제