前言
(1)本文主要讲步骤,想知道为什么的可以自行查阅其他博客
(2)在复现这个代码前,推荐先运行最原始的yolo3代码,这个网上有很多教程,推荐一下这个博客:
https://blog.csdn.net/u012746060/article/details/81183006,跟着【二、快速使用】自己先体会一下
(3)本文涉及到的内容都可以从网上免费下载,下面上链接:
keras-yolo3的代码:https://github.com/qqwweee/keras-yolo3
wider_face数据集:http://shuoyang1213.me/WIDERFACE/
这4个都要下载下来,新建一个wider_face文件夹放这4个东西
下面就是具体怎么操作了
(4)根据我自己的经验,在最开头先把整个项目的结构大家看一下,大家也许会在后面用到
第一步:布置好数据集
(1)将上面下载好的keras-yolo3-master放入pycharm中,如图
(2)将wider_face文件夹放进keras-yolo3-master的项目中,如图
(3)在keras-yolo3-master中新建VOC一系列文件夹,包括里面的这么多个文件夹都要,名字要一样(这个是yolo中所使用的数据集的固定名字,跟着建就是了。更具体的,等全部弄完自己看一下代码就知道了)
(4)在keras-yolo3-master中新建一个Python文件:widerfaceTovoc.py
# -*- coding: utf-8 -*-
from skimage import io
import shutil
import random
import os
import string
headstr = """\
<annotation>
<folder>VOC2007</folder>
<filename>%06d.jpg</filename>
<source>
<database>My Database</database>
<annotation>PASCAL VOC2007</annotation>
<image>flickr</image>
<flickrid>NULL</flickrid>
</source>
<owner>
<flickrid>NULL</flickrid>
<name>company</name>
</owner>
<size>
<width>%d</width>
<height>%d</height>
<depth>%d</depth>
</size>
<segmented>0</segmented>
"""
objstr = """\
<object>
<name>%s</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>%d</xmin>
<ymin>%d</ymin>
<xmax>%d</xmax>
<ymax>%d</ymax>
</bndbox>
</object>
"""
tailstr = '''\
</annotation>
'''
def all_path(filename):
return os.path.join('wider_face', filename)
def writexml(idx, head, bbxes, tail):
filename = all_path("Annotations/%06d.xml" % (idx))
f = open(filename, "w")
f.write(head)
for bbx in bbxes:
f.write(objstr % ('face', bbx[0], bbx[1], bbx[0] + bbx[2], bbx[1] + bbx[3]))
f.write(tail)
f.close()
def clear_dir():
if shutil.os.path.exists(all_path('Annotations')):
shutil.rmtree(all_path('Annotations'))
if shutil.os.path.exists(all_path('ImageSets')):
shutil.rmtree(all_path('ImageSets'))
if shutil.os.path.exists(all_path('JPEGImages')):
shutil.rmtree(all_path('JPEGImages'))
shutil.os.mkdir(all_path('Annotations'))
shutil.os.makedirs(all_path('ImageSets/Main'))
shutil.os.mkdir(all_path('JPEGImages'))
def excute_datasets(idx, datatype):
f = open(all_path('ImageSets/Main/' + datatype + '.txt'), 'a'