widerface2retina 标签格式转换

在使用WIDER FACE训练retianface人脸检测器的时候,需要将wider face训练集标签转换为retinaface的标签格式,下面给出的是训练集标签转换方式,验证集转换给是类似。

以下代码也可以用于自己标注的数据转换为retinaface训练数据格式。

'''
Function: transfer the wider face train label to retinaface label, it can be used at any data
Method  : transfer in reference to the format of "retinaface_gt_v1.1"
Author  : xiakj
Date    : 2019/9/9
'''

import os
import sys
import numpy as np

def transTrainLabel(input_path, out_path):
    out_fp = open(out_path, "w")
    with open(input_path, "r") as in_fp:
        while True:
            # read file name
            line = in_fp.readline()
            if not line:
                break
            # write file name to out_fp
            out_fp.write("# " + line)
            # read bbox number
            num = int(in_fp.readline())
            if num == 0:
                num = 1
            for i in range(num):
                line = in_fp.readline()
                values = [x for x in line.strip().split()]
                out_fp.write(values[0] + ' ' + values[1] + ' ' + values[2] + ' ' + values[3])
                out_fp.write(' -1.0'*16)
                out_fp.write('\n')
    out_fp.close()

def main():
    train_path = "C:/Users/Administrator/Desktop/wider_face_train_bbx_gt.txt"
    out_path = "C:/Users/Administrator/Desktop/out.txt"
    transTrainLabel(train_path, out_path)

if __name__ == "__main__":
    main()



发布了59 篇原创文章 · 获赞 57 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/xiakejiang/article/details/100664973