【问题标题】:Creating a JSON with FDDB fold txt files使用 FDDB 折叠 txt 文件创建 JSON
【发布时间】:2023-03-23 05:15:02
【问题描述】:

TL;DR 即使我使用了 while 循环,该函数也没有从所有行返回值

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

我写了下面的代码,提取数据的方式可以返回center_x或angle等具体参数

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() 也只会返回一行

最终,我想将数据集转换为字典到 JSON。

更多信息:我知道有许多关于 FDDB 评估的问题和教程。但是,我不打算根据注释评估我的算法。我打算使用这些注释作为ground truth来训练Mask RCNN。

【问题讨论】:

    标签: python json dictionary dataset txt


    【解决方案1】:

    我不是一次提取所有 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  
    

    【讨论】:

      猜你喜欢
      • 2020-06-27
      • 1970-01-01
      • 2016-01-06
      • 2021-11-22
      • 2013-03-23
      • 1970-01-01
      • 2019-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多