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_config.py 2.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 configuration manager
  17. """
  18. import filecmp
  19. import glob
  20. import os
  21. import mindspore.dataset as ds
  22. import mindspore.dataset.transforms.vision.c_transforms as vision
  23. DATA_DIR = ["../data/dataset/test_tf_file_3_images/train-0000-of-0001.data"]
  24. SCHEMA_DIR = "../data/dataset/test_tf_file_3_images/datasetSchema.json"
  25. def test_basic():
  26. ds.config.load('../data/dataset/declient.cfg')
  27. # assert ds.config.get_rows_per_buffer() == 32
  28. assert ds.config.get_num_parallel_workers() == 4
  29. # assert ds.config.get_worker_connector_size() == 16
  30. assert ds.config.get_prefetch_size() == 16
  31. assert ds.config.get_seed() == 5489
  32. # ds.config.set_rows_per_buffer(1)
  33. ds.config.set_num_parallel_workers(2)
  34. # ds.config.set_worker_connector_size(3)
  35. ds.config.set_prefetch_size(4)
  36. ds.config.set_seed(5)
  37. # assert ds.config.get_rows_per_buffer() == 1
  38. assert ds.config.get_num_parallel_workers() == 2
  39. # assert ds.config.get_worker_connector_size() == 3
  40. assert ds.config.get_prefetch_size() == 4
  41. assert ds.config.get_seed() == 5
  42. def test_pipeline():
  43. """
  44. Test that our configuration pipeline works when we set parameters at dataset interval
  45. """
  46. data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, shuffle=False)
  47. ds.config.set_num_parallel_workers(2)
  48. data1 = data1.map(input_columns=["image"], operations=[vision.Decode(True)])
  49. ds.serialize(data1, "testpipeline.json")
  50. data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, shuffle=False)
  51. ds.config.set_num_parallel_workers(4)
  52. data2 = data2.map(input_columns=["image"], operations=[vision.Decode(True)])
  53. ds.serialize(data2, "testpipeline2.json")
  54. # check that the generated output is different
  55. assert (filecmp.cmp('testpipeline.json', 'testpipeline2.json'))
  56. # this test passes currently because our num_parallel_workers don't get updated.
  57. # remove generated jason files
  58. file_list = glob.glob('*.json')
  59. for f in file_list:
  60. try:
  61. os.remove(f)
  62. except IOError:
  63. logger.info("Error while deleting: {}".format(f))
  64. if __name__ == '__main__':
  65. test_basic()
  66. test_pipeline()