def test_random_affine_op_c(plot=False):
    """
    Test RandomAffine in C transformations
    """
    logger.info("test_random_affine_op_c")
    # define map operations
    transforms1 = [
        c_vision.Decode(),
        c_vision.RandomAffine(degrees=0, translate=(0.5, 0.5, 0, 0))
    ]

    transforms2 = [
        c_vision.Decode()
    ]

    #  First dataset
    data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
    data1 = data1.map(operations=transforms1, input_columns=["image"])
    #  Second dataset
    data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
    data2 = data2.map(operations=transforms2, input_columns=["image"])

    image_affine = []
    image_original = []
    for item1, item2 in zip(data1.create_dict_iterator(num_epochs=1, output_numpy=True),
                            data2.create_dict_iterator(num_epochs=1, output_numpy=True)):
        image1 = item1["image"]
        image2 = item2["image"]
        image_affine.append(image1)
        image_original.append(image2)
    if plot:
        visualize_list(image_original, image_affine)
Example #2
0
def test_random_affine_c_md5():
    """
    Test RandomAffine C Op with md5 comparison
    """
    logger.info("test_random_affine_c_md5")
    original_seed = config_get_set_seed(1)
    original_num_parallel_workers = config_get_set_num_parallel_workers(1)
    # define map operations
    transforms = [
        c_vision.Decode(),
        c_vision.RandomAffine(degrees=(-5, 15),
                              translate=(-0.1, 0.1, -0.3, 0.3),
                              scale=(0.9, 1.1),
                              shear=(-10, 10, -5, 5))
    ]

    #  Generate dataset
    data = ds.TFRecordDataset(DATA_DIR,
                              SCHEMA_DIR,
                              columns_list=["image"],
                              shuffle=False)
    data = data.map(operations=transforms, input_columns=["image"])

    # check results with md5 comparison
    filename = "random_affine_01_c_result.npz"
    save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN)

    # Restore configuration
    ds.config.set_seed(original_seed)
    ds.config.set_num_parallel_workers((original_num_parallel_workers))
def test_random_affine_exception_translation_range():
    """
    Test RandomAffine: translation value is not in [-1, 1], expected to raise ValueError
    """
    logger.info("test_random_affine_exception_translation_range")
    try:
        _ = c_vision.RandomAffine(degrees=15, translate=(0.1, 1.5))
    except ValueError as e:
        logger.info("Got an exception in DE: {}".format(str(e)))
        assert str(e) == "Input translate at 1 is not within the required interval of (-1.0 to 1.0)."
    logger.info("test_random_affine_exception_translation_range")
    try:
        _ = c_vision.RandomAffine(degrees=15, translate=(-2, 1.5))
    except ValueError as e:
        logger.info("Got an exception in DE: {}".format(str(e)))
        assert str(e) == "Input translate at 0 is not within the required interval of (-1.0 to 1.0)."