-1

I am using hdf5 layer for video classification (C3D). This is my code to generate hdf5 file

import h5py
import numpy as np
import skvideo.datasets
import skvideo.io

videodata = skvideo.io.vread('./v_ApplyEyeMakeup_g01_c01.avi')
videodata=videodata.transpose(3,0,1,2) # To chanelxdepthxhxw
videodata=videodata[None,:,:,:]

with h5py.File('./data.h5','w') as f:
    f['data'] = videodata
    f['label'] = 1

Now, the data.h5 is saved in the file video.list. I perform the classification based on the prototxt

layer {
  name: "data"
  type: "HDF5Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  hdf5_data_param {
    source: "./video.list"
    batch_size: 1
    shuffle: true
  }
}
layer {
  name: "conv1a"
  type: "Convolution"
  bottom: "data"
  top: "conv1a"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  convolution_param {
    num_output: 32
    pad: 1
    kernel_size: 3
    stride: 1
    weight_filler {
      type: "msra"
    }
    bias_filler {
      type: "constant"
      value: -0.1
    }
    axis: 1
  }
}
layer {
  name: "fc8"
  type: "InnerProduct"
  bottom: "conv1a"
  top: "fc8"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  param {
    lr_mult: 2
    decay_mult: 0
  }
  inner_product_param {
    num_output: 101
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}
layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "fc8"
  bottom: "label"
  top: "loss"
}

However, I got the error as

I0918 22:29:37.163431 32197 hdf5.cpp:35] Datatype class: H5T_INTEGER
F0918 22:29:37.164500 32197 blob.hpp:122] Check failed: axis_index < num_axes() (1 vs. 1) axis 1 out of range for 1-D Blob with shape 6 (6)

Update: When I change the code as f['label'] = 1, I also got the error F0918 23:04:39.884270 2138 hdf5.cpp:21] Check failed: ndims >= min_dim (0 vs. 1) How should I fix it? I guess the hdf5 generating part has some error in label field. Thanks all

John
  • 2,838
  • 7
  • 36
  • 65

1 Answers1

0
  1. Please read carefully the answer you linked:
    Your label should be an integer and not a 1-hot vector.

  2. It seems like your data is of type integer. I suppose you would like to convert it to np.float32. And while you are at it, consider subtracting the mean.

  3. Since your HDF5 file has only one sample, you cannot have label as a scalar ("0 dim array"). You need to make label as np.ones((1,1), dtype=np.float32).
    Use h5ls ./data.h5 to verify that label is indeed an array and not a scalar.

Community
  • 1
  • 1
Shai
  • 111,146
  • 38
  • 238
  • 371
  • Thanks, Shai. Of course, i check label as `label=1` before and I got the error `Check failed: ndims >= min_dim (0 vs. 1) `. Let see my update question – John Sep 18 '17 at 14:04
  • 1
    You are right. It worked now. Thanks so much. What is happen if I have 6 labels. For example, video 1->label 1, video2->label 2 and so on – John Sep 18 '17 at 14:21