def test_random_vertical_flip_with_bbox_op_invalid_c():
    """
     Test RandomVerticalFlipWithBBox Op on invalid constructor parameters, expected to raise ValueError
    """
    logger.info("test_random_vertical_flip_with_bbox_op_invalid_c")
    dataVoc2 = ds.VOCDataset(DATA_DIR,
                             task="Detection",
                             mode="train",
                             decode=True,
                             shuffle=False)

    try:
        test_op = c_vision.RandomVerticalFlipWithBBox(2)
        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])

        for _ in dataVoc2.create_dict_iterator():
            break

    except ValueError as err:
        logger.info("Got an exception in DE: {}".format(str(err)))
        assert "Input is not" in str(err)
Exemplo n.º 2
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",
                             mode="train",
                             decode=True,
                             shuffle=False)

    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(input_columns=["image", "annotation"],
                                output_columns=["image", "annotation"],
                                columns_order=["image", "annotation"],
                                operations=[test_op
                                            ])  # Add column for "annotation"

        for _ in dataVoc2.create_dict_iterator():
            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)
def test_voc_dataset_size():
    dataset = ds.VOCDataset(VOC_DATA_DIR,
                            task="Segmentation",
                            usage="train",
                            shuffle=False,
                            decode=True)
    assert dataset.get_dataset_size() == 10

    dataset_shard_2_0 = ds.VOCDataset(VOC_DATA_DIR,
                                      task="Segmentation",
                                      usage="train",
                                      shuffle=False,
                                      decode=True,
                                      num_shards=2,
                                      shard_id=0)
    assert dataset_shard_2_0.get_dataset_size() == 5
Exemplo n.º 4
0
def test_voc_sampler_chain():
    """
    Test VOC sampler chain
    """
    logger.info("test_voc_sampler_chain")

    sampler = ds.DistributedSampler(num_shards=2, shard_id=0, shuffle=False, num_samples=5)
    child_sampler = ds.SequentialSampler(start_index=0)
    sampler.add_child(child_sampler)
    data1 = ds.VOCDataset(VOC_DATA_DIR, task="Segmentation", sampler=sampler)

    # Verify dataset size
    data1_size = data1.get_dataset_size()
    logger.info("dataset size is: {}".format(data1_size))
    assert data1_size == 5

    # Verify number of rows
    assert sum([1 for _ in data1]) == 5

    # Verify dataset contents
    res = []
    for item in data1.create_tuple_iterator(num_epochs=1, output_numpy=True):
        logger.info("item: {}".format(item))
        res.append(item)
    logger.info("dataset: {}".format(res))
Exemplo n.º 5
0
def test_c_random_resized_crop_with_bbox_op_invalid2():
    """
     Prints images side by side with and without Aug applied + bboxes to compare and test
    """
    # Load dataset # only loading the to AugDataset as test will fail on this
    dataVoc2 = ds.VOCDataset(DATA_DIR,
                             task="Detection",
                             mode="train",
                             decode=True,
                             shuffle=False)

    try:
        # If input range of ratio is not in the order of (min, max), ValueError will be raised.
        test_op = c_vision.RandomResizedCropWithBBox((256, 512), (1, 1),
                                                     (1, 0.5))

        # maps to fix annotations to HQ standard
        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])

        for _ in dataVoc2.create_dict_iterator():
            break

    except ValueError as err:
        logger.info("Got an exception in DE: {}".format(str(err)))
        assert "Input range is not valid" in str(err)
def test_random_resized_crop_with_bbox_op_invalid2_c():
    """
     Tests RandomResizedCropWithBBox Op on invalid constructor parameters, expected to raise ValueError
    """
    logger.info("test_random_resized_crop_with_bbox_op_invalid2_c")
    # Load dataset # only loading the to AugDataset as test will fail on this
    dataVoc2 = ds.VOCDataset(DATA_DIR_VOC,
                             task="Detection",
                             usage="train",
                             shuffle=False,
                             decode=True)

    try:
        # If input range of ratio is not in the order of (min, max), ValueError will be raised.
        test_op = c_vision.RandomResizedCropWithBBox((256, 512), (1, 1),
                                                     (1, 0.5))

        # map to apply ops
        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 is not within the required interval of (0 to 16777216)." in str(
            err)
def test_random_vertical_flip_with_bbox_op_invalid_c():
    """
    Test RandomVerticalFlipWithBBox Op on invalid constructor parameters, expected to raise ValueError
    """
    logger.info("test_random_vertical_flip_with_bbox_op_invalid_c")
    dataVoc2 = ds.VOCDataset(DATA_DIR_VOC,
                             task="Detection",
                             usage="train",
                             shuffle=False,
                             decode=True)

    try:
        test_op = c_vision.RandomVerticalFlipWithBBox(2)

        # map to apply ops
        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 prob is not within the required interval of (0.0 to 1.0)." in str(
            err)
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", mode="train", decode=True, shuffle=False)

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

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

        for _ in dataVoc2.create_dict_iterator():
            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(input_columns=["image", "bbox"],
                                output_columns=["image", "bbox"],
                                columns_order=["image", "bbox"],
                                operations=[test_op])

        for _ in dataVoc2.create_dict_iterator():
            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)
def test_random_horizontal_flip_with_bbox_invalid_prob_c():
    """
    Test RandomHorizontalFlipWithBBox op with invalid input probability
    """
    logger.info("test_random_horizontal_bbox_invalid_prob_c")

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

    try:
        # Note: Valid range of prob should be [0.0, 1.0]
        test_op = c_vision.RandomHorizontalFlipWithBBox(1.5)
        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
                                            ])  # Add column for "annotation"
    except ValueError as error:
        logger.info("Got an exception in DE: {}".format(str(error)))
        assert "Input is not" in str(error)
Exemplo n.º 10
0
def test_bounding_box_augment_invalid_ratio_c():
    """
    Test BoundingBoxAugment op with invalid input ratio
    """
    logger.info("test_bounding_box_augment_invalid_ratio_c")

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

    try:
        # ratio range is from 0 - 1
        test_op = c_vision.BoundingBoxAugment(c_vision.RandomHorizontalFlip(1),
                                              1.5)
        # map to apply ops
        dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"],
                                output_columns=["image", "bbox"],
                                columns_order=["image", "bbox"],
                                operations=[test_op])  # Add column for "bbox"
    except ValueError as error:
        logger.info("Got an exception in DE: {}".format(str(error)))
        assert "Input ratio is not within the required interval of (0.0 to 1.0)." in str(
            error)
Exemplo n.º 11
0
def test_voc_get_class_indexing():
    data1 = ds.VOCDataset(DATA_DIR,
                          task="Detection",
                          mode="train",
                          decode=True)
    class_index1 = data1.get_class_indexing()
    assert (class_index1 == {
        'car': 0,
        'cat': 1,
        'chair': 2,
        'dog': 3,
        'person': 4,
        'train': 5
    })
    data1 = data1.shuffle(4)
    class_index2 = data1.get_class_indexing()
    assert (class_index2 == {
        'car': 0,
        'cat': 1,
        'chair': 2,
        'dog': 3,
        'person': 4,
        'train': 5
    })
    num = 0
    count = [0, 0, 0, 0, 0, 0]
    for item in data1.create_dict_iterator():
        for label in item["label"]:
            count[label[0]] += 1
            assert label[0] in (0, 1, 2, 3, 4, 5)
        num += 1
    assert num == 9
    assert count == [3, 2, 1, 2, 4, 3]
Exemplo n.º 12
0
def test_voc_get_class_indexing():
    data1 = ds.VOCDataset(DATA_DIR,
                          task="Detection",
                          mode="train",
                          decode=True)
    class_index1 = data1.get_class_indexing()
    assert (class_index1 == {
        'car': 0,
        'cat': 1,
        'chair': 2,
        'dog': 3,
        'person': 4,
        'train': 5
    })
    data1 = data1.shuffle(4)
    class_index2 = data1.get_class_indexing()
    assert (class_index2 == {
        'car': 0,
        'cat': 1,
        'chair': 2,
        'dog': 3,
        'person': 4,
        'train': 5
    })
    num = 0
    count = [0, 0, 0, 0, 0, 0]
    for item in data1.create_dict_iterator():
        for bbox in item["annotation"]:
            assert (int(bbox[6]) == 0 or int(bbox[6]) == 1 or int(bbox[6]) == 2
                    or int(bbox[6]) == 3 or int(bbox[6]) == 4
                    or int(bbox[6]) == 5)
            count[int(bbox[6])] += 1
        num += 1
    assert num == 9
    assert count == [3, 2, 1, 2, 4, 3]
def test_random_resized_crop_with_bbox_op_invalid_c():
    """
    Tests RandomResizedCropWithBBox on invalid constructor parameters, expected to raise ValueError
    """
    logger.info("test_random_resized_crop_with_bbox_op_invalid_c")

    # Load dataset, only Augmented Dataset as test will raise ValueError
    dataVoc2 = ds.VOCDataset(DATA_DIR_VOC,
                             task="Detection",
                             usage="train",
                             shuffle=False,
                             decode=True)

    try:
        # If input range of scale is not in the order of (min, max), ValueError will be raised.
        test_op = c_vision.RandomResizedCropWithBBox((256, 512), (1, 0.5),
                                                     (0.5, 0.5))

        # map to apply ops
        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 "scale should be in (min,max) format. Got (max,min)." in str(
            err)
Exemplo n.º 14
0
def c_random_vertical_flip_with_bbox_op_bad():
    # Should Fail - Errors logged to logger
    for ix, badFunc in enumerate(badGenFuncs):
        try:
            dataVoc2 = ds.VOCDataset(DATA_DIR,
                                     task="Detection",
                                     mode="train",
                                     decode=True,
                                     shuffle=False)

            test_op = c_vision.RandomVerticalFlipWithBBox(1)

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

            dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"],
                                    output_columns=["image", "annotation"],
                                    columns_order=["image", "annotation"],
                                    operations=[badFunc])

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

            for _ in dataVoc2.create_dict_iterator():
                break  # first sample will cause exception

        except RuntimeError as err:
            logger.info("Got an exception in DE: {}".format(str(err)))
            assert assertVal[ix] in str(err)
Exemplo n.º 15
0
def c_random_vertical_flip_with_bbox_op_invalid():
    # Should Fail
    # Load dataset

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

    try:
        test_op = c_vision.RandomVerticalFlipWithBBox(2)

        # maps to fix annotations to HQ standard

        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])

        for _ in dataVoc2.create_dict_iterator():
            break

    except ValueError as err:
        logger.info("Got an exception in DE: {}".format(str(err)))
        assert "Input is not" in str(err)
def test_random_vertical_flip_with_bbox_op_rand_c(plot_vis=False):
    """
    Prints images and bboxes side by side with and without RandomVerticalFlipWithBBox Op applied,
    tests with MD5 check, expected to pass
    """
    logger.info("test_random_vertical_flip_with_bbox_op_rand_c")
    original_seed = config_get_set_seed(29847)
    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)

    test_op = c_vision.RandomVerticalFlipWithBBox(0.8)

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

    filename = "random_vertical_flip_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)
Exemplo n.º 17
0
def test_bounding_box_augment_with_crop_op(plot_vis=False):
    """
    Test BoundingBoxAugment op (passing crop op as transform)
    Prints images side by side with and without Aug applied + bboxes to compare and test
    """
    logger.info("test_bounding_box_augment_with_crop_op")

    original_seed = config_get_set_seed(0)
    original_num_parallel_workers = config_get_set_num_parallel_workers(1)

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

    # Ratio is set to 0.9 to apply RandomCrop of size (50, 50) on 90% of the bounding boxes.
    test_op = c_vision.BoundingBoxAugment(c_vision.RandomCrop(50), 0.9)

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

    filename = "bounding_box_augment_crop_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)
Exemplo n.º 18
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",
                             mode="train",
                             decode=True,
                             shuffle=False)
    dataVoc2 = ds.VOCDataset(DATA_DIR_VOC,
                             task="Detection",
                             mode="train",
                             decode=True,
                             shuffle=False)

    # 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(input_columns=["image", "annotation"],
                            output_columns=["image", "annotation"],
                            columns_order=["image", "annotation"],
                            operations=[test_op])

    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(),
                          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)
Exemplo n.º 19
0
def test_voc_segmentation():
    data1 = ds.VOCDataset(DATA_DIR, task="Segmentation", usage="train", shuffle=False, decode=True)
    num = 0
    for item in data1.create_dict_iterator(num_epochs=1, output_numpy=True):
        assert item["image"].shape[0] == IMAGE_SHAPE[num]
        assert item["target"].shape[0] == TARGET_SHAPE[num]
        num += 1
    assert num == 10
Exemplo n.º 20
0
def test_bounding_box_augment_invalid_bounds_c():
    """
    Test BoundingBoxAugment op with invalid bboxes.
    """
    logger.info("test_bounding_box_augment_invalid_bounds_c")

    test_op = c_vision.BoundingBoxAugment(c_vision.RandomHorizontalFlip(1),
                                          1)

    dataVoc2 = ds.VOCDataset(DATA_DIR, task="Detection", mode="train", decode=True, shuffle=False)
    check_bad_bbox(dataVoc2, test_op, InvalidBBoxType.WidthOverflow, "bounding boxes is out of bounds of the image")
    dataVoc2 = ds.VOCDataset(DATA_DIR, task="Detection", mode="train", decode=True, shuffle=False)
    check_bad_bbox(dataVoc2, test_op, InvalidBBoxType.HeightOverflow, "bounding boxes is out of bounds of the image")
    dataVoc2 = ds.VOCDataset(DATA_DIR, task="Detection", mode="train", decode=True, shuffle=False)
    check_bad_bbox(dataVoc2, test_op, InvalidBBoxType.NegativeXY, "min_x")
    dataVoc2 = ds.VOCDataset(DATA_DIR, task="Detection", mode="train", decode=True, shuffle=False)
    check_bad_bbox(dataVoc2, test_op, InvalidBBoxType.WrongShape, "4 features")
Exemplo n.º 21
0
def test_bounding_box_augment_valid_edge_c(plot_vis=False):
    """
    Test BoundingBoxAugment op (testing with valid edge case, box covering full image).
    Prints images side by side with and without Aug applied + bboxes to compare and test
    """
    logger.info("test_bounding_box_augment_valid_edge_c")

    original_seed = config_get_set_seed(1)
    original_num_parallel_workers = config_get_set_num_parallel_workers(1)

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

    test_op = c_vision.BoundingBoxAugment(c_vision.RandomHorizontalFlip(1), 1)

    # map to apply ops
    # Add column for "bbox"
    dataVoc1 = dataVoc1.map(
        operations=lambda img, bbox: (img, np.array([[0, 0, img.shape[1], img.shape[0], 0, 0, 0]]).astype(np.float32)),
        input_columns=["image", "bbox"],
        output_columns=["image", "bbox"],
        column_order=["image", "bbox"])
    dataVoc2 = dataVoc2.map(
        operations=lambda img, bbox: (img, np.array([[0, 0, img.shape[1], img.shape[0], 0, 0, 0]]).astype(np.float32)),
        input_columns=["image", "bbox"],
        output_columns=["image", "bbox"],
        column_order=["image", "bbox"])
    dataVoc2 = dataVoc2.map(operations=[test_op], input_columns=["image", "bbox"],
                            output_columns=["image", "bbox"],
                            column_order=["image", "bbox"])
    filename = "bounding_box_augment_valid_edge_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)
Exemplo n.º 22
0
def test_bounding_box_augment_valid_ratio_c(plot_vis=False):
    """
    Test BoundingBoxAugment op (testing with valid ratio, less than 1.
    Prints images side by side with and without Aug applied + bboxes to compare and test
    """
    logger.info("test_bounding_box_augment_valid_ratio_c")

    original_seed = config_get_set_seed(1)
    original_num_parallel_workers = config_get_set_num_parallel_workers(1)

    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.BoundingBoxAugment(c_vision.RandomHorizontalFlip(1),
                                          0.9)

    # map to apply ops
    dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"],
                            output_columns=["image", "annotation"],
                            columns_order=["image", "annotation"],
                            operations=[test_op
                                        ])  # Add column for "annotation"
    filename = "bounding_box_augment_valid_ratio_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)
Exemplo n.º 23
0
def c_random_vertical_flip_with_bbox_op_edge(plot_vis=False):
    # Should Pass
    # 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.RandomVerticalFlipWithBBox(0.6)

    # maps to fix annotations to HQ standard
    dataVoc1 = dataVoc1.map(input_columns=["annotation"],
                            output_columns=["annotation"],
                            operations=fix_annotate)
    dataVoc2 = dataVoc2.map(input_columns=["annotation"],
                            output_columns=["annotation"],
                            operations=fix_annotate)

    # Modify BBoxes to serve as valid edge cases
    dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"],
                            output_columns=["image", "annotation"],
                            columns_order=["image", "annotation"],
                            operations=[gen_bbox_edge])

    # map to apply ops
    dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"],
                            output_columns=["image", "annotation"],
                            columns_order=["image", "annotation"],
                            operations=[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(unaugSamp, augSamp)
Exemplo n.º 24
0
def test_random_resize_with_bbox_op_voc_c(plot_vis=False):
    """
    Prints images and bboxes side by side with and without RandomResizeWithBBox Op applied
    testing with VOC dataset
    """
    logger.info("test_random_resize_with_bbox_op_voc_c")
    original_seed = config_get_set_seed(123)
    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(100)

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

    filename = "random_resize_with_bbox_op_01_c_voc_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)
Exemplo n.º 25
0
def c_random_crop_with_bbox_op2(plot_vis=False):
    """
     Prints images side by side with and without Aug applied + bboxes
     With Fill Value
    """

    # 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)

    # 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))

    # maps to fix annotations to HQ standard
    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
                                        ])  # Add column for "annotation"

    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(unaugSamp, augSamp)
Exemplo n.º 26
0
def test_resize_with_bbox_op_edge_c(plot_vis=False):
    """
    Prints images and bboxes side by side with and without ResizeWithBBox 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_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.ResizeWithBBox(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))])

    # Test Op added to list of Operations here
    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)
def test_random_horizontal_flip_with_bbox_op_c(plot_vis=False):
    """
    Prints images side by side with and without Aug applied + bboxes to
    compare and test
    """
    logger.info("test_random_horizontal_flip_with_bbox_op_c")

    # 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.RandomHorizontalFlipWithBBox(1)

    # maps to fix annotations to minddata standard
    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])

    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)
Exemplo n.º 28
0
def test_noop_sched():
    os.environ['MS_ROLE'] = 'MS_SCHED'
    context.set_ps_context(enable_ps=True)
    data1 = ds.VOCDataset(DATA_DIR, task="Segmentation", usage="train", shuffle=False, decode=True)
    num = 0
    for _ in data1.create_dict_iterator(num_epochs=1):
        num += 1
    assert num == 0
    del os.environ['MS_ROLE']
    context.set_ps_context(enable_ps=False)
Exemplo n.º 29
0
def test_voc_normal():
    data1 = ds.VOCDataset(DATA_DIR, decode=True)
    num = 0
    for item in data1.create_dict_iterator():
        logger.info("item[image] is {}".format(item["image"]))
        logger.info("item[image].shape is {}".format(item["image"].shape))
        logger.info("item[target] is {}".format(item["target"]))
        logger.info("item[target].shape is {}".format(item["target"].shape))
        num += 1
    logger.info("num is {}".format(str(num)))
Exemplo n.º 30
0
def test_c_random_resized_crop_with_bbox_op(plot_vis=False):
    """
     Prints images side by side with and without Aug applied + bboxes to compare and test
    """
    # 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.RandomResizedCropWithBBox((256, 512), (0.5, 0.5),
                                                 (0.5, 0.5))

    # maps to fix annotations to HQ standard
    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
                                        ])  # Add column for "annotation"

    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(unaugSamp, augSamp)