我们参考caffe中ImageNet的例子来完成图像分类,我们的流程如下
1.参考ImageNet的代码,构建我们自己的数据集,jpg格式的图像分为train和val,即训练集和测试集
2.在文本文件中列出图像和标注
3.修改create_convert脚本,将图像转化为lmdb格式,注意,一定是jpg格式的图像,如果没有进行大小归一化,最好在脚本中进行缩放操作
4.使用make_mean脚本,计算图像均值
5.修改solver_prototxt文件和train_val_prototxt文件中的参数,进行训练
这里只列个提纲,网上的参考代码比较多,这里再附赠一个工具
附带自动生成列表文件的python代码:
import os.path,os
import sys
def cur_file_dir():
path = sys.path[0]
if os.path.isdir(path):
return path
elif os.path.isfile(path):
return os.path.dirname(path)
def StringSort(strList):
strTuple = [(int(line[:-4]), line) for line in strList]
strTuple.sort()
return [s for __, s in strTuple]
filePath=cur_file_dir()
listfile=os.listdir(filePath)
#print(listfile)
filename=raw_input("Please input filename (\\usr\\temp)")
os.chdir(filePath)
with open("./../"+filename,"w") as out:
mylist=[]
for line in listfile:
#print line
if line[-4:]=='.bmp' or line[-4:]=='.jpg':
mylist.append(line)
#out.write(line+" \t-1\n")
mylist=StringSort(mylist)
for line in mylist:
out.write(line+" \t-1\n")
print("Done")
放置于图片目录下,会在父目录生成文本文件,并可由键盘输入的方式指定输出文本文件的文件名。