在CAFFE中使用HDF5进行视频分类?

时间:2017-09-18 13:39:42

标签: machine-learning deep-learning caffe hdf5

我正在使用hdf5层进行视频分类(C3D)。这是我生成hdf5文件的代码

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

现在,data.h5已保存在文件video.list中。我根据原型文件进行分类

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"
}

然而,我收到了错误

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)

更新:当我将代码更改为f['label'] = 1时,我也收到错误F0918 23:04:39.884270 2138 hdf5.cpp:21] Check failed: ndims >= min_dim (0 vs. 1) 我该如何解决?我想hdf5生成部分在标签字段中有一些错误。谢谢大家

1 个答案:

答案 0 :(得分:0)

  1. 请仔细阅读 你的答案linked
    您的label应为整数且为1热矢量。

  2. 您的data似乎是整数类型。我想你想将它转换为np.float32。当你在它时,考虑减去平均值。

  3. 由于您的HDF5文件只有一个样本,因此您不能将label作为标量(“0 dim array”)。您需要将label设为np.ones((1,1), dtype=np.float32) 使用h5ls ./data.h5验证label确实是数组而不是标量。