在CAFFE中使用HDF5进行视频分类? [英] Video classification using HDF5 in CAFFE?

查看:112
本文介绍了在CAFFE中使用HDF5进行视频分类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

现在,data.h5保存在文件video.list中.我根据原型创建分类

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

但是,我得到的错误是

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生成部分在标签字段中有一些错误.谢谢大家

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

推荐答案

  1. 仔细阅读您的答案

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

似乎您的data是整数类型.我想您想将其转换为np.float32.而在使用它时,请考虑减去均值.

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.

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

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.

这篇关于在CAFFE中使用HDF5进行视频分类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆