我正在使用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生成部分在标签字段中有一些错误。谢谢大家
答案 0 :(得分:0)
请仔细阅读 你的答案linked:
您的label
应为整数且不为1热矢量。
您的data
似乎是整数类型。我想你想将它转换为np.float32
。当你在它时,考虑减去平均值。
由于您的HDF5文件只有一个样本,因此您不能将label
作为标量(“0 dim array”)。您需要将label
设为np.ones((1,1), dtype=np.float32)
使用h5ls ./data.h5
验证label
确实是数组而不是标量。