参考:(http://www.cnblogs.com/louyihang-loves-baiyan/p/5038758.html)
整个思路大致如下:
Step 1: 数据集准备:http://pan.baidu.com/s/1gfBrmGb 密码:ql14
Step 2: 转化为lmdb数据集
Caffe的数据格式采用leveldb或者lmdb格式的,第一步要做的就是数据的格式转换了;首先将图片分成trainpicture和testpicture,然后作者用matlab生成train.txt和test.txt
准备两个txt文件,放成list的形式,图像路径之后一个空格之后跟着类别的ID,如下,这里记住ID必须从0开始,要连续,否则会出错,loss不下降,按照要求写就OK。这个是训练的图像label,测试的也同理
test.txt 亦如
生成train.txt 和 test.txt代码如下:
clc
clear all
%% 读取文件夹里的图片名称,且将图片名保存到txt
file_path = '../SinImage2/';
img_path_list = dir(strcat(file_path,'*.bmp'));
mkdir('../trainpicture1');
mkdir('../testpicture1');
img_num = length(img_path_list);
img_path_list = img_path_list(randperm(img_num )) ;
img_path_train = img_path_list(1:12000) ;
img_path_test = img_path_list(12001:img_num) ;
img_num = length(img_path_train) ;
fp = fopen('../train.txt','wt');
if img_num > 0 %有满足条件的图像
for j = 1:img_num %逐一读取图像
image_name = img_path_train(j).name;% 图像名
copyfile([file_path image_name] ,'../trainpicture1');
outdata = abs(image_name(8))-48;
if (abs(image_name(8))>60)
outdata = abs(image_name(8))-55;
end
fprintf(fp,'%s %d\n',image_name,outdata);
end
end
fclose(fp)
% test data prepare
img_num = length(img_path_test);
fp = fopen('../test.txt','wt')