You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_random_crop.py 2.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright 2019 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. """
  16. Testing RandomCropAndResize op in DE
  17. """
  18. import matplotlib.pyplot as plt
  19. import mindspore.dataset.transforms.vision.c_transforms as vision
  20. from mindspore import log as logger
  21. import mindspore.dataset as ds
  22. DATA_DIR = ["../data/dataset/test_tf_file_3_images/train-0000-of-0001.data"]
  23. SCHEMA_DIR = "../data/dataset/test_tf_file_3_images/datasetSchema.json"
  24. def visualize(a, mse, original):
  25. """
  26. visualizes the image using DE op and Numpy op
  27. """
  28. plt.subplot(141)
  29. plt.imshow(original)
  30. plt.title("Original image")
  31. plt.subplot(142)
  32. plt.imshow(a)
  33. plt.title("DE random_crop image")
  34. plt.subplot(143)
  35. plt.imshow(a - original)
  36. plt.title("Difference image, mse : {}".format(mse))
  37. plt.show()
  38. def test_random_crop_op():
  39. """
  40. Test RandomCropAndResize op
  41. """
  42. logger.info("test_random_crop_and_resize_op")
  43. # First dataset
  44. data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
  45. random_crop_op = vision.RandomCrop([512, 512], [200, 200, 200, 200])
  46. decode_op = vision.Decode()
  47. data1 = data1.map(input_columns=["image"], operations=decode_op)
  48. data1 = data1.map(input_columns=["image"], operations=random_crop_op)
  49. # Second dataset
  50. data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
  51. data2 = data2.map(input_columns=["image"], operations=decode_op)
  52. for item1, item2 in zip(data1.create_dict_iterator(), data2.create_dict_iterator()):
  53. image1 = item1["image"]
  54. image2 = item2["image"]
  55. if __name__ == "__main__":
  56. test_random_crop_op()