Tensorflow下使用SSD训练自己的数据集
1、数据集格式转换。
① 将自己的数据集做成VOC2007格式,直接将VOC2007文件夹粘贴到SSD-Tensorflow-master目录下。
② 修改datasets文件夹中pascalvoc_common.py文件中的训练类。
#原始的
# VOC_LABELS = {
# 'none': (0, 'Background'),
# 'aeroplane': (1, 'Vehicle'),
# 'bicycle': (2, 'Vehicle'),
# 'bird': (3, 'Animal'),
# 'boat': (4, 'Vehicle'),
# 'bottle': (5, 'Indoor'),
# 'bus': (6, 'Vehicle'),
# 'car': (7, 'Vehicle'),
# 'cat': (8, 'Animal'),
# 'chair': (9, 'Indoor'),
# 'cow': (10, 'Animal'),
# 'diningtable': (11, 'Indoor'),
# 'dog': (12, 'Animal'),
# 'horse': (13, 'Animal'),
# 'motorbike': (14, 'Vehicle'),
# 'person': (15, 'Person'),
# 'pottedplant': (16, 'Indoor'),
# 'sheep': (17, 'Animal'),
# 'sofa': (18, 'Indoor'),
# 'train': (19, 'Vehicle'),
# 'tvmonitor': (20, 'Indoor'),
# }
#修改后的
VOC_LABELS = {
'none': (0, 'Background'),
'gun': (1, 'gun'),
'knife': (2, 'knife'),
}
③ 修改datasets文件夹中的pascalvoc_to_tfrecords.py文件。
修改文件的83行读取方式为’rb‘,如果你的文件不是.jpg格式,也可以修改图片的类型。
# Read the image file.
filename = directory + DIRECTORY_IMAGES + name + '.jpg'
image_data = tf.gfile.FastGFile(filename, 'rb').read()
修改文件的67行,设置将几张图片转为一个tfrecords。
# TFRecords convertion parameters.
RANDOM_SEED = 4242
SAMPLES_PER_FILES = 1 # 一张图片转为一个tfrecords
④ 在SSD-Tensorflow-master目录下创建tfrecords_文件夹,做