我想使用带有矢量标签而不是整数的caffe。我检查了一些答案,看来HDF5是更好的方法。但是后来我陷入了这样的错误:
precision_layer.cpp:34]检查失败:outer_num_ * inner_num_ == bottom[1]->count()(50对200)标签数必须与预测数相匹配;例如,如果标签轴== 1并且预测形状为(N,C,H,W),则标签计数(标签数量)必须为N*H*W,且整数值分别为{0,1,…,C-1}。
HDF5创建为: f = h5py.File('train.h5', 'w') f.create_dataset('data', (1200, 128), dtype='f8') f.create_dataset('label', (1200, 4), dtype='f4')
我的网络是通过以下方式生成的:
def net(hdf5, batch_size): n = caffe.NetSpec() n.data, n.label = L.HDF5Data(batch_size=batch_size, source=hdf5, ntop=2) n.ip1 = L.InnerProduct(n.data, num_output=50, weight_filler=dict(type='xavier')) n.relu1 = L.ReLU(n.ip1, in_place=True) n.ip2 = L.InnerProduct(n.relu1, num_output=50, weight_filler=dict(type='xavier')) n.relu2 = L.ReLU(n.ip2, in_place=True) n.ip3 = L.InnerProduct(n.relu1, num_output=4, weight_filler=dict(type='xavier')) n.accuracy = L.Accuracy(n.ip3, n.label) n.loss = L.SoftmaxWithLoss(n.ip3, n.label) return n.to_proto() with open(PROJECT_HOME + 'auto_train.prototxt', 'w') as f: f.write(str(net('/home/romulus/code/project/train.h5list', 50))) with open(PROJECT_HOME + 'auto_test.prototxt', 'w') as f: f.write(str(net('/home/romulus/code/project/test.h5list', 20)))
似乎我应该增加标签数量并将其放入整数而不是数组中,但是如果我这样做,caffe会抱怨数据数量和标签不相等,然后就存在。
那么,提供多标签数据的正确格式是什么?
另外,我很好奇,为什么没有人只是简单地编写HDF5映射到caffe blob的数据格式?