创建一个 JSON with FDDB fold txt 文件
Creating a JSON with FDDB fold txt files
TL;DR 即使我使用了 while 循环,该函数也不会 returning 所有行的值
FDDB fold txt 文件的数据格式如下。首先是图片文件路径,然后下一行是面的个数,后面几行是每个面椭圆的参数。
2002/08/11/big/img_591
1
123.583300 85.549500 1.265839 269.693400 161.781200 1
2002/08/26/big/img_265
3
67.363819 44.511485 -1.476417 105.249970 87.209036 1
41.936870 27.064477 1.471906 184.070915 129.345601 1
70.993052 43.355200 1.370217 340.894300 117.498951 1
2002/07/19/big/img_423
1
87.080955 59.379319 1.550861 255.383099 133.767857 1
2002/08/24/big/img_490
1
54.692105 35.056825 -1.384924 145.665694 78.101005 1
我写了下面的代码来提取数据,我可以return特定的参数,比如center_x或角度
def fddb_dataset(annotations):
for d in os.listdir(annotations):
if fnmatch(d, 'FDDB-fold-*-ellipseList.txt'):
with open(os.path.join(annotations, d), 'rt') as f:
lines = [line.rstrip('\n') for line in f]
lineId = 0
while lineId < len(lines):
# Image
imgPath = lines[lineId]
lineId += 1
# Faces
numFaces = int(lines[lineId])
lineId += 1
for i in range(numFaces):
params = [float(v) for v in lines[lineId].split()]
lineId += 1
rad_x, rad_y, angle, center_x, center_y, detection_score = params
return imgPath, rad_x, rad_y, angle, center_x, center_y, detection_score
问题是,即使我尝试使用 .append()
,这也只是 return 一行最终,我想将数据集转换为字典 JSON。
更多信息:我知道有很多关于 FDDB 评估的问题和教程。但是,我不打算根据注释评估我的算法。我打算使用这些注释作为 ground truth 来训练 Mask RCNN。
我一次从一个 txt 文件中提取数据,而不是一次提取所有 txt 文件
def fddb_dataset(annotations):
with open(annotations) as f:
imgPath = []
rad_x = []
rad_y = []
angle = []
center_x = []
center_y = []
detection_score = []
lineId = 0
lines = f.readlines()
while lineId < len(lines):
Path = lines[lineId]
lineId += 1
# Faces
numFaces = int(lines[lineId])
for i in range(numFaces):
lineId += 1
params = [float(v) for v in lines[lineId].split()]
radx, rady, ang, centerx, centery, score = params
imgPath.append(Path)
rad_x.append(radx)
rad_y.append(rady)
angle.append(ang)
center_x.append(centerx)
center_y.append(centery)
detection_score.append(score)
lineId += 1
data = pd.DataFrame(
{'imgPath': imgPath,
'rad_x': rad_x,
'rad_y': rad_y,
'angle': angle,
'center_x': center_x,
'center_y': center_y,
'detection_score': detection_score
})
return data