1

TL;DR The function is not returning values from all the lines even though I used a while loop

The FDDB fold txt files have data formatted as below. First there is the image file path, then the next line has the number of faces, and the following lines are the parameters of the ellipse for each face.

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

I wrote the following code to extract the data in a way that I can return the specific parameters such as center_x or 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

The problem is that this is only returning one single row even if I try using .append()

Ultimately, I want to convert the dataset to a dictionary to a JSON.

More info: I am aware there are a number of questions and tutorials for FDDB evaluation. However, I am not looking to evaluate my algorithm against the annotations. I am planning to use these annotations as ground truth to train Mask RCNN.

1 Answers1

0

Instead of all the txt files at once, I extracted the data from one txt file at a time

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