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_deviceop_cpu.py 4.1 kB

5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. import time
  16. import mindspore.dataset as ds
  17. import mindspore.dataset.transforms.vision.c_transforms as vision
  18. from mindspore import log as logger
  19. DATA_DIR = ["../data/dataset/test_tf_file_3_images/train-0000-of-0001.data"]
  20. SCHEMA_DIR = "../data/dataset/test_tf_file_3_images/datasetSchema.json"
  21. TF_FILES = ["../data/dataset/testTFTestAllTypes/test.data"]
  22. TF_SCHEMA_FILE = "../data/dataset/testTFTestAllTypes/datasetSchema.json"
  23. def test_case_0():
  24. """
  25. Test Repeat
  26. """
  27. # apply dataset operations
  28. data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, shuffle=False)
  29. # define parameters
  30. repeat_count = 2
  31. data = data.repeat(repeat_count)
  32. data = data.device_que()
  33. data.send()
  34. time.sleep(0.1)
  35. data.stop_send()
  36. def test_case_1():
  37. """
  38. Test Batch
  39. """
  40. data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, shuffle=False)
  41. # define data augmentation parameters
  42. resize_height, resize_width = 224, 224
  43. # define map operations
  44. decode_op = vision.Decode()
  45. resize_op = vision.Resize((resize_height, resize_width))
  46. # apply map operations on images
  47. data = data.map(input_columns=["image"], operations=decode_op)
  48. data = data.map(input_columns=["image"], operations=resize_op)
  49. batch_size = 3
  50. data = data.batch(batch_size, drop_remainder=True)
  51. data = data.device_que()
  52. data.send()
  53. time.sleep(0.1)
  54. data.stop_send()
  55. def test_case_2():
  56. """
  57. Test Batch & Repeat
  58. """
  59. data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, shuffle=False)
  60. # define data augmentation parameters
  61. resize_height, resize_width = 224, 224
  62. # define map operations
  63. decode_op = vision.Decode()
  64. resize_op = vision.Resize((resize_height, resize_width))
  65. # apply map operations on images
  66. data = data.map(input_columns=["image"], operations=decode_op)
  67. data = data.map(input_columns=["image"], operations=resize_op)
  68. batch_size = 2
  69. data = data.batch(batch_size, drop_remainder=True)
  70. data = data.repeat(2)
  71. data = data.device_que()
  72. assert data.get_repeat_count() == 2
  73. data.send()
  74. time.sleep(0.1)
  75. data.stop_send()
  76. def test_case_3():
  77. """
  78. Test Repeat & Batch
  79. """
  80. data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, shuffle=False)
  81. # define data augmentation parameters
  82. resize_height, resize_width = 224, 224
  83. # define map operations
  84. decode_op = vision.Decode()
  85. resize_op = vision.Resize((resize_height, resize_width))
  86. # apply map operations on images
  87. data = data.map(input_columns=["image"], operations=decode_op)
  88. data = data.map(input_columns=["image"], operations=resize_op)
  89. data = data.repeat(2)
  90. batch_size = 2
  91. data = data.batch(batch_size, drop_remainder=True)
  92. data = data.device_que()
  93. data.send()
  94. time.sleep(0.1)
  95. data.stop_send()
  96. def test_case_tf_file():
  97. data = ds.TFRecordDataset(TF_FILES, TF_SCHEMA_FILE, shuffle=ds.Shuffle.FILES)
  98. data = data.to_device()
  99. data.send()
  100. time.sleep(0.1)
  101. data.stop_send()
  102. if __name__ == '__main__':
  103. logger.info('===========now test Repeat============')
  104. test_case_0()
  105. logger.info('===========now test Batch============')
  106. test_case_1()
  107. logger.info('===========now test Batch & Repeat============')
  108. test_case_2()
  109. logger.info('===========now test Repeat & Batch============')
  110. test_case_3()
  111. logger.info('===========now test tf file============')
  112. test_case_tf_file()