我很难在图像分类和回归任务上使用HDF5进行caffe,出于某种原因,HDF5的训练在第一次开始时总会失败,测试和火车损失很快就会降到接近零。在尝试了所有降低学习速度的技巧后,添加RELU,辍学,什么都没有开始工作,所以我开始怀疑我正在为caffe提供的HDF5数据是错误的。
所以目前我正在研究通用数据集(Oxford 102 category flower dataset并且它还有public code),首先我开始尝试使用ImageData和LMDB层进行分类,它们都运行良好。最后我使用HDF5数据层进行微调,除非在使用HDF5的数据层上,否则training_prototxt不会改变。再次,在学习开始时,损失在迭代60时从5下降到0.14,在迭代100下从0.00146下降,这似乎证明HDF5数据不正确。
我在github上有HDF5片段的两个图像和标签,所有这些片段似乎都会生成HDF5数据集,但由于某些原因,这些数据集似乎不能与caffe一起使用
我想知道这些数据有什么问题,或者是什么使得这个例子在HDF5中运行,或者你有一些用于分类或回归的HDF5示例,这对我很有帮助。
一个代码段显示为
def generateHDF5FromText2(label_num):
print '\nplease wait...'
HDF5_FILE = ['hdf5_train.h5', 'hdf5_test1.h5']
#store the training and testing data path and labels
LIST_FILE = ['train.txt','test.txt']
for kk, list_file in enumerate(LIST_FILE):
#reading the training.txt or testing.txt to extract the all the image path and labels, store into the array
path_list = []
label_list = []
with open(list_file, buffering=1) as hosts_file:
for line in hosts_file:
line = line.rstrip()
array = line.split(' ')
lab = int(array[1])
label_list.append(lab)
path_list.append(array[0])
print len(path_list), len(label_list)
# init the temp data and labels storage for HDF5
datas = np.zeros((len(path_list),3,227,227),dtype='f4')
labels = np.zeros((len(path_list), 1),dtype="f4")
for ii, _file in enumerate(path_list):
# feed the image and label data to the TEMP data
img = caffe.io.load_image( _file )
img = caffe.io.resize( img, (227, 227, 3) ) # resize to fixed size
img = np.transpose( img , (2,0,1))
datas[ii] = img
labels[ii] = int(label_list[ii])
# store the temp data and label into the HDF5
with h5py.File("/data2/"+HDF5_FILE[kk], 'w') as f:
f['data'] = datas
f['label'] = labels
f.close()
答案 0 :(得分:2)
一个输入转换似乎发生在原始网络中,并且在平均减法中的HDF5创建中丢失了。
您应该获得平均文件(在您的示例中看起来像"imagenet_mean.binaryproto"
),将其读入python并从每个图像中减去它。
BTW,平均文件可以为您提供输入图像比例的线索(如果像素值应在[0..1]范围内或[0..255])。
您可能会发现caffe.io
有用的将binaryproto转换为numpy数组。