这个工作其实是第四周完成的。
首先对比一下人脸检测的数据集。
wider_face和FDDB数据集。
wider_face人脸更多,训练结果当然更好。但是使用起来很麻烦。
所以我选择FDDB数据集,但是darknet的格式却和FDDB的格式不一样,这怎么办呢?
那就需要把FDDB的数据格式转成VOC格式,
再把VOC格式转成darkenet所认识的格式
这是我的代码
import os,cv2
from math import *
import numpy as np
from xml.dom.minidom import Document
rootdir="/home/zibojia"
#you
origimagedir=rootdir+"/orignal_face"
#you
imagesdir=rootdir+"/voc_face"
#you
annotationdir=rootdir+"/FDDB-folds"
#
labelsdir=rootdir+"/labels"
#
Annotationsdir=rootdir+"/Annotations"
convert2rects=True
bsavexmlanno=True
bsavetxtanno=True
# the dir that store the pics
datasetprefix="/home/zibojia/voc_face/"
def show_annotations():
if not os.path.exists(Annotationsdir):
os.mkdir(Annotationsdir)
if not os.path.exists(labelsdir):
os.mkdir(labelsdir)
for i in range(10):
#you
annotationfilepath=annotationdir+"/FDDB-fold-%0*d-ellipseList.txt"%(2,i+1)
annotationfile=open(annotationfilepath)
while(True):
filename=annotationfile.readline()[:-1]+".jpg"
if not filename:
break
line=annotationfile.readline()
if not line:
break
print filename
facenum=(int)(line)
img=cv2.imread(origimagedir+"/"+filename)
filename=filename.replace('/','_')
cv2.imwrite(imagesdir+"/"+filename,img)
w = img.shape[1]
h = img.shape[0]
if bsavetxtanno:
labelpath=labelsdir+"/"+filename.replace('/','_')[:-3]+"txt"
labelfile=open(labelpath,'w')
if bsavexmlanno:
xmlpath=Annotationsdir+"/"+filename.replace('/','_')[:-3]+"txt"
xmlpath=xmlpath[:-3]+"xml"
doc = Document()
annotation = doc.createElement('annotation')
doc.appendChild(annotation)
folder = doc.createElement('folder')
folder_name = doc.createTextNode('fddb')
folder.appendChild(folder_name)
annotation.appendChild(folder)
filenamenode = doc.createElement('filename')
filename_name = doc.createTextNode(filename)
filenamenode.appendChild(filename_name)
annotation.appendChild(filenamenode)
source = doc.createElement('source')
annotation.appendChild(source)
database = doc.create