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_cifarop.py 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 mindspore.dataset as ds
  16. from mindspore import log as logger
  17. # Data for CIFAR and MNIST are not part of build tree
  18. # They need to be downloaded directly
  19. # prep_data.py can be executed or code below
  20. # import sys
  21. # sys.path.insert(0,"../../data")
  22. # import prep_data
  23. # prep_data.download_all_for_test("../../data")
  24. DATA_DIR_10 = "../data/dataset/testCifar10Data"
  25. DATA_DIR_100 = "../data/dataset/testCifar100Data"
  26. def test_case_dataset_cifar10():
  27. """
  28. dataset parameter
  29. """
  30. logger.info("Test dataset parameter")
  31. # apply dataset operations
  32. data1 = ds.Cifar10Dataset(DATA_DIR_10, 100)
  33. num_iter = 0
  34. for item in data1.create_dict_iterator():
  35. # in this example, each dictionary has keys "image" and "label"
  36. num_iter += 1
  37. assert (num_iter == 100)
  38. def test_case_dataset_cifar100():
  39. """
  40. dataset parameter
  41. """
  42. logger.info("Test dataset parameter")
  43. # apply dataset operations
  44. data1 = ds.Cifar100Dataset(DATA_DIR_100, 100)
  45. num_iter = 0
  46. for item in data1.create_dict_iterator():
  47. # in this example, each dictionary has keys "image" and "label"
  48. num_iter += 1
  49. assert (num_iter == 100)
  50. if __name__ == '__main__':
  51. test_case_dataset_cifar10()
  52. test_case_dataset_cifar100()