|
|
@@ -41,7 +41,8 @@ def test_random_crop_and_resize_op_c(plot=False): |
|
|
# First dataset |
|
|
# First dataset |
|
|
data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) |
|
|
data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) |
|
|
decode_op = c_vision.Decode() |
|
|
decode_op = c_vision.Decode() |
|
|
random_crop_and_resize_op = c_vision.RandomResizedCrop((256, 512), (1, 1), (0.5, 0.5)) |
|
|
|
|
|
|
|
|
# With these inputs we expect the code to crop the whole image |
|
|
|
|
|
random_crop_and_resize_op = c_vision.RandomResizedCrop((256, 512), (2, 2), (1, 3)) |
|
|
data1 = data1.map(input_columns=["image"], operations=decode_op) |
|
|
data1 = data1.map(input_columns=["image"], operations=decode_op) |
|
|
data1 = data1.map(input_columns=["image"], operations=random_crop_and_resize_op) |
|
|
data1 = data1.map(input_columns=["image"], operations=random_crop_and_resize_op) |
|
|
|
|
|
|
|
|
@@ -65,6 +66,7 @@ def test_random_crop_and_resize_op_c(plot=False): |
|
|
if plot: |
|
|
if plot: |
|
|
visualize(original_images, crop_and_resize_images) |
|
|
visualize(original_images, crop_and_resize_images) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_random_crop_and_resize_op_py(plot=False): |
|
|
def test_random_crop_and_resize_op_py(plot=False): |
|
|
""" |
|
|
""" |
|
|
Test RandomCropAndResize op in py transforms |
|
|
Test RandomCropAndResize op in py transforms |
|
|
@@ -72,9 +74,10 @@ def test_random_crop_and_resize_op_py(plot=False): |
|
|
logger.info("test_random_crop_and_resize_op_py") |
|
|
logger.info("test_random_crop_and_resize_op_py") |
|
|
# First dataset |
|
|
# First dataset |
|
|
data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) |
|
|
data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) |
|
|
|
|
|
# With these inputs we expect the code to crop the whole image |
|
|
transforms1 = [ |
|
|
transforms1 = [ |
|
|
py_vision.Decode(), |
|
|
py_vision.Decode(), |
|
|
py_vision.RandomResizedCrop((256, 512), (1, 1), (0.5, 0.5)), |
|
|
|
|
|
|
|
|
py_vision.RandomResizedCrop((256, 512), (2, 2), (1, 3)), |
|
|
py_vision.ToTensor() |
|
|
py_vision.ToTensor() |
|
|
] |
|
|
] |
|
|
transform1 = py_vision.ComposeOp(transforms1) |
|
|
transform1 = py_vision.ComposeOp(transforms1) |
|
|
@@ -96,6 +99,8 @@ def test_random_crop_and_resize_op_py(plot=False): |
|
|
original = (item2["image"].transpose(1, 2, 0) * 255).astype(np.uint8) |
|
|
original = (item2["image"].transpose(1, 2, 0) * 255).astype(np.uint8) |
|
|
original = cv2.resize(original, (512, 256)) |
|
|
original = cv2.resize(original, (512, 256)) |
|
|
mse = diff_mse(crop_and_resize, original) |
|
|
mse = diff_mse(crop_and_resize, original) |
|
|
|
|
|
# Due to rounding error the mse for Python is not exactly 0 |
|
|
|
|
|
assert mse <= 0.05 |
|
|
logger.info("random_crop_and_resize_op_{}, mse: {}".format(num_iter + 1, mse)) |
|
|
logger.info("random_crop_and_resize_op_{}, mse: {}".format(num_iter + 1, mse)) |
|
|
num_iter += 1 |
|
|
num_iter += 1 |
|
|
crop_and_resize_images.append(crop_and_resize) |
|
|
crop_and_resize_images.append(crop_and_resize) |
|
|
@@ -103,6 +108,7 @@ def test_random_crop_and_resize_op_py(plot=False): |
|
|
if plot: |
|
|
if plot: |
|
|
visualize(original_images, crop_and_resize_images) |
|
|
visualize(original_images, crop_and_resize_images) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_random_crop_and_resize_01(): |
|
|
def test_random_crop_and_resize_01(): |
|
|
""" |
|
|
""" |
|
|
Test RandomCropAndResize with md5 check, expected to pass |
|
|
Test RandomCropAndResize with md5 check, expected to pass |
|
|
@@ -114,7 +120,7 @@ def test_random_crop_and_resize_01(): |
|
|
# First dataset |
|
|
# First dataset |
|
|
data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) |
|
|
data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) |
|
|
decode_op = c_vision.Decode() |
|
|
decode_op = c_vision.Decode() |
|
|
random_crop_and_resize_op = c_vision.RandomResizedCrop((256, 512), (0.5, 1), (0.5, 1)) |
|
|
|
|
|
|
|
|
random_crop_and_resize_op = c_vision.RandomResizedCrop((256, 512), (0.5, 0.5), (1, 1)) |
|
|
data1 = data1.map(input_columns=["image"], operations=decode_op) |
|
|
data1 = data1.map(input_columns=["image"], operations=decode_op) |
|
|
data1 = data1.map(input_columns=["image"], operations=random_crop_and_resize_op) |
|
|
data1 = data1.map(input_columns=["image"], operations=random_crop_and_resize_op) |
|
|
|
|
|
|
|
|
@@ -122,7 +128,7 @@ def test_random_crop_and_resize_01(): |
|
|
data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) |
|
|
data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) |
|
|
transforms = [ |
|
|
transforms = [ |
|
|
py_vision.Decode(), |
|
|
py_vision.Decode(), |
|
|
py_vision.RandomResizedCrop((256, 512), (0.5, 1), (0.5, 1)), |
|
|
|
|
|
|
|
|
py_vision.RandomResizedCrop((256, 512), (0.5, 0.5), (1, 1)), |
|
|
py_vision.ToTensor() |
|
|
py_vision.ToTensor() |
|
|
] |
|
|
] |
|
|
transform = py_vision.ComposeOp(transforms) |
|
|
transform = py_vision.ComposeOp(transforms) |
|
|
@@ -137,6 +143,7 @@ def test_random_crop_and_resize_01(): |
|
|
ds.config.set_seed(original_seed) |
|
|
ds.config.set_seed(original_seed) |
|
|
ds.config.set_num_parallel_workers(original_num_parallel_workers) |
|
|
ds.config.set_num_parallel_workers(original_num_parallel_workers) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_random_crop_and_resize_02(): |
|
|
def test_random_crop_and_resize_02(): |
|
|
""" |
|
|
""" |
|
|
Test RandomCropAndResize with md5 check:Image interpolation mode is Inter.NEAREST, |
|
|
Test RandomCropAndResize with md5 check:Image interpolation mode is Inter.NEAREST, |
|
|
@@ -172,6 +179,7 @@ def test_random_crop_and_resize_02(): |
|
|
ds.config.set_seed(original_seed) |
|
|
ds.config.set_seed(original_seed) |
|
|
ds.config.set_num_parallel_workers(original_num_parallel_workers) |
|
|
ds.config.set_num_parallel_workers(original_num_parallel_workers) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_random_crop_and_resize_03(): |
|
|
def test_random_crop_and_resize_03(): |
|
|
""" |
|
|
""" |
|
|
Test RandomCropAndResize with md5 check: max_attempts is 1, expected to pass |
|
|
Test RandomCropAndResize with md5 check: max_attempts is 1, expected to pass |
|
|
@@ -206,6 +214,7 @@ def test_random_crop_and_resize_03(): |
|
|
ds.config.set_seed(original_seed) |
|
|
ds.config.set_seed(original_seed) |
|
|
ds.config.set_num_parallel_workers(original_num_parallel_workers) |
|
|
ds.config.set_num_parallel_workers(original_num_parallel_workers) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_random_crop_and_resize_04_c(): |
|
|
def test_random_crop_and_resize_04_c(): |
|
|
""" |
|
|
""" |
|
|
Test RandomCropAndResize with c_tranforms: invalid range of scale (max<min), |
|
|
Test RandomCropAndResize with c_tranforms: invalid range of scale (max<min), |
|
|
@@ -225,6 +234,7 @@ def test_random_crop_and_resize_04_c(): |
|
|
logger.info("Got an exception in DE: {}".format(str(e))) |
|
|
logger.info("Got an exception in DE: {}".format(str(e))) |
|
|
assert "Input range is not valid" in str(e) |
|
|
assert "Input range is not valid" in str(e) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_random_crop_and_resize_04_py(): |
|
|
def test_random_crop_and_resize_04_py(): |
|
|
""" |
|
|
""" |
|
|
Test RandomCropAndResize with py_transforms: invalid range of scale (max<min), |
|
|
Test RandomCropAndResize with py_transforms: invalid range of scale (max<min), |
|
|
@@ -247,6 +257,7 @@ def test_random_crop_and_resize_04_py(): |
|
|
logger.info("Got an exception in DE: {}".format(str(e))) |
|
|
logger.info("Got an exception in DE: {}".format(str(e))) |
|
|
assert "Input range is not valid" in str(e) |
|
|
assert "Input range is not valid" in str(e) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_random_crop_and_resize_05_c(): |
|
|
def test_random_crop_and_resize_05_c(): |
|
|
""" |
|
|
""" |
|
|
Test RandomCropAndResize with c_transforms: invalid range of ratio (max<min), |
|
|
Test RandomCropAndResize with c_transforms: invalid range of ratio (max<min), |
|
|
@@ -266,6 +277,7 @@ def test_random_crop_and_resize_05_c(): |
|
|
logger.info("Got an exception in DE: {}".format(str(e))) |
|
|
logger.info("Got an exception in DE: {}".format(str(e))) |
|
|
assert "Input range is not valid" in str(e) |
|
|
assert "Input range is not valid" in str(e) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_random_crop_and_resize_05_py(): |
|
|
def test_random_crop_and_resize_05_py(): |
|
|
""" |
|
|
""" |
|
|
Test RandomCropAndResize with py_transforms: invalid range of ratio (max<min), |
|
|
Test RandomCropAndResize with py_transforms: invalid range of ratio (max<min), |
|
|
@@ -288,6 +300,7 @@ def test_random_crop_and_resize_05_py(): |
|
|
logger.info("Got an exception in DE: {}".format(str(e))) |
|
|
logger.info("Got an exception in DE: {}".format(str(e))) |
|
|
assert "Input range is not valid" in str(e) |
|
|
assert "Input range is not valid" in str(e) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_random_crop_and_resize_comp(plot=False): |
|
|
def test_random_crop_and_resize_comp(plot=False): |
|
|
""" |
|
|
""" |
|
|
Test RandomCropAndResize and compare between python and c image augmentation |
|
|
Test RandomCropAndResize and compare between python and c image augmentation |
|
|
@@ -321,6 +334,7 @@ def test_random_crop_and_resize_comp(plot=False): |
|
|
if plot: |
|
|
if plot: |
|
|
visualize(image_c_cropped, image_py_cropped) |
|
|
visualize(image_c_cropped, image_py_cropped) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
|
test_random_crop_and_resize_op_c(True) |
|
|
test_random_crop_and_resize_op_c(True) |
|
|
test_random_crop_and_resize_op_py(True) |
|
|
test_random_crop_and_resize_op_py(True) |
|
|
|