Beispiel #1
0
def test_random_crop_with_bbox_op_bad_padding():
    """
    Test RandomCropWithBBox Op on invalid constructor parameters, expected to raise ValueError
    """
    logger.info("test_random_crop_with_bbox_op_invalid_c")

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

    try:
        test_op = c_vision.RandomCropWithBBox([512, 512], padding=-1)

        dataVoc2 = dataVoc2.map(operations=[test_op], input_columns=["image", "bbox"],
                                output_columns=["image", "bbox"],
                                column_order=["image", "bbox"])

        for _ in dataVoc2.create_dict_iterator(num_epochs=1):
            break
    except ValueError as err:
        logger.info("Got an exception in DE: {}".format(str(err)))
        assert "Input padding is not within the required interval of (0 to 2147483647)." in str(err)

    try:
        test_op = c_vision.RandomCropWithBBox([512, 512], padding=[16777216, 16777216, 16777216, 16777216])

        dataVoc2 = dataVoc2.map(operations=[test_op], input_columns=["image", "bbox"],
                                output_columns=["image", "bbox"],
                                column_order=["image", "bbox"])

        for _ in dataVoc2.create_dict_iterator(num_epochs=1):
            break
    except RuntimeError as err:
        logger.info("Got an exception in DE: {}".format(str(err)))
        assert "RandomCropBBoxOp padding size is too big, it\'s more than 3 times the original size." in str(err)
Beispiel #2
0
def test_random_crop_with_bbox_op_coco_c(plot_vis=False):
    """
    Prints images and bboxes side by side with and without RandomCropWithBBox Op applied,
    Testing with Coco dataset
    """
    logger.info("test_random_crop_with_bbox_op_coco_c")
    # load dataset
    dataCoco1 = ds.CocoDataset(DATA_DIR_COCO[0], annotation_file=DATA_DIR_COCO[1], task="Detection",
                               decode=True, shuffle=False)

    dataCoco2 = ds.CocoDataset(DATA_DIR_COCO[0], annotation_file=DATA_DIR_COCO[1], task="Detection",
                               decode=True, shuffle=False)

    test_op = c_vision.RandomCropWithBBox([512, 512], [200, 200, 200, 200])

    dataCoco2 = dataCoco2.map(operations=[test_op], input_columns=["image", "bbox"],
                              output_columns=["image", "bbox"],
                              column_order=["image", "bbox"])

    unaugSamp, augSamp = [], []

    for unAug, Aug in zip(dataCoco1.create_dict_iterator(num_epochs=1, output_numpy=True),
                          dataCoco2.create_dict_iterator(num_epochs=1, output_numpy=True)):
        unaugSamp.append(unAug)
        augSamp.append(Aug)

    if plot_vis:
        visualize_with_bounding_boxes(unaugSamp, augSamp, "bbox")
Beispiel #3
0
def test_random_crop_with_bbox_op_c(plot_vis=False):
    """
    Prints images and bboxes side by side with and without RandomCropWithBBox Op applied
    """
    logger.info("test_random_crop_with_bbox_op_c")

    # Load dataset
    dataVoc1 = ds.VOCDataset(DATA_DIR_VOC, task="Detection", usage="train", shuffle=False, decode=True)
    dataVoc2 = ds.VOCDataset(DATA_DIR_VOC, task="Detection", usage="train", shuffle=False, decode=True)

    # define test OP with values to match existing Op UT
    test_op = c_vision.RandomCropWithBBox([512, 512], [200, 200, 200, 200])

    # map to apply ops
    dataVoc2 = dataVoc2.map(operations=[test_op], input_columns=["image", "bbox"],
                            output_columns=["image", "bbox"],
                            column_order=["image", "bbox"])  # Add column for "bbox"

    unaugSamp, augSamp = [], []

    for unAug, Aug in zip(dataVoc1.create_dict_iterator(num_epochs=1, output_numpy=True),
                          dataVoc2.create_dict_iterator(num_epochs=1, output_numpy=True)):
        unaugSamp.append(unAug)
        augSamp.append(Aug)

    if plot_vis:
        visualize_with_bounding_boxes(unaugSamp, augSamp)
Beispiel #4
0
def test_random_crop_with_bbox_op_bad_c():
    """
    Tests RandomCropWithBBox Op with invalid bounding boxes, expected to catch multiple errors.
    """
    logger.info("test_random_crop_with_bbox_op_bad_c")
    test_op = c_vision.RandomCropWithBBox([512, 512], [200, 200, 200, 200])

    data_voc2 = ds.VOCDataset(DATA_DIR_VOC,
                              task="Detection",
                              usage="train",
                              shuffle=False,
                              decode=True)
    check_bad_bbox(data_voc2, test_op, InvalidBBoxType.WidthOverflow,
                   "bounding boxes is out of bounds of the image")
    data_voc2 = ds.VOCDataset(DATA_DIR_VOC,
                              task="Detection",
                              usage="train",
                              shuffle=False,
                              decode=True)
    check_bad_bbox(data_voc2, test_op, InvalidBBoxType.HeightOverflow,
                   "bounding boxes is out of bounds of the image")
    data_voc2 = ds.VOCDataset(DATA_DIR_VOC,
                              task="Detection",
                              usage="train",
                              shuffle=False,
                              decode=True)
    check_bad_bbox(data_voc2, test_op, InvalidBBoxType.NegativeXY,
                   "negative value")
    data_voc2 = ds.VOCDataset(DATA_DIR_VOC,
                              task="Detection",
                              usage="train",
                              shuffle=False,
                              decode=True)
    check_bad_bbox(data_voc2, test_op, InvalidBBoxType.WrongShape,
                   "4 features")
Beispiel #5
0
def test_random_crop_with_bbox_op_invalid_c():
    """
    Test RandomCropWithBBox Op on invalid constructor parameters, expected to raise ValueError
    """
    logger.info("test_random_crop_with_bbox_op_invalid_c")

    # Load dataset
    dataVoc2 = ds.VOCDataset(DATA_DIR_VOC,
                             task="Detection",
                             usage="train",
                             shuffle=False,
                             decode=True)

    try:
        # define test OP with values to match existing Op unit - test
        test_op = c_vision.RandomCropWithBBox([512, 512, 375])

        # map to apply ops
        dataVoc2 = dataVoc2.map(operations=[test_op],
                                input_columns=["image", "bbox"],
                                output_columns=["image", "bbox"],
                                column_order=["image",
                                              "bbox"])  # Add column for "bbox"

        for _ in dataVoc2.create_dict_iterator(num_epochs=1):
            break
    except TypeError as err:
        logger.info("Got an exception in DE: {}".format(str(err)))
        assert "Size should be a single integer" in str(err)
Beispiel #6
0
def test_random_crop_with_bbox_op_edge_c(plot_vis=False):
    """
    Prints images and bboxes side by side with and without RandomCropWithBBox Op applied,
    applied on dynamically generated edge case, expected to pass
    """
    logger.info("test_random_crop_with_bbox_op_edge_c")

    # Load dataset
    dataVoc1 = ds.VOCDataset(DATA_DIR_VOC,
                             task="Detection",
                             usage="train",
                             shuffle=False,
                             decode=True)
    dataVoc2 = ds.VOCDataset(DATA_DIR_VOC,
                             task="Detection",
                             usage="train",
                             shuffle=False,
                             decode=True)

    # define test OP with values to match existing Op unit - test
    test_op = c_vision.RandomCropWithBBox(512, [200, 200, 200, 200],
                                          padding_mode=mode.Border.EDGE)

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

    # Test Op added to list of Operations here
    dataVoc2 = dataVoc2.map(operations=[
        lambda img, bboxes: (img, np.array([[0, 0, img.shape[1], img.shape[0]]]
                                           ).astype(bboxes.dtype)), test_op
    ],
                            input_columns=["image", "bbox"],
                            output_columns=["image", "bbox"],
                            column_order=["image", "bbox"])

    unaugSamp, augSamp = [], []

    for unAug, Aug in zip(
            dataVoc1.create_dict_iterator(num_epochs=1, output_numpy=True),
            dataVoc2.create_dict_iterator(num_epochs=1, output_numpy=True)):
        unaugSamp.append(unAug)
        augSamp.append(Aug)

    if plot_vis:
        visualize_with_bounding_boxes(unaugSamp, augSamp)
Beispiel #7
0
def test_random_crop_with_bbox_op2_c(plot_vis=False):
    """
    Prints images and bboxes side by side with and without RandomCropWithBBox Op applied,
    with md5 check, expected to pass
    """
    logger.info("test_random_crop_with_bbox_op2_c")
    original_seed = config_get_set_seed(593447)
    original_num_parallel_workers = config_get_set_num_parallel_workers(1)

    # Load dataset
    dataVoc1 = ds.VOCDataset(DATA_DIR_VOC,
                             task="Detection",
                             usage="train",
                             shuffle=False,
                             decode=True)
    dataVoc2 = ds.VOCDataset(DATA_DIR_VOC,
                             task="Detection",
                             usage="train",
                             shuffle=False,
                             decode=True)

    # define test OP with values to match existing Op unit - test
    test_op = c_vision.RandomCropWithBBox(512, [200, 200, 200, 200],
                                          fill_value=(255, 255, 255))

    # map to apply ops
    dataVoc2 = dataVoc2.map(operations=[test_op],
                            input_columns=["image", "bbox"],
                            output_columns=["image", "bbox"],
                            column_order=["image", "bbox"])

    filename = "random_crop_with_bbox_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(num_epochs=1, output_numpy=True),
            dataVoc2.create_dict_iterator(num_epochs=1, output_numpy=True)):
        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)