均值文件的意义:https://blog.csdn.net/chen1234520nnn/article/details/89519552
1.数据集下载,这里采用用于视觉定位的数据集:https://drive.google.com/drive/folders/1a4qf-ZVsuGF96xsG8_GEgo-ifcAtZMPE数据数据位于db文件夹下(共4479张图):
2.生成标签文件
参考:https://blog.csdn.net/u010417185/article/details/52119863
# <pre class="python" name="code">#coding:utf-8
'''
Created on Jul 29, 2016
@author: sgg
'''
"<span style=""font-family:Arial;font-size:18px;"">"
"<span style=""font-size:18px;"">"
"<span style=""font-size:18px;"">"
import os
def IsSubString(SubStrList,Str):
flag=True
for substr in SubStrList:
if not(substr in Str):
flag=False
return flag
#扫面文件
def GetFileList(FindPath,FlagStr=[]):
FileList=[]
FileNames=os.listdir(FindPath)
if len(FileNames)>0:
for fn in FileNames:
if len(FlagStr)>0:
if IsSubString(FlagStr,fn):
fullfilename=os.path.join(FindPath,fn)
FileList.append(fullfilename)
else:
fullfilename=os.path.join(FindPath,fn)
FileList.append(fullfilename)
if len(FileList)>0:
FileList.sort()
return FileList
train_txt=open('train.txt','w')
imgfile=GetFileList('db')#将数据集放在与.py文件相同目录下
for img in imgfile:
str1=img+' '+'1'+'\n' #用空格代替转义字符 \t
train_txt.writelines(str1)
print("成功生成文件列表")
切换到对应目录下,cmd中运行上面的py文件,生成train.txt
3.Window 下编译Caffe 生成的工程caffe-windows\scripts\build\install\bin 下compute_image_mean.exe和convert_imageset.exe 两个可执行文件,编译过程参考:https://blog.csdn.net/Z5122/article/details/90759355
3.1.生成lmdb文件,参考:https://blog.csdn.net/sinat_28519535/article/details/78533319
将数据集拷贝到与前面两个exe同目录下(这里为caffe-windows\scripts\build\install\bin\data\db下),上一步生成的train.txt也位于同一目录下,创建convertimage2lmdb.txt,
输入如下内容:
//第一行
SET GLOG_logtostderr=1
//第二行
convert_imageset.exe --shuffle --resize_height=512 --resize_width=512 G:/caffeproject/caffe-windows/scripts/build/install/bin/data/ train.txt trainlmdb 0
//第三行
pause
第二行的参数说明参考:https://blog.csdn.net/sinat_28519535/article/details/78533319
保存后,改后缀为bat,双击运行,caffe-windows\scripts\build\install\bin下生成trainlmdb文件夹,包括:
3.2.生成binaryproto文件,bin目录下创建compute_mean.txt,输入如下内容:
SET GLOG_logtostderr=1
compute_image_mean.exe trainlmdb train_mean.binaryproto
pause
保存后,改后缀为bat,双击运行,caffe-windows\scripts\build\install\bin下生成train_mean.binaryproto。