Ejemplo n.º 1
0
 def test_calc_center_dist(self):
     pred = Prediction(13.88, 0, 10, 0.58)
     lbl = Label(0, 0, 10)
     pred.matched_label = lbl
     self.assertEquals(pred.center_dist, None)
     pred.calc_center_dist()
     self.assertEquals(pred.center_dist, 13.88)
Ejemplo n.º 2
0
def parse_preds(preds_path, labels):
    """
    Returns a list of Prediction objects parsed from a given txt file, and matched with a corresponding label.
    :param preds_path: The path to the txt file that contains predictions in the (x, y, r) format.
    The predictions are line separated and the coordinates are space separated.
    :param labels: A list of labels to match with.
    :return: A list of Prediction objects parsed from the given file, each matched with a single Label object from the
    labels list (or with None if not found).
    """
    preds = []
    with open(preds_path, 'r') as pred_f:
        time = float(pred_f.readline())
        for line in pred_f.readlines():
            log = [float(x) for x in line.split()]
            pred = Prediction(int(log[0]), int(log[1]), log[2], log[3])
            pred.match_label(labels)
            preds.append(pred)
    return preds, time
Ejemplo n.º 3
0
def generate_fake_preds(preds_path, labels, persist=False):
    preds = []
    time = np.random.exponential(0.3)
    if persist:
        with open(preds_path, 'a') as file:
            file.write('%g\n' % time)

    for label in labels:
        pred_num_for_label = np.random.choice(NUM_PREDS_LIST,
                                              p=NUM_PREDS_PROBS)
        for i in range(pred_num_for_label):
            x, y, r, sc = _generate_fake_pred(label)
            if persist:
                with open(preds_path, 'a') as pred_f:
                    pred_f.write(('%g ' * 4 + '\n') % (x, y, r, sc))
            pred = Prediction(x, y, r, sc)
            pred.match_label(labels)
            preds.append(pred)
    return preds, time
Ejemplo n.º 4
0
 def test_calc_rect_iou(self):
     pred = Prediction(0, 0, 10, 0.58)
     lbl = Label(0, 5, 10)
     iou = pred.calc_rect_iou(lbl)
     self.assertAlmostEqual(iou, 0.6, 1)
Ejemplo n.º 5
0
 def test_calc_circle_iou_zero_both_radius(self):
     pred = Prediction(0, 0, 0, 0.58)
     lbl = Label(0, 0, 0)
     iou = pred.calc_circle_iou(lbl)
     self.assertAlmostEqual(iou, 1)
Ejemplo n.º 6
0
 def test_calc_circle_iou_fully_intersecting(self):
     pred = Prediction(0, 0, 10, 0.58)
     lbl = Label(0, 0, 10)
     iou = pred.calc_circle_iou(lbl)
     self.assertAlmostEqual(iou, 1)
Ejemplo n.º 7
0
 def test_calc_circle_iou_one_inside_other_not_centered_2(self):
     pred = Prediction(0, 0.1, 20, 0.58)
     lbl = Label(0, 0, 5)
     iou = pred.calc_circle_iou(lbl)
     self.assertAlmostEqual(iou, 0.0625)
Ejemplo n.º 8
0
 def test_calc_circle_iou_one_inside_other(self):
     pred = Prediction(0, 0, 10, 0.58)
     lbl = Label(0, 0, 20)
     iou = pred.calc_circle_iou(lbl)
     self.assertAlmostEqual(iou, 0.25)
Ejemplo n.º 9
0
 def test_calc_circle_iou_not_even_close(self):
     pred = Prediction(50, 0, 10, 0.58)
     lbl = Label(0, 0, 10)
     iou = pred.calc_circle_iou(lbl)
     self.assertAlmostEqual(iou, 0)