def test_dataset_by_frame_ids():
    frame_ids = set([
        724, 1532, 5037, 5992, 6040, 6723, 7088, 7386, 7977, 8762, 9769, 9891
    ])
    if platform.system() == "Linux":
        datalake_path = r"/data1/workspaces/aiftimie/tms/tms_data"
    else:
        datalake_path = r"D:\tms_data"
    download_data_if_not_exists(datalake_path)
    coco_dset = get_dataset(datalake_path)

    g_tdp_fdp_1: Iterable[Tuple[FrameDatapoint, TargetDatapoint]]
    g_tdp_fdp_2: Iterable[Tuple[FrameDatapoint, TargetDatapoint]]
    g_tdp_fdp_1, g_tdp_fdp_2 = tee(
        gen_cocoitem2datapoints(coco_dset, frame_ids))
    g_tdp = gen_cocoitem2targetdp(g_tdp_fdp_1)
    g_fdp_1, g_fdp_2, g_fdp_3 = tee(gen_cocoitem2framedp(g_tdp_fdp_2), 3)

    model = create_model_efficient(
        model_creation_func=partial(create_model, max_operating_res=800))
    g_pred = compute(g_fdp_1,
                     model,
                     batch_size=5,
                     filter_classes=model_class_names)
    for fdp_pred, fdp_gt in zip(plot_detections(g_fdp_2, g_pred),
                                plot_targets(g_fdp_3, g_tdp)):
        cv2.imshow("image_pred", fdp_pred.image)
        cv2.imshow("image_gt", fdp_gt.image)
        cv2.waitKey(0)
Пример #2
0
def html_imgs_generator(video_path, csv_path):
    pred_gen_from_df = pandas_to_pred_iter(pd.read_csv(csv_path))
    filtered_pred = filter_pred_detections(pred_gen_from_df)
    filtered_dataframe = pred_iter_to_pandas(filtered_pred)

    important_frames, important_df = get_important_frames(filtered_dataframe)
    image_gen = framedatapoint_generator_by_frame_ids2(video_path, important_frames)

    pred_from_important = pandas_to_pred_iter(important_df)

    for fdp in plot_detections(image_gen, pred_from_important):
        yield image2htmlstr(fdp.image)
def test_filter_predictions_generator():
    show_video = False
    csv_file_path = osp.join(osp.dirname(__file__), 'data', 'cut.csv')
    pred_gen_from_df = pandas_to_pred_iter(pd.read_csv(csv_file_path))
    filtered_pred = filter_pred_detections(pred_gen_from_df)
    # filtered_dataframe = TruckDetector.pred_iter_to_pandas(filtered_pred)

    video_file = osp.join(osp.dirname(__file__), '..', 'service', 'data',
                          'cut.mkv')
    image_gen = framedatapoint_generator(video_file, skip=0)
    if show_video:
        for fdp in plot_detections(image_gen, filtered_pred):
            cv2.imshow("image", fdp.image)
            cv2.waitKey(0)
Пример #4
0
def test_auu_data():
    auu_data_root = r'D:\tms_data\aau-rainsnow\Hjorringvej\Hjorringvej-2'
    video_files = [
        osp.join(r, f) for (r, _, fs) in os.walk(auu_data_root) for f in fs
        if 'avi' in f or 'mkv' in f
    ]
    model = create_model()

    for video_path in video_files:
        image_gen = framedatapoint_generator(video_path, skip=5)
        image_gen1, image_gen2 = tee(image_gen)

        for idx, fdp in enumerate(
                plot_detections(image_gen1, compute(image_gen2, model))):
            cv2.imshow("image", fdp.image)
            cv2.waitKey(1)
Пример #5
0
def test_truck_detector():
    show_image = False
    test_image_path = osp.join(osp.dirname(__file__), 'data', 'test_image.PNG')
    test_image = cv2.cvtColor(cv2.imread(test_image_path), cv2.COLOR_BGR2RGB)
    model = create_model_efficient()

    input_images = [FrameDatapoint(test_image, 1)]
    predictions = list(compute(input_images, model))
    assert len(predictions) != 0
    assert isinstance(predictions, list)
    assert isinstance(predictions[0], PredictionDatapoint)
    assert isinstance(predictions[0].pred, dict)
    assert 'labels' in predictions[0].pred
    assert 'scores' in predictions[0].pred
    assert 'boxes' in predictions[0].pred
    if show_image:
        cv2.imshow("image",
                   next(plot_detections(input_images, predictions)).image)
        cv2.waitKey(0)
Пример #6
0
def test_TruckDetector_pred_iter_to_pandas():
    auu_data_root = r'D:\aau-rainsnow\Hjorringvej\Hjorringvej-2'
    video_file = [
        osp.join(r, f) for (r, _, fs) in os.walk(auu_data_root) for f in fs
        if 'avi' in f or 'mkv' in f
    ][0]
    #file 'Hjorringvej\\Hjorringvej-2\\cam1.mkv' has 6000 frames
    model = create_model(max_operating_res=320)
    image_gen = framedatapoint_generator(video_file, skip=6000 // 30)
    image_gen1, image_gen2 = tee(image_gen)

    pred_gen = compute(image_gen1, model)

    df = pred_iter_to_pandas(pred_gen)

    pred_gen_from_df = pandas_to_pred_iter(df)

    for idx, fdp in enumerate(plot_detections(image_gen2, pred_gen_from_df)):
        cv2.imshow("image", fdp.image)
        cv2.waitKey(1)
        if idx == 5: break
Пример #7
0
def compare_multiple_dataframes(video_path, destination, *dataframes):
    """
    Given a set of dataframes this function will look at the union of the dataframes. The resulted frames will be the
    union of the dataframes where there is a prediction or there is a reason (motionmap) for the presence of a frame.
    In other words, rows that have at least one column not Null.

    In this way you can see frames where one detector managed to detect something when the other didn't.

    The dataframes do not need to have the same number of rows in order to be compared. The presence of the 'img_id'
    column is sufficient.

    Args:
        video_path: video file from which the dataframes resulted
        destination: path to a destination .mp4 or .avi file that will contain the plotting of the dataframes
        dataframes: positional arguments with dataframes

    Result:
        None
    """
    common_frames = get_common_frames(dataframes)
    dataframes = normalize_dataframes(dataframes, common_frames)
    g = framedatapoint_generator_by_frame_ids2(video_path, common_frames)
    fdpgs = tee(g, len(dataframes))

    gdfs = [pandas_to_pred_iter(df) for df in dataframes]
    plots = [plot_detections(fdpg, gdf) for fdpg, gdf in zip(fdpgs, gdfs)]
    pairsg = zip(*plots)

    fdp_list = next(pairsg)
    assert all(fdp.frame_id == fdp_list[0].frame_id for fdp in fdp_list)

    images = [fdp.image for fdp in fdp_list]
    frame = np.concatenate((*images, ), axis=1)
    with create_avi(destination, frame) as append_fn:
        for fdp_list in pairsg:
            assert all(fdp.frame_id == fdp_list[0].frame_id
                       for fdp in fdp_list)
            images = [fdp.image for fdp in fdp_list]
            frame = np.concatenate((*images, ), axis=1)
            append_fn(frame)