Esempio n. 1
0
def task1(gt_file):
    gt = read_xml_gt(gt_file)
    classes_to_keep = ['car']
    gt = filter_gt(gt, classes_to_keep)

    det_bb = generate_noisy_annotations(gt)

    lst_gt = [item[0] for item in gt]
    last_frame = np.max(lst_gt)

    miou = 0
    for f_val in range(0, last_frame):
        frame_gt_bb = [gt[i] for i, num in enumerate(gt) if num[0] == f_val]

        frame_det_bb = [det_bb[i] for i, num in enumerate(det_bb) if num[0] == f_val]
        miou += frame_miou(frame_det_bb, frame_gt_bb, confidence=False)

    miou = miou/last_frame
    print("Noisy GT (Sorted Random): ", calculate_ap(det_bb, gt, 'random'))
    print("Noisy GT (Sorted by Area): ", calculate_ap(det_bb, gt, 'area'))


    preds_mask = read_detections_file("datasets/AICity_data/train/S03/c010/det/det_mask_rcnn.txt")
    print("maskrcnn ap: {}".format(calculate_ap(preds_mask, gt, 'sort')))

    preds_ssd = read_detections_file("datasets/AICity_data/train/S03/c010/det/det_ssd512.txt")
    print("ssd ap: {}".format(calculate_ap(preds_ssd, gt, 'sort')))

    preds_yolo = read_detections_file("datasets/AICity_data/train/S03/c010/det/det_yolo3.txt")
    print("yolo ap: {}".format(calculate_ap(preds_yolo, gt, 'sort')))
Esempio n. 2
0
def task_31():
    gt_annot_file = 'datasets/ai_challenge_s03_c010-full_annotation.xml'
    frames_path = 'datasets/AICity_data/train/S03/c010/data'


    det_bb = read_detections_file("datasets/AICity_data/train/S03/c010/det/our_results_finetune_faster.txt")
    gt_bb = read_xml_gt_options(gt_annot_file, False, False)
    gt_bb = filter_gt(gt_bb, ["car"])

    video_n_frames = number_of_images_jpg(frames_path)
    det_bb_max_iou, idd = tracking_iou(frames_path, copy.deepcopy(det_bb), video_n_frames, mode='of')
    ap_max_iou = calculate_ap(det_bb_max_iou, gt_bb, 0, video_n_frames, mode='sort')

    print("Ap after tracking with maximum IoU: {}".format(ap_max_iou))

    det_bb_max_iou, idd = tracking_iou(frames_path, copy.deepcopy(det_bb), video_n_frames, mode='other')
    ap_max_iou = calculate_ap(det_bb_max_iou, copy.deepcopy(gt_bb), 0, video_n_frames, mode='sort')
    print("Ap after tracking with maximum IoU: {}".format(ap_max_iou))


    new_tracks = restore_tracks(frames_path, det_bb_max_iou)
    ap_max_iou = calculate_ap(new_tracks, copy.deepcopy(gt_bb), 0, video_n_frames, mode='sort')
    print("Ap after tracking with maximum IoU and of: {}".format(ap_max_iou))



    ini_frame = 700
    end_frame = 900
    animation_tracks(new_tracks, idd, ini_frame, end_frame, frames_path)
Esempio n. 3
0
def task22(gt_annot_file, detections_file, frames_path):
    ap_mode = 'area'
    #Read and filter detections
    det_bb = read_detections_file(detections_file)
    det_bb = filter_det_confidence(det_bb, threshold=0.5)
    #Read and filter gt
    gt_bb = read_xml_gt_options(gt_annot_file, False, False)
    gt_bb = filter_gt(gt_bb, ["car"])
    #Calculate original ap
    video_n_frames = number_of_images_jpg(frames_path)
    # Constant velocity
    det_bb_vel = kalman_filter_tracking(det_bb, video_n_frames, 0)
    # Constant acceleration
    det_bb_acc = kalman_filter_tracking(det_bb, video_n_frames, 1)
    #Print ap results
    print("Original ap: {}".format(
        calculate_ap(det_bb, gt_bb, 0, video_n_frames, mode=ap_mode)))
    print("Ap after tracking with constant velocity: {}".format(
        calculate_ap(det_bb_vel, gt_bb, 0, video_n_frames, mode=ap_mode)))
    print("Ap after tracking with constant acceleration: {}".format(
        calculate_ap(det_bb_acc, gt_bb, 0, video_n_frames, mode=ap_mode)))
    #Obtain animation
    max_id_vel = max(det_bb_vel, key=lambda x: x[2])[2]
    max_id_acc = max(det_bb_acc, key=lambda x: x[2])[2]
    ini_frame = 550
    end_frame = 650
Esempio n. 4
0
def task21(gt_annot_file, detections_file, frames_path):
    ap_mode = 'area'
    # Read and filter detections
    #    det_bb = read_detections_file(detections_file)

    #    det_bb = read_detections_file("datasets/AICity_data/train/S03/c010/det/det_mask_rcnn.txt")
    #    det_bb = read_detections_file("datasets/AICity_data/train/S03/c010/det/det_ssd512.txt")
    #    det_bb = read_detections_file("datasets/AICity_data/train/S03/c010/det/det_yolo3.txt")
    #    det_bb = read_detections_file("datasets/AICity_data/train/S03/c010/det/our_results_coco_faster.txt")

    det_bb = read_detections_file(
        "datasets/AICity_data/train/S03/c010/det/our_results_finetune_faster.txt"
    )
    det_bb = filter_det_confidence(det_bb, threshold=0.5)
    #Read and filter gt
    gt_bb = read_xml_gt_options(gt_annot_file, False, False)
    gt_bb = filter_gt(gt_bb, ["car"])

    video_n_frames = number_of_images_jpg(frames_path)

    original_ap = calculate_ap(det_bb, gt_bb, 0, video_n_frames, mode=ap_mode)

    det_bb_max_iou, idd = tracking_iou(copy.deepcopy(det_bb), video_n_frames)

    ap_max_iou = calculate_ap(det_bb_max_iou,
                              gt_bb,
                              0,
                              video_n_frames,
                              mode=ap_mode)

    print("Original ap: {}".format(original_ap))
    print("Ap after tracking with maximum IoU: {}".format(ap_max_iou))
    ini_frame = 550
    end_frame = 650
    animation_tracks(det_bb_max_iou, idd, ini_frame, end_frame, frames_path)
Esempio n. 5
0
def task1(frames_path,
          detections_file,
          gt_file,
          tracking_method,
          postprocessing=True,
          visualization=False):
    print("Start loading data")
    # Read gt
    gt_bb = read_gt_txt(gt_file)

    # Read and filter detections
    det_bb = read_detections_file(detections_file)
    det_bb = filter_det_confidence(det_bb, threshold=0.5)

    # Tracking
    print("Start tracking")
    video_n_frames = number_of_images_jpg(frames_path)
    if tracking_method == "MaxOverlap":
        det_bb_tracking, id_max = tracking_iou(frames_path,
                                               copy.deepcopy(det_bb),
                                               video_n_frames,
                                               mode='other')
    elif tracking_method == "Kalman":
        det_bb_tracking = kalman_filter_tracking(copy.deepcopy(det_bb),
                                                 video_n_frames, 0)
        id_max = max([v[2] for v in det_bb_tracking])
    else:
        raise NotImplemented

    # Postprocessing
    if postprocessing:
        print("Starting postprocessing tracking")
        det_bb_tracking = clean_tracks(copy.deepcopy(det_bb_tracking), id_max)
        det_bb_tracking = remove_parked(copy.deepcopy(det_bb_tracking),
                                        id_max,
                                        threshold=10.0)

    # Results
    print("Start obtaining metrics")
    ap = calculate_ap(det_bb_tracking,
                      copy.deepcopy(gt_bb),
                      0,
                      video_n_frames,
                      mode='sort')
    print("Average precision: {}".format(ap))

    # Create animation if required
    if visualization:
        print("Start storing animation")
        ini_frame = 700
        end_frame = 800
        frames_path = 'datasets/AICity_data/train/S03/c010/data'
        animation_tracks(det_bb_tracking, id_max, ini_frame, end_frame,
                         frames_path)

    return det_bb_tracking
Esempio n. 6
0
def task2(gt_file, ini_frame):
    gt_bb = read_xml_gt(gt_file)
    classes_to_keep = ['car']
    gt_bb = filter_gt(gt_bb, classes_to_keep)

#    det_bb = generate_noisy_annotations(gt_bb)
#    det_bb = read_detections_file("datasets/AICity_data/train/S03/c010/det/det_mask_rcnn.txt")
#    det_bb = read_detections_file("datasets/AICity_data/train/S03/c010/det/det_ssd512.txt")
#    det_bb = read_detections_file("datasets/AICity_data/train/S03/c010/det/det_yolo3.txt")
    det_bb = read_detections_file("datasets/AICity_data/train/S03/c010/det/our_results_finetune_faster.txt")
    fps = 10
    seconds = 30
    animation_2bb("bb_frames_our_faster", ".gif", gt_bb, det_bb, "datasets/AICity_data/train/S03/c010/data/", fps, seconds,
              ini_frame, int(1920 / 4), int(1080 / 4))

    mious = []
    for f_val in range(ini_frame, ini_frame+int(seconds*fps)):
        frame_gt_bb = [gt_bb[i] for i, num in enumerate(gt_bb) if num[0] == f_val]

        frame_det_bb = [det_bb[i] for i, num in enumerate(det_bb) if num[0] == f_val]
        mious.append(frame_miou(frame_det_bb, frame_gt_bb, confidence=False))

    xx = np.arange(ini_frame, ini_frame+int(seconds*fps))
    plt.figure()
    plt.ylim((0,1))
    plt.xlabel('Frame')
    plt.ylabel('mIoU')
##    plt.plot(xx, yolo, label = 'YOLOv3')
##    plt.plot(xx, mask, label = 'Mask R-CNN')
##    plt.plot(xx, ssd, label = 'SSD')
    plt.plot(xx, retina, label = 'RetinaNet')      
    plt.plot(xx, faster, label = 'Faster R-CNN')    
    plt.plot(xx, our_faster, label = 'Faster R-CNN (Fine tuned)')
    plt.legend()
        
    frames = list(range(0, len(mious)))
    ani = plot_animation(frames, mious, 'Frame', 'IoU', [0,1], fps)
    ani.save('iou_our_faster.gif')