Esempio n. 1
0
def test_random_resize_with_bbox_op_bad_c():
    """
    Tests RandomResizeWithBBox Op with invalid bounding boxes, expected to catch multiple errors
    """
    logger.info("test_random_resize_with_bbox_op_bad_c")
    test_op = c_vision.RandomResizeWithBBox((400, 300))

    data_voc2 = ds.VOCDataset(DATA_DIR,
                              task="Detection",
                              mode="train",
                              decode=True,
                              shuffle=False)
    check_bad_bbox(data_voc2, test_op, InvalidBBoxType.WidthOverflow,
                   "bounding boxes is out of bounds of the image")
    data_voc2 = ds.VOCDataset(DATA_DIR,
                              task="Detection",
                              mode="train",
                              decode=True,
                              shuffle=False)
    check_bad_bbox(data_voc2, test_op, InvalidBBoxType.HeightOverflow,
                   "bounding boxes is out of bounds of the image")
    data_voc2 = ds.VOCDataset(DATA_DIR,
                              task="Detection",
                              mode="train",
                              decode=True,
                              shuffle=False)
    check_bad_bbox(data_voc2, test_op, InvalidBBoxType.NegativeXY, "min_x")
    data_voc2 = ds.VOCDataset(DATA_DIR,
                              task="Detection",
                              mode="train",
                              decode=True,
                              shuffle=False)
    check_bad_bbox(data_voc2, test_op, InvalidBBoxType.WrongShape,
                   "4 features")
Esempio n. 2
0
def test_random_resize_with_bbox_op_edge_c(plot_vis=False):
    """
    Prints images and bboxes side by side with and without RandomresizeWithBBox Op applied,
    applied on dynamically generated edge case, expected to pass. edge case is when bounding
    box has dimensions as the image itself.
    """
    logger.info("test_random_resize_with_bbox_op_edge_c")
    dataVoc1 = ds.VOCDataset(DATA_DIR,
                             task="Detection",
                             mode="train",
                             decode=True,
                             shuffle=False)

    dataVoc2 = ds.VOCDataset(DATA_DIR,
                             task="Detection",
                             mode="train",
                             decode=True,
                             shuffle=False)

    test_op = c_vision.RandomResizeWithBBox(500)

    dataVoc1 = dataVoc1.map(input_columns=["annotation"],
                            output_columns=["annotation"],
                            operations=fix_annotate)
    dataVoc2 = dataVoc2.map(input_columns=["annotation"],
                            output_columns=["annotation"],
                            operations=fix_annotate)

    # maps to convert data into valid edge case data
    dataVoc1 = dataVoc1.map(
        input_columns=["image", "annotation"],
        output_columns=["image", "annotation"],
        columns_order=["image", "annotation"],
        operations=[
            lambda img, bboxes:
            (img, np.array([[0, 0, img.shape[1], img.shape[0]]]).astype(bboxes.
                                                                        dtype))
        ])

    dataVoc2 = dataVoc2.map(
        input_columns=["image", "annotation"],
        output_columns=["image", "annotation"],
        columns_order=["image", "annotation"],
        operations=[
            lambda img, bboxes:
            (img, np.array([[0, 0, img.shape[1], img.shape[0]]]).astype(
                bboxes.dtype)), test_op
        ])

    unaugSamp, augSamp = [], []

    for unAug, Aug in zip(dataVoc1.create_dict_iterator(),
                          dataVoc2.create_dict_iterator()):
        unaugSamp.append(unAug)
        augSamp.append(Aug)

    if plot_vis:
        visualize_with_bounding_boxes(unaugSamp, augSamp)
Esempio n. 3
0
def test_random_resize_with_bbox_op_invalid_c():
    """
    Test RandomResizeWithBBox Op on invalid constructor parameters, expected to raise ValueError
    """
    logger.info("test_random_resize_with_bbox_op_invalid_c")

    try:
        # zero value for resize
        c_vision.RandomResizeWithBBox(0)

    except ValueError as err:
        logger.info("Got an exception in DE: {}".format(str(err)))
        assert "Input is not within the required interval of (1 to 16777216)." in str(
            err)

    try:
        # one of the size values is zero
        c_vision.RandomResizeWithBBox((0, 100))

    except ValueError as err:
        logger.info("Got an exception in DE: {}".format(str(err)))
        assert "Input size at dim 0 is not within the required interval of (1 to 2147483647)." in str(
            err)

    try:
        # negative value for resize
        c_vision.RandomResizeWithBBox(-10)

    except ValueError as err:
        logger.info("Got an exception in DE: {}".format(str(err)))
        assert "Input is not within the required interval of (1 to 16777216)." in str(
            err)

    try:
        # invalid input shape
        c_vision.RandomResizeWithBBox((100, 100, 100))

    except TypeError as err:
        logger.info("Got an exception in DE: {}".format(str(err)))
        assert "Size should be" in str(err)
Esempio n. 4
0
def test_random_resize_with_bbox_op_rand_c(plot_vis=False):
    """
    Prints images and bboxes side by side with and without RandomResizeWithBBox Op applied,
    tests with MD5 check, expected to pass
    """
    logger.info("test_random_resize_with_bbox_rand_c")
    original_seed = config_get_set_seed(1)
    original_num_parallel_workers = config_get_set_num_parallel_workers(1)

    # Load dataset
    dataVoc1 = ds.VOCDataset(DATA_DIR,
                             task="Detection",
                             mode="train",
                             decode=True,
                             shuffle=False)

    dataVoc2 = ds.VOCDataset(DATA_DIR,
                             task="Detection",
                             mode="train",
                             decode=True,
                             shuffle=False)

    test_op = c_vision.RandomResizeWithBBox(200)

    dataVoc1 = dataVoc1.map(input_columns=["annotation"],
                            output_columns=["annotation"],
                            operations=fix_annotate)
    dataVoc2 = dataVoc2.map(input_columns=["annotation"],
                            output_columns=["annotation"],
                            operations=fix_annotate)
    # map to apply ops
    dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"],
                            output_columns=["image", "annotation"],
                            columns_order=["image", "annotation"],
                            operations=[test_op])

    filename = "random_resize_with_bbox_op_01_c_result.npz"
    save_and_check_md5(dataVoc2, filename, generate_golden=GENERATE_GOLDEN)

    unaugSamp, augSamp = [], []

    for unAug, Aug in zip(dataVoc1.create_dict_iterator(),
                          dataVoc2.create_dict_iterator()):
        unaugSamp.append(unAug)
        augSamp.append(Aug)

    if plot_vis:
        visualize_with_bounding_boxes(unaugSamp, augSamp)

    # Restore config setting
    ds.config.set_seed(original_seed)
    ds.config.set_num_parallel_workers(original_num_parallel_workers)