0

I'd like to train a neural network (NN) on my own 1-dim data, which I stored in a hdf5 database for caffe. According to the documetation this should work. It also works for me as far as I only use "Fully Connected Layers", "Relu" and "Dropout". However I get an error when I try to use "Convolution" and "Max Pooling" layers in the NN architecture. The error complains about the input dimension of the data.

I0622 16:44:20.456007  9513 net.cpp:84] Creating Layer conv1
I0622 16:44:20.456015  9513 net.cpp:380] conv1 <- data
I0622 16:44:20.456048  9513 net.cpp:338] conv1 -> conv1
I0622 16:44:20.456061  9513 net.cpp:113] Setting up conv1
F0622 16:44:20.456487  9513 blob.cpp:28] Check failed: shape[i] >= 0 (-9 vs. 0) 

This is the error when I only want to use a "Pooling" layer behind an "InnerProduct" layer:

I0622 16:52:44.328660  9585 net.cpp:338] pool1 -> pool1
I0622 16:52:44.328666  9585 net.cpp:113] Setting up pool1
F0622 16:52:44.328680  9585 pooling_layer.cpp:84] Check failed: 4 == bottom[0]->num_axes() (4 vs. 2) Input must have 4 axes, corresponding to (num, channels, height, width)

However I don't know how to change the input dimensions such that it works. This is the beginning of my prototxt file specifying the network architecture:

name: "LeNet"
layer {
  name: "myNet"
  type: "HDF5Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  hdf5_data_param {
    source: "/path/to/my/data/train.txt"
    batch_size: 200
  }
}

layer {
  name: "myNet"
  type: "HDF5Data"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
  hdf5_data_param {
    source: "/path/to/my/data/test.txt"
    batch_size: 200
  }
}

layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 1
    kernel_h: 11
    kernel_w: 1    
    stride: 1
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "conv1"
  top: "conv1"
}
layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_h: 3
    kernel_w: 1
    stride: 2
  }
}

And this is how I output my 4D-database (with two singleton dimensions) using Matlabs h5write function:

h5create('train.h5','/data',[dimFeats 1 1 numSamplesTrain]);
h5write('train.h5','/data', traindata); 
mcExchange
  • 6,154
  • 12
  • 57
  • 103
  • Possible duplicate of [\[caffe\]: check fails: Check failed: hdf\_blobs\_\[i\]->shape(0) == num (200 vs. 6000)](http://stackoverflow.com/questions/34418027/caffe-check-fails-check-failed-hdf-blobs-i-shape0-num-200-vs-6000) – Shai Apr 20 '16 at 18:25

2 Answers2

1

You seem to be outputting your data using the wrong shape. Caffe blobs have the dimensions (n_samples, n_channels, height, width) .

Other than that your prototxt seems to be fine for doing predictions based on a 1D input.

pir
  • 5,513
  • 12
  • 63
  • 101
  • You are right, my input dimensions were wrong. I found out by carefully checking the terminal output, while caffe is creating the neural net. There it says something like `Top shape: 200 1 1 4872 (974400) `. By carefully checking the in and output dimensions of each layer due to these logging outputs I could fix my problem. Thanks – mcExchange Jun 23 '15 at 13:41
  • By the way, you might want a smaller batch size than 200, that requires quite a bit of memory. – pir Jun 23 '15 at 17:34
  • 1
    Not specifically for OP but if it can help someone: I had similar symptoms, however the actual problem was not in the net itself, but in the data. I was feeding different datasets with various widths (1D lengths) and one dataset happened to had a very short width, too short for the net used. So make sure your input dimensions are big enough. – mdup Nov 03 '15 at 08:29
0

As I have no experience in using the h5create and h5write in Matlab, I am not sure on whether the training dataset is generated with the dimensions that you expect it to generate.

The error msg for the convolution layer says that shape[i] = -9. This means that either the width, height, channels or number of images in a batch is being set to -9.

The error msg when using pooling layer alone says that the network could detect only an input of 2D while the network is expecting an input of 4D.

The error messages in both the layers are related to reshaping the blobs and this is a clear indication that the dimensions of the input are not as expected.

Try debugging the Reshape functions present in blob.cpp & layers/pooling_layer.cpp to get an insight on which value is actually going rogue.

Anoop K. Prabhu
  • 5,417
  • 2
  • 26
  • 43