diff --git a/tests/ut/data/dataset/golden/random_grayscale_01_result.npz b/tests/ut/data/dataset/golden/random_grayscale_01_result.npz new file mode 100644 index 0000000000000000000000000000000000000000..d606ab8619e955f7d35ecb0939175938bd2604ec Binary files /dev/null and b/tests/ut/data/dataset/golden/random_grayscale_01_result.npz differ diff --git a/tests/ut/data/dataset/golden/random_grayscale_02_result.npz b/tests/ut/data/dataset/golden/random_grayscale_02_result.npz new file mode 100644 index 0000000000000000000000000000000000000000..3333dd17841153a4453cb2a8e75dce6e8f10ce56 Binary files /dev/null and b/tests/ut/data/dataset/golden/random_grayscale_02_result.npz differ diff --git a/tests/ut/data/dataset/golden/random_horizontal_01_c_result.npz b/tests/ut/data/dataset/golden/random_horizontal_01_c_result.npz new file mode 100644 index 0000000000000000000000000000000000000000..99d4b849dd80376aa85939b038f444272ef16866 Binary files /dev/null and b/tests/ut/data/dataset/golden/random_horizontal_01_c_result.npz differ diff --git a/tests/ut/data/dataset/golden/random_horizontal_01_py_result.npz b/tests/ut/data/dataset/golden/random_horizontal_01_py_result.npz new file mode 100644 index 0000000000000000000000000000000000000000..262c01c99f73391b088e616852d652346dc70576 Binary files /dev/null and b/tests/ut/data/dataset/golden/random_horizontal_01_py_result.npz differ diff --git a/tests/ut/data/dataset/golden/random_vertical_01_c_result.npz b/tests/ut/data/dataset/golden/random_vertical_01_c_result.npz new file mode 100644 index 0000000000000000000000000000000000000000..e09d5774e02ac2eef32dd357e89c268e0bae1cf3 Binary files /dev/null and b/tests/ut/data/dataset/golden/random_vertical_01_c_result.npz differ diff --git a/tests/ut/data/dataset/golden/random_vertical_01_py_result.npz b/tests/ut/data/dataset/golden/random_vertical_01_py_result.npz new file mode 100644 index 0000000000000000000000000000000000000000..7145fc35df626989686726197fbb54ec7a2979ac Binary files /dev/null and b/tests/ut/data/dataset/golden/random_vertical_01_py_result.npz differ diff --git a/tests/ut/python/dataset/test_random_crop.py b/tests/ut/python/dataset/test_random_crop.py index 75beaa48161246a641477f87f44d2868998bd6ab..80746845790d688d9e4c0a80403c3cbd43dc6ce6 100644 --- a/tests/ut/python/dataset/test_random_crop.py +++ b/tests/ut/python/dataset/test_random_crop.py @@ -21,7 +21,8 @@ import mindspore.dataset.transforms.vision.py_transforms as py_vision import mindspore.dataset.transforms.vision.utils as mode import mindspore.dataset as ds from mindspore import log as logger -from util import save_and_check_md5, visualize +from util import save_and_check_md5, visualize, config_get_set_seed, \ + config_get_set_num_parallel_workers GENERATE_GOLDEN = False @@ -30,11 +31,11 @@ DATA_DIR = ["../data/dataset/test_tf_file_3_images/train-0000-of-0001.data"] SCHEMA_DIR = "../data/dataset/test_tf_file_3_images/datasetSchema.json" -def test_random_crop_op(plot=False): +def test_random_crop_op_c(plot=False): """ - Test RandomCrop Op + Test RandomCrop Op in c transforms """ - logger.info("test_random_crop_op") + logger.info("test_random_crop_op_c") # First dataset data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -58,13 +59,47 @@ def test_random_crop_op(plot=False): if plot: visualize(image, image_cropped) +def test_random_crop_op_py(plot=False): + """ + Test RandomCrop op in py transforms + """ + logger.info("test_random_crop_op_py") + # First dataset + data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) + transforms1 = [ + py_vision.Decode(), + py_vision.RandomCrop([512, 512], [200, 200, 200, 200]), + py_vision.ToTensor() + ] + transform1 = py_vision.ComposeOp(transforms1) + data1 = data1.map(input_columns=["image"], operations=transform1()) + # Second dataset + # Second dataset for comparison + data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) + transforms2 = [ + py_vision.Decode(), + py_vision.ToTensor() + ] + transform2 = py_vision.ComposeOp(transforms2) + data2 = data2.map(input_columns=["image"], operations=transform2()) + + crop_images = [] + original_images = [] + for item1, item2 in zip(data1.create_dict_iterator(), data2.create_dict_iterator()): + crop = (item1["image"].transpose(1, 2, 0) * 255).astype(np.uint8) + original = (item2["image"].transpose(1, 2, 0) * 255).astype(np.uint8) + crop_images.append(crop) + original_images.append(original) + if plot: + visualize(original_images, crop_images) + def test_random_crop_01_c(): """ Test RandomCrop op with c_transforms: size is a single integer, expected to pass """ logger.info("test_random_crop_01_c") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # Generate dataset data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -77,13 +112,17 @@ def test_random_crop_01_c(): filename = "random_crop_01_c_result.npz" save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_01_py(): """ Test RandomCrop op with py_transforms: size is a single integer, expected to pass """ logger.info("test_random_crop_01_py") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # Generate dataset data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -99,13 +138,17 @@ def test_random_crop_01_py(): filename = "random_crop_01_py_result.npz" save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_02_c(): """ Test RandomCrop op with c_transforms: size is a list/tuple with length 2, expected to pass """ logger.info("test_random_crop_02_c") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # Generate dataset data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -118,13 +161,17 @@ def test_random_crop_02_c(): filename = "random_crop_02_c_result.npz" save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_02_py(): """ Test RandomCrop op with py_transforms: size is a list/tuple with length 2, expected to pass """ logger.info("test_random_crop_02_py") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # Generate dataset data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -140,13 +187,17 @@ def test_random_crop_02_py(): filename = "random_crop_02_py_result.npz" save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_03_c(): """ Test RandomCrop op with c_transforms: input image size == crop size, expected to pass """ logger.info("test_random_crop_03_c") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # Generate dataset data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -159,13 +210,17 @@ def test_random_crop_03_c(): filename = "random_crop_03_c_result.npz" save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_03_py(): """ Test RandomCrop op with py_transforms: input image size == crop size, expected to pass """ logger.info("test_random_crop_03_py") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # Generate dataset data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -181,27 +236,28 @@ def test_random_crop_03_py(): filename = "random_crop_03_py_result.npz" save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_04_c(): """ Test RandomCrop op with c_transforms: input image size < crop size, expected to fail """ logger.info("test_random_crop_04_c") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + + # Generate dataset + data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) + # Note: The size of the image is 4032*2268 + random_crop_op = c_vision.RandomCrop([2268, 4033]) + decode_op = c_vision.Decode() + data = data.map(input_columns=["image"], operations=decode_op) + data = data.map(input_columns=["image"], operations=random_crop_op) try: - # Generate dataset - data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) - # Note: The size of the image is 4032*2268 - random_crop_op = c_vision.RandomCrop([2268, 4033]) - decode_op = c_vision.Decode() - data = data.map(input_columns=["image"], operations=decode_op) - data = data.map(input_columns=["image"], operations=random_crop_op) - image_list = [] - for item in data.create_dict_iterator(): - image = item["image"] - image_list.append(image.shape) - except Exception as e: + data.create_dict_iterator().get_next() + except RuntimeError as e: logger.info("Got an exception in DE: {}".format(str(e))) + assert "Crop size is greater than the image dim" in str(e) def test_random_crop_04_py(): """ @@ -209,25 +265,20 @@ def test_random_crop_04_py(): input image size < crop size, expected to fail """ logger.info("test_random_crop_04_py") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + # Generate dataset + data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) + # Note: The size of the image is 4032*2268 + transforms = [ + py_vision.Decode(), + py_vision.RandomCrop([2268, 4033]), + py_vision.ToTensor() + ] + transform = py_vision.ComposeOp(transforms) + data = data.map(input_columns=["image"], operations=transform()) try: - # Generate dataset - data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) - # Note: The size of the image is 4032*2268 - transforms = [ - py_vision.Decode(), - py_vision.RandomCrop([2268, 4033]), - py_vision.ToTensor() - ] - transform = py_vision.ComposeOp(transforms) - data = data.map(input_columns=["image"], operations=transform()) - image_list = [] - for item in data.create_dict_iterator(): - image = (item["image"].transpose(1, 2, 0) * 255).astype(np.uint8) - image_list.append(image.shape) - except Exception as e: + data.create_dict_iterator().get_next() + except RuntimeError as e: logger.info("Got an exception in DE: {}".format(str(e))) def test_random_crop_05_c(): @@ -237,8 +288,8 @@ def test_random_crop_05_c(): expected to pass """ logger.info("test_random_crop_05_c") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # Generate dataset data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -251,6 +302,10 @@ def test_random_crop_05_c(): filename = "random_crop_05_c_result.npz" save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_05_py(): """ Test RandomCrop op with py_transforms: @@ -258,8 +313,8 @@ def test_random_crop_05_py(): expected to pass """ logger.info("test_random_crop_05_py") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # Generate dataset data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -275,30 +330,28 @@ def test_random_crop_05_py(): filename = "random_crop_05_py_result.npz" save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_06_c(): """ Test RandomCrop op with c_transforms: invalid size, expected to raise TypeError """ logger.info("test_random_crop_06_c") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + # Generate dataset + data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) try: - # Generate dataset - data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) # Note: if size is neither an int nor a list of length 2, an exception will raise random_crop_op = c_vision.RandomCrop([512, 512, 375]) decode_op = c_vision.Decode() data = data.map(input_columns=["image"], operations=decode_op) data = data.map(input_columns=["image"], operations=random_crop_op) - image_list = [] - for item in data.create_dict_iterator(): - image = item["image"] - image_list.append(image.shape) except TypeError as e: logger.info("Got an exception in DE: {}".format(str(e))) - assert "Size" in str(e) + assert "Size should be a single integer" in str(e) def test_random_crop_06_py(): """ @@ -306,12 +359,10 @@ def test_random_crop_06_py(): invalid size, expected to raise TypeError """ logger.info("test_random_crop_06_py") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + # Generate dataset + data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) try: - # Generate dataset - data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) # Note: if size is neither an int nor a list of length 2, an exception will raise transforms = [ py_vision.Decode(), @@ -320,13 +371,9 @@ def test_random_crop_06_py(): ] transform = py_vision.ComposeOp(transforms) data = data.map(input_columns=["image"], operations=transform()) - image_list = [] - for item in data.create_dict_iterator(): - image = (item["image"].transpose(1, 2, 0) * 255).astype(np.uint8) - image_list.append(image.shape) except TypeError as e: logger.info("Got an exception in DE: {}".format(str(e))) - assert "Size" in str(e) + assert "Size should be a single integer" in str(e) def test_random_crop_07_c(): """ @@ -335,8 +382,8 @@ def test_random_crop_07_c(): expected to pass """ logger.info("test_random_crop_07_c") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # Generate dataset data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -349,6 +396,10 @@ def test_random_crop_07_c(): filename = "random_crop_07_c_result.npz" save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_07_py(): """ Test RandomCrop op with py_transforms: @@ -356,8 +407,8 @@ def test_random_crop_07_py(): expected to pass """ logger.info("test_random_crop_07_py") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # Generate dataset data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -373,14 +424,18 @@ def test_random_crop_07_py(): filename = "random_crop_07_py_result.npz" save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_08_c(): """ Test RandomCrop op with c_transforms: padding_mode is Border.EDGE, expected to pass """ logger.info("test_random_crop_08_c") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # Generate dataset data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -393,14 +448,18 @@ def test_random_crop_08_c(): filename = "random_crop_08_c_result.npz" save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_08_py(): """ Test RandomCrop op with py_transforms: padding_mode is Border.EDGE, expected to pass """ logger.info("test_random_crop_08_py") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # Generate dataset data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -416,13 +475,15 @@ def test_random_crop_08_py(): filename = "random_crop_08_py_result.npz" save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_09(): """ Test RandomCrop op: invalid type of input image (not PIL), expected to raise TypeError """ logger.info("test_random_crop_09") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) # Generate dataset data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -433,13 +494,10 @@ def test_random_crop_09(): py_vision.RandomCrop(512) ] transform = py_vision.ComposeOp(transforms) + data = data.map(input_columns=["image"], operations=transform()) try: - data = data.map(input_columns=["image"], operations=transform()) - image_list = [] - for item in data.create_dict_iterator(): - image = item["image"] - image_list.append(image.shape) - except Exception as e: + data.create_dict_iterator().get_next() + except RuntimeError as e: logger.info("Got an exception in DE: {}".format(str(e))) assert "should be PIL Image" in str(e) @@ -448,8 +506,6 @@ def test_random_crop_comp(plot=False): Test RandomCrop and compare between python and c image augmentation """ logger.info("Test RandomCrop with c_transform and py_transform comparison") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) cropped_size = 512 # First dataset @@ -479,6 +535,7 @@ def test_random_crop_comp(plot=False): if plot: visualize(image_c_cropped, image_py_cropped) + if __name__ == "__main__": test_random_crop_01_c() test_random_crop_02_c() @@ -497,5 +554,6 @@ if __name__ == "__main__": test_random_crop_07_py() test_random_crop_08_py() test_random_crop_09() - test_random_crop_op(True) + test_random_crop_op_c(True) + test_random_crop_op_py(True) test_random_crop_comp(True) diff --git a/tests/ut/python/dataset/test_random_crop_and_resize.py b/tests/ut/python/dataset/test_random_crop_and_resize.py index e706c9b2266eb3a74c1a24342d7ffc104b1e8cec..2fe158ddd6a164f8fc61678951d70632ac9670ff 100644 --- a/tests/ut/python/dataset/test_random_crop_and_resize.py +++ b/tests/ut/python/dataset/test_random_crop_and_resize.py @@ -23,7 +23,8 @@ import mindspore.dataset.transforms.vision.py_transforms as py_vision import mindspore.dataset.transforms.vision.utils as mode import mindspore.dataset as ds from mindspore import log as logger -from util import diff_mse, save_and_check_md5, visualize +from util import diff_mse, save_and_check_md5, visualize, \ + config_get_set_seed, config_get_set_num_parallel_workers DATA_DIR = ["../data/dataset/test_tf_file_3_images/train-0000-of-0001.data"] SCHEMA_DIR = "../data/dataset/test_tf_file_3_images/datasetSchema.json" @@ -31,11 +32,11 @@ SCHEMA_DIR = "../data/dataset/test_tf_file_3_images/datasetSchema.json" GENERATE_GOLDEN = False -def test_random_crop_and_resize_op(plot=False): +def test_random_crop_and_resize_op_c(plot=False): """ - Test RandomCropAndResize op + Test RandomCropAndResize op in c transforms """ - logger.info("test_random_crop_and_resize_op") + logger.info("test_random_crop_and_resize_op_c") # First dataset data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -64,13 +65,51 @@ def test_random_crop_and_resize_op(plot=False): if plot: visualize(original_images, crop_and_resize_images) +def test_random_crop_and_resize_op_py(plot=False): + """ + Test RandomCropAndResize op in py transforms + """ + logger.info("test_random_crop_and_resize_op_py") + # First dataset + data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) + transforms1 = [ + py_vision.Decode(), + py_vision.RandomResizedCrop((256, 512), (1, 1), (0.5, 0.5)), + py_vision.ToTensor() + ] + transform1 = py_vision.ComposeOp(transforms1) + data1 = data1.map(input_columns=["image"], operations=transform1()) + # Second dataset + # Second dataset for comparison + data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) + transforms2 = [ + py_vision.Decode(), + py_vision.ToTensor() + ] + transform2 = py_vision.ComposeOp(transforms2) + data2 = data2.map(input_columns=["image"], operations=transform2()) + num_iter = 0 + crop_and_resize_images = [] + original_images = [] + for item1, item2 in zip(data1.create_dict_iterator(), data2.create_dict_iterator()): + crop_and_resize = (item1["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)) + mse = diff_mse(crop_and_resize, original) + logger.info("random_crop_and_resize_op_{}, mse: {}".format(num_iter + 1, mse)) + num_iter += 1 + crop_and_resize_images.append(crop_and_resize) + original_images.append(original) + if plot: + visualize(original_images, crop_and_resize_images) + def test_random_crop_and_resize_01(): """ Test RandomCropAndResize with md5 check, expected to pass """ logger.info("test_random_crop_and_resize_01") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # First dataset data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -94,14 +133,18 @@ def test_random_crop_and_resize_01(): save_and_check_md5(data1, filename1, generate_golden=GENERATE_GOLDEN) save_and_check_md5(data2, filename2, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_and_resize_02(): """ Test RandomCropAndResize with md5 check:Image interpolation mode is Inter.NEAREST, expected to pass """ logger.info("test_random_crop_and_resize_02") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # First dataset data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -125,13 +168,17 @@ def test_random_crop_and_resize_02(): save_and_check_md5(data1, filename1, generate_golden=GENERATE_GOLDEN) save_and_check_md5(data2, filename2, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_and_resize_03(): """ Test RandomCropAndResize with md5 check: max_attempts is 1, expected to pass """ logger.info("test_random_crop_and_resize_03") - ds.config.set_seed(0) - ds.config.set_num_parallel_workers(1) + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) # First dataset data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) @@ -155,27 +202,25 @@ def test_random_crop_and_resize_03(): save_and_check_md5(data1, filename1, generate_golden=GENERATE_GOLDEN) save_and_check_md5(data2, filename2, generate_golden=GENERATE_GOLDEN) + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + def test_random_crop_and_resize_04_c(): """ Test RandomCropAndResize with c_tranforms: invalid range of scale (max