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_batch.py 15 kB

5 years ago
added python api based on cpp api 1st draft of python iterator Added Cifar10 and Cifar100 pybind port Change pybind to use IR for Skip and Manifest Signed-off-by: alex-yuyue <yue.yu1@huawei.com> DatasetNode as a base for all IR nodes namespace change Fix the namespace issue and make ut tests work Signed-off-by: alex-yuyue <yue.yu1@huawei.com> Add VOCDataset !63 Added RandomDataset * Added RandomDataset add imagefolder ir Pybind switch: CelebA and UT !61 CLUE example with class definition * Merge branch 'python-api' of gitee.com:ezphlow/mindspore into clue_class_pybind * Passing testcases * Added CLUE, not working add ManifestDataset IR Signed-off-by: alex-yuyue <yue.yu1@huawei.com> Update Coco & VOC & TFReader, Update clang-format, Reorder datasets_binding !69 Add Generator and move c_dataset.Iterator to dataset.Iterator * Add GeneratorDataset to c_dataset * Add GeneratorDataset to c_dataset !67 Moving c_datasets and adding sampler wrapper * Need to add create() method in datasets.py * migration from c_dataset to dataset part 1 !71 Fix indent error * Fix indentation error !72 Fix c_api tests cases * Fix c_api tests cases !73 Added CSV Dataset * Added CSVDataset pybind switch: Take and CelebA fixes !75 move c_dataset functionality to datasets * Fixed existing testcases * Added working clue and imagefolder * Added sampler conversion from pybind * Added sampler creation !77 Add Python API tree * Python API tree add minddataset TextFileDataset pybind Rename to skip test_concat.py and test_minddataset_exception.py !80 Add batch IR to python-api branch, most test cases work * staging III * staging, add pybind Enable more c_api take and CelebA tests; delete util_c_api !84 Schema changes in datasets.py * Schema changes !85 Remove input_indexes from sub-classes * remove input_index from each subclass !83 Remove C datasets * Removed c_dataset package * Remove c_datasets !82 pybind switch: shuffle * pybind switch: shuffle !86 Add build_vocab * Add build_vocab Rebase with upstream/master _shuffle conflict BatchNode error !88 Fix rebase problem * fix rebase problem Enable more unit tests; code typo/nit fixes !91 Fix python vocag hang * Fix python vocab hang !89 Added BucketBatchByLength Pybind switch * Added BucketBatchByLength Update and enable more tet_c_api_*.py tests !95 Add BuildSentencePeiceVocab * - Add BuildSentencePeiceVocab !96 Fix more tests * - Fix some tests - Enable more test_c_api_* - Add syncwait !99 pybind switch for device op * pybind switch for device op !93 Add getters to python API * Add getters to python API !101 Validate tree, error if graph * - Add sync wait !103 TFrecord/Random Datasets schema problem * - TfRecord/Random schem aproblem !102 Added filter pybind switch * Added Filter pybind switch !104 Fix num_samples * - TfRecord/Random schem aproblem !105 Fix to_device hang * Fix to_device hang !94 Adds Cache support for CLUE dataset * Added cache for all dataset ops * format change * Added CLUE cache support * Added Cache conversion Add save pybind fix compile err init modify concat_node !107 Fix some tests cases * Fix tests cases Enable and fix more tests !109 pybind switch for get dataset size * pybind_get_dataset_size some check-code fixes for pylint, cpplint and clang-format !113 Add callback * revert * dataset_sz 1 line * fix typo * get callback to work !114 Make Android compile clean * Make Android Compile Clean Fix build issues due to rebase !115 Fix more tests * Fix tests cases * !93 Add getters to python API fix test_profiling.py !116 fix get dataset size * fix get dataset size !117 GetColumnNames pybind switch * Added GetColumnNames pybind switch code-check fixes: clangformat, cppcheck, cpplint, pylint Delete duplicate test_c_api_*.py files; more lint fixes !121 Fix cpp tests * Remove extra call to getNext in cpp tests !122 Fix Schema with Generator * Fix Schema with Generator fix some cases of csv & mindrecord !124 fix tfrecord get_dataset_size and add some UTs * fix tfrecord get dataset size and add some ut for get_dataset_size !125 getter separation * Getter separation !126 Fix sampler.GetNumSamples * Fix sampler.GetNumSampler !127 Assign runtime getter to each get function * Assign runtime getter to each get function Fix compile issues !128 Match master code * Match master code !129 Cleanup DeviceOp/save code * Cleanup ToDevice/Save code !130 Add cache fix * Added cache fix for map and image folder !132 Fix testing team issues * Pass queue_name from python to C++ * Add Schema.from_json !131 Fix Cache op issues and delete de_pipeline * Roll back C++ change * Removed de_pipeline and passing all cache tests. * fixed cache tests !134 Cleanup datasets.py part1 * Cleanup dataset.py part1 !133 Updated validation for SentencePieceVocab.from_dataset * Added type_check for column names in SentencePieceVocab.from_dataset Rebase on master 181120 10:20 fix profiling temporary solution of catching stauts from Node.Build() !141 ToDevice Termination * ToDevice termination pylint fixes !137 Fix test team issues and add some corresponding tests * Fix test team issues and add some corresponding tests !138 TreeGetter changes to use OptPass * Getter changes to use OptPass (Zirui) Rebase fix !143 Fix cpplint issue * Fix cpplint issue pylint fixes in updated testcases !145 Reset exceptions testcase * reset exception test to master !146 Fix Check_Pylint Error * Fix Check_Pylint Error !147 fix android * fix android !148 ToDevice changes * Add ToDevice to the iterator List for cleanup at exit !149 Pylint issue * Add ToDevice to the iterator List for cleanup at exit !150 Pylint 2 * Add ToDevice to the iterator List for cleanup at exit !152 ExecutionTree error * ET destructor error !153 in getter_pass, only remove callback, without deleting map op * getter pass no longer removes map !156 early __del__ of iterator/to_device * early __del__ of iterator !155 Address review comments Eric 1 * Added one liner fix to validators.py * roll back signature fix * lint fix * Eric Address comments 2 * C++ lint fix * Address comments Eric 1 !158 Review rework for dataset bindings - part 1 * Reorder nodes repeat and rename * Review rework for dataset bindings - part 1 !154 Fixing minor problems in the comments (datasets.py, python_tree_consumer.cc, iterators_bindings.cc, and iterators.py) * Fixing minor problems in the comments (datasets.py, python_tree_consum… !157 add replace none * Add replace_none to datasets.py, address comments in tests Trying to resolve copy Override the deepcopy method of deviceop Create_ir_tree method Create_ir_tree method 2 Create_ir_tree method 2 del to_device if already exists del to_device if already exists cache getters shapes and types Added yolov3 relaxation, to be rolled back Get shapes and types together bypass yolo NumWorkers for MapOp revert Yolo revert Thor Print more info Debug code: Update LOG INFO to LOG ERROR do not remove epochctrl for getter pass Remove repeat(1) pritn batch size add log to tree_consumer and device_queue op Revert PR 8744 Signed-off-by: alex-yuyue <yue.yu1@huawei.com> __del__ toDEvice __del__ toDevice2 !165 add ifndef ENABLE_ANDROID to device queue print * Add ifndef ENABLE_ANDROID to device queue print revert some changes !166 getter: get_data_info * getter: get_data_info !168 add back tree print * revert info to warnning in one log * add back the missed print tree log Release GIL in GetDataInfo
5 years ago
added python api based on cpp api 1st draft of python iterator Added Cifar10 and Cifar100 pybind port Change pybind to use IR for Skip and Manifest Signed-off-by: alex-yuyue <yue.yu1@huawei.com> DatasetNode as a base for all IR nodes namespace change Fix the namespace issue and make ut tests work Signed-off-by: alex-yuyue <yue.yu1@huawei.com> Add VOCDataset !63 Added RandomDataset * Added RandomDataset add imagefolder ir Pybind switch: CelebA and UT !61 CLUE example with class definition * Merge branch 'python-api' of gitee.com:ezphlow/mindspore into clue_class_pybind * Passing testcases * Added CLUE, not working add ManifestDataset IR Signed-off-by: alex-yuyue <yue.yu1@huawei.com> Update Coco & VOC & TFReader, Update clang-format, Reorder datasets_binding !69 Add Generator and move c_dataset.Iterator to dataset.Iterator * Add GeneratorDataset to c_dataset * Add GeneratorDataset to c_dataset !67 Moving c_datasets and adding sampler wrapper * Need to add create() method in datasets.py * migration from c_dataset to dataset part 1 !71 Fix indent error * Fix indentation error !72 Fix c_api tests cases * Fix c_api tests cases !73 Added CSV Dataset * Added CSVDataset pybind switch: Take and CelebA fixes !75 move c_dataset functionality to datasets * Fixed existing testcases * Added working clue and imagefolder * Added sampler conversion from pybind * Added sampler creation !77 Add Python API tree * Python API tree add minddataset TextFileDataset pybind Rename to skip test_concat.py and test_minddataset_exception.py !80 Add batch IR to python-api branch, most test cases work * staging III * staging, add pybind Enable more c_api take and CelebA tests; delete util_c_api !84 Schema changes in datasets.py * Schema changes !85 Remove input_indexes from sub-classes * remove input_index from each subclass !83 Remove C datasets * Removed c_dataset package * Remove c_datasets !82 pybind switch: shuffle * pybind switch: shuffle !86 Add build_vocab * Add build_vocab Rebase with upstream/master _shuffle conflict BatchNode error !88 Fix rebase problem * fix rebase problem Enable more unit tests; code typo/nit fixes !91 Fix python vocag hang * Fix python vocab hang !89 Added BucketBatchByLength Pybind switch * Added BucketBatchByLength Update and enable more tet_c_api_*.py tests !95 Add BuildSentencePeiceVocab * - Add BuildSentencePeiceVocab !96 Fix more tests * - Fix some tests - Enable more test_c_api_* - Add syncwait !99 pybind switch for device op * pybind switch for device op !93 Add getters to python API * Add getters to python API !101 Validate tree, error if graph * - Add sync wait !103 TFrecord/Random Datasets schema problem * - TfRecord/Random schem aproblem !102 Added filter pybind switch * Added Filter pybind switch !104 Fix num_samples * - TfRecord/Random schem aproblem !105 Fix to_device hang * Fix to_device hang !94 Adds Cache support for CLUE dataset * Added cache for all dataset ops * format change * Added CLUE cache support * Added Cache conversion Add save pybind fix compile err init modify concat_node !107 Fix some tests cases * Fix tests cases Enable and fix more tests !109 pybind switch for get dataset size * pybind_get_dataset_size some check-code fixes for pylint, cpplint and clang-format !113 Add callback * revert * dataset_sz 1 line * fix typo * get callback to work !114 Make Android compile clean * Make Android Compile Clean Fix build issues due to rebase !115 Fix more tests * Fix tests cases * !93 Add getters to python API fix test_profiling.py !116 fix get dataset size * fix get dataset size !117 GetColumnNames pybind switch * Added GetColumnNames pybind switch code-check fixes: clangformat, cppcheck, cpplint, pylint Delete duplicate test_c_api_*.py files; more lint fixes !121 Fix cpp tests * Remove extra call to getNext in cpp tests !122 Fix Schema with Generator * Fix Schema with Generator fix some cases of csv & mindrecord !124 fix tfrecord get_dataset_size and add some UTs * fix tfrecord get dataset size and add some ut for get_dataset_size !125 getter separation * Getter separation !126 Fix sampler.GetNumSamples * Fix sampler.GetNumSampler !127 Assign runtime getter to each get function * Assign runtime getter to each get function Fix compile issues !128 Match master code * Match master code !129 Cleanup DeviceOp/save code * Cleanup ToDevice/Save code !130 Add cache fix * Added cache fix for map and image folder !132 Fix testing team issues * Pass queue_name from python to C++ * Add Schema.from_json !131 Fix Cache op issues and delete de_pipeline * Roll back C++ change * Removed de_pipeline and passing all cache tests. * fixed cache tests !134 Cleanup datasets.py part1 * Cleanup dataset.py part1 !133 Updated validation for SentencePieceVocab.from_dataset * Added type_check for column names in SentencePieceVocab.from_dataset Rebase on master 181120 10:20 fix profiling temporary solution of catching stauts from Node.Build() !141 ToDevice Termination * ToDevice termination pylint fixes !137 Fix test team issues and add some corresponding tests * Fix test team issues and add some corresponding tests !138 TreeGetter changes to use OptPass * Getter changes to use OptPass (Zirui) Rebase fix !143 Fix cpplint issue * Fix cpplint issue pylint fixes in updated testcases !145 Reset exceptions testcase * reset exception test to master !146 Fix Check_Pylint Error * Fix Check_Pylint Error !147 fix android * fix android !148 ToDevice changes * Add ToDevice to the iterator List for cleanup at exit !149 Pylint issue * Add ToDevice to the iterator List for cleanup at exit !150 Pylint 2 * Add ToDevice to the iterator List for cleanup at exit !152 ExecutionTree error * ET destructor error !153 in getter_pass, only remove callback, without deleting map op * getter pass no longer removes map !156 early __del__ of iterator/to_device * early __del__ of iterator !155 Address review comments Eric 1 * Added one liner fix to validators.py * roll back signature fix * lint fix * Eric Address comments 2 * C++ lint fix * Address comments Eric 1 !158 Review rework for dataset bindings - part 1 * Reorder nodes repeat and rename * Review rework for dataset bindings - part 1 !154 Fixing minor problems in the comments (datasets.py, python_tree_consumer.cc, iterators_bindings.cc, and iterators.py) * Fixing minor problems in the comments (datasets.py, python_tree_consum… !157 add replace none * Add replace_none to datasets.py, address comments in tests Trying to resolve copy Override the deepcopy method of deviceop Create_ir_tree method Create_ir_tree method 2 Create_ir_tree method 2 del to_device if already exists del to_device if already exists cache getters shapes and types Added yolov3 relaxation, to be rolled back Get shapes and types together bypass yolo NumWorkers for MapOp revert Yolo revert Thor Print more info Debug code: Update LOG INFO to LOG ERROR do not remove epochctrl for getter pass Remove repeat(1) pritn batch size add log to tree_consumer and device_queue op Revert PR 8744 Signed-off-by: alex-yuyue <yue.yu1@huawei.com> __del__ toDEvice __del__ toDevice2 !165 add ifndef ENABLE_ANDROID to device queue print * Add ifndef ENABLE_ANDROID to device queue print revert some changes !166 getter: get_data_info * getter: get_data_info !168 add back tree print * revert info to warnning in one log * add back the missed print tree log Release GIL in GetDataInfo
5 years ago
added python api based on cpp api 1st draft of python iterator Added Cifar10 and Cifar100 pybind port Change pybind to use IR for Skip and Manifest Signed-off-by: alex-yuyue <yue.yu1@huawei.com> DatasetNode as a base for all IR nodes namespace change Fix the namespace issue and make ut tests work Signed-off-by: alex-yuyue <yue.yu1@huawei.com> Add VOCDataset !63 Added RandomDataset * Added RandomDataset add imagefolder ir Pybind switch: CelebA and UT !61 CLUE example with class definition * Merge branch 'python-api' of gitee.com:ezphlow/mindspore into clue_class_pybind * Passing testcases * Added CLUE, not working add ManifestDataset IR Signed-off-by: alex-yuyue <yue.yu1@huawei.com> Update Coco & VOC & TFReader, Update clang-format, Reorder datasets_binding !69 Add Generator and move c_dataset.Iterator to dataset.Iterator * Add GeneratorDataset to c_dataset * Add GeneratorDataset to c_dataset !67 Moving c_datasets and adding sampler wrapper * Need to add create() method in datasets.py * migration from c_dataset to dataset part 1 !71 Fix indent error * Fix indentation error !72 Fix c_api tests cases * Fix c_api tests cases !73 Added CSV Dataset * Added CSVDataset pybind switch: Take and CelebA fixes !75 move c_dataset functionality to datasets * Fixed existing testcases * Added working clue and imagefolder * Added sampler conversion from pybind * Added sampler creation !77 Add Python API tree * Python API tree add minddataset TextFileDataset pybind Rename to skip test_concat.py and test_minddataset_exception.py !80 Add batch IR to python-api branch, most test cases work * staging III * staging, add pybind Enable more c_api take and CelebA tests; delete util_c_api !84 Schema changes in datasets.py * Schema changes !85 Remove input_indexes from sub-classes * remove input_index from each subclass !83 Remove C datasets * Removed c_dataset package * Remove c_datasets !82 pybind switch: shuffle * pybind switch: shuffle !86 Add build_vocab * Add build_vocab Rebase with upstream/master _shuffle conflict BatchNode error !88 Fix rebase problem * fix rebase problem Enable more unit tests; code typo/nit fixes !91 Fix python vocag hang * Fix python vocab hang !89 Added BucketBatchByLength Pybind switch * Added BucketBatchByLength Update and enable more tet_c_api_*.py tests !95 Add BuildSentencePeiceVocab * - Add BuildSentencePeiceVocab !96 Fix more tests * - Fix some tests - Enable more test_c_api_* - Add syncwait !99 pybind switch for device op * pybind switch for device op !93 Add getters to python API * Add getters to python API !101 Validate tree, error if graph * - Add sync wait !103 TFrecord/Random Datasets schema problem * - TfRecord/Random schem aproblem !102 Added filter pybind switch * Added Filter pybind switch !104 Fix num_samples * - TfRecord/Random schem aproblem !105 Fix to_device hang * Fix to_device hang !94 Adds Cache support for CLUE dataset * Added cache for all dataset ops * format change * Added CLUE cache support * Added Cache conversion Add save pybind fix compile err init modify concat_node !107 Fix some tests cases * Fix tests cases Enable and fix more tests !109 pybind switch for get dataset size * pybind_get_dataset_size some check-code fixes for pylint, cpplint and clang-format !113 Add callback * revert * dataset_sz 1 line * fix typo * get callback to work !114 Make Android compile clean * Make Android Compile Clean Fix build issues due to rebase !115 Fix more tests * Fix tests cases * !93 Add getters to python API fix test_profiling.py !116 fix get dataset size * fix get dataset size !117 GetColumnNames pybind switch * Added GetColumnNames pybind switch code-check fixes: clangformat, cppcheck, cpplint, pylint Delete duplicate test_c_api_*.py files; more lint fixes !121 Fix cpp tests * Remove extra call to getNext in cpp tests !122 Fix Schema with Generator * Fix Schema with Generator fix some cases of csv & mindrecord !124 fix tfrecord get_dataset_size and add some UTs * fix tfrecord get dataset size and add some ut for get_dataset_size !125 getter separation * Getter separation !126 Fix sampler.GetNumSamples * Fix sampler.GetNumSampler !127 Assign runtime getter to each get function * Assign runtime getter to each get function Fix compile issues !128 Match master code * Match master code !129 Cleanup DeviceOp/save code * Cleanup ToDevice/Save code !130 Add cache fix * Added cache fix for map and image folder !132 Fix testing team issues * Pass queue_name from python to C++ * Add Schema.from_json !131 Fix Cache op issues and delete de_pipeline * Roll back C++ change * Removed de_pipeline and passing all cache tests. * fixed cache tests !134 Cleanup datasets.py part1 * Cleanup dataset.py part1 !133 Updated validation for SentencePieceVocab.from_dataset * Added type_check for column names in SentencePieceVocab.from_dataset Rebase on master 181120 10:20 fix profiling temporary solution of catching stauts from Node.Build() !141 ToDevice Termination * ToDevice termination pylint fixes !137 Fix test team issues and add some corresponding tests * Fix test team issues and add some corresponding tests !138 TreeGetter changes to use OptPass * Getter changes to use OptPass (Zirui) Rebase fix !143 Fix cpplint issue * Fix cpplint issue pylint fixes in updated testcases !145 Reset exceptions testcase * reset exception test to master !146 Fix Check_Pylint Error * Fix Check_Pylint Error !147 fix android * fix android !148 ToDevice changes * Add ToDevice to the iterator List for cleanup at exit !149 Pylint issue * Add ToDevice to the iterator List for cleanup at exit !150 Pylint 2 * Add ToDevice to the iterator List for cleanup at exit !152 ExecutionTree error * ET destructor error !153 in getter_pass, only remove callback, without deleting map op * getter pass no longer removes map !156 early __del__ of iterator/to_device * early __del__ of iterator !155 Address review comments Eric 1 * Added one liner fix to validators.py * roll back signature fix * lint fix * Eric Address comments 2 * C++ lint fix * Address comments Eric 1 !158 Review rework for dataset bindings - part 1 * Reorder nodes repeat and rename * Review rework for dataset bindings - part 1 !154 Fixing minor problems in the comments (datasets.py, python_tree_consumer.cc, iterators_bindings.cc, and iterators.py) * Fixing minor problems in the comments (datasets.py, python_tree_consum… !157 add replace none * Add replace_none to datasets.py, address comments in tests Trying to resolve copy Override the deepcopy method of deviceop Create_ir_tree method Create_ir_tree method 2 Create_ir_tree method 2 del to_device if already exists del to_device if already exists cache getters shapes and types Added yolov3 relaxation, to be rolled back Get shapes and types together bypass yolo NumWorkers for MapOp revert Yolo revert Thor Print more info Debug code: Update LOG INFO to LOG ERROR do not remove epochctrl for getter pass Remove repeat(1) pritn batch size add log to tree_consumer and device_queue op Revert PR 8744 Signed-off-by: alex-yuyue <yue.yu1@huawei.com> __del__ toDEvice __del__ toDevice2 !165 add ifndef ENABLE_ANDROID to device queue print * Add ifndef ENABLE_ANDROID to device queue print revert some changes !166 getter: get_data_info * getter: get_data_info !168 add back tree print * revert info to warnning in one log * add back the missed print tree log Release GIL in GetDataInfo
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. from util import save_and_check_dict
  18. # Note: Number of rows in test.data dataset: 12
  19. DATA_DIR = ["../data/dataset/testTFTestAllTypes/test.data"]
  20. GENERATE_GOLDEN = False
  21. def test_batch_01():
  22. """
  23. Test batch: batch_size>1, drop_remainder=True, no remainder exists
  24. """
  25. logger.info("test_batch_01")
  26. # define parameters
  27. batch_size = 2
  28. drop_remainder = True
  29. # apply dataset operations
  30. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  31. data1 = data1.batch(batch_size, drop_remainder)
  32. assert sum([1 for _ in data1]) == 6
  33. filename = "batch_01_result.npz"
  34. save_and_check_dict(data1, filename, generate_golden=GENERATE_GOLDEN)
  35. def test_batch_02():
  36. """
  37. Test batch: batch_size>1, drop_remainder=True, remainder exists
  38. """
  39. logger.info("test_batch_02")
  40. # define parameters
  41. batch_size = 5
  42. drop_remainder = True
  43. # apply dataset operations
  44. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  45. data1 = data1.batch(batch_size, drop_remainder=drop_remainder)
  46. assert sum([1 for _ in data1]) == 2
  47. filename = "batch_02_result.npz"
  48. save_and_check_dict(data1, filename, generate_golden=GENERATE_GOLDEN)
  49. def test_batch_03():
  50. """
  51. Test batch: batch_size>1, drop_remainder=False, no remainder exists
  52. """
  53. logger.info("test_batch_03")
  54. # define parameters
  55. batch_size = 3
  56. drop_remainder = False
  57. # apply dataset operations
  58. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  59. data1 = data1.batch(batch_size=batch_size, drop_remainder=drop_remainder)
  60. assert sum([1 for _ in data1]) == 4
  61. filename = "batch_03_result.npz"
  62. save_and_check_dict(data1, filename, generate_golden=GENERATE_GOLDEN)
  63. def test_batch_04():
  64. """
  65. Test batch: batch_size>1, drop_remainder=False, remainder exists
  66. """
  67. logger.info("test_batch_04")
  68. # define parameters
  69. batch_size = 7
  70. drop_remainder = False
  71. # apply dataset operations
  72. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  73. data1 = data1.batch(batch_size, drop_remainder)
  74. assert sum([1 for _ in data1]) == 2
  75. filename = "batch_04_result.npz"
  76. save_and_check_dict(data1, filename, generate_golden=GENERATE_GOLDEN)
  77. def test_batch_05():
  78. """
  79. Test batch: batch_size=1 (minimum valid size), drop_remainder default
  80. """
  81. logger.info("test_batch_05")
  82. # define parameters
  83. batch_size = 1
  84. # apply dataset operations
  85. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  86. data1 = data1.batch(batch_size)
  87. assert sum([1 for _ in data1]) == 12
  88. filename = "batch_05_result.npz"
  89. save_and_check_dict(data1, filename, generate_golden=GENERATE_GOLDEN)
  90. def test_batch_06():
  91. """
  92. Test batch: batch_size = number-of-rows-in-dataset, drop_remainder=True, reorder params
  93. """
  94. logger.info("test_batch_06")
  95. # define parameters
  96. batch_size = 12
  97. drop_remainder = False
  98. # apply dataset operations
  99. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  100. data1 = data1.batch(drop_remainder=drop_remainder, batch_size=batch_size)
  101. assert sum([1 for _ in data1]) == 1
  102. filename = "batch_06_result.npz"
  103. save_and_check_dict(data1, filename, generate_golden=GENERATE_GOLDEN)
  104. def test_batch_07():
  105. """
  106. Test batch: num_parallel_workers>1, drop_remainder=False, reorder params
  107. """
  108. logger.info("test_batch_07")
  109. # define parameters
  110. batch_size = 4
  111. drop_remainder = False
  112. num_parallel_workers = 2
  113. # apply dataset operations
  114. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  115. data1 = data1.batch(num_parallel_workers=num_parallel_workers, drop_remainder=drop_remainder,
  116. batch_size=batch_size)
  117. assert sum([1 for _ in data1]) == 3
  118. filename = "batch_07_result.npz"
  119. save_and_check_dict(data1, filename, generate_golden=GENERATE_GOLDEN)
  120. def test_batch_08():
  121. """
  122. Test batch: num_parallel_workers=1, drop_remainder default
  123. """
  124. logger.info("test_batch_08")
  125. # define parameters
  126. batch_size = 6
  127. num_parallel_workers = 1
  128. # apply dataset operations
  129. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  130. data1 = data1.batch(batch_size, num_parallel_workers=num_parallel_workers)
  131. assert sum([1 for _ in data1]) == 2
  132. filename = "batch_08_result.npz"
  133. save_and_check_dict(data1, filename, generate_golden=GENERATE_GOLDEN)
  134. def test_batch_09():
  135. """
  136. Test batch: batch_size > number-of-rows-in-dataset, drop_remainder=False
  137. """
  138. logger.info("test_batch_09")
  139. # define parameters
  140. batch_size = 13
  141. drop_remainder = False
  142. # apply dataset operations
  143. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  144. data1 = data1.batch(batch_size, drop_remainder=drop_remainder)
  145. assert sum([1 for _ in data1]) == 1
  146. filename = "batch_09_result.npz"
  147. save_and_check_dict(data1, filename, generate_golden=GENERATE_GOLDEN)
  148. def test_batch_10():
  149. """
  150. Test batch: batch_size > number-of-rows-in-dataset, drop_remainder=True
  151. """
  152. logger.info("test_batch_10")
  153. # define parameters
  154. batch_size = 99
  155. drop_remainder = True
  156. # apply dataset operations
  157. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  158. data1 = data1.batch(batch_size, drop_remainder=drop_remainder)
  159. assert sum([1 for _ in data1]) == 0
  160. filename = "batch_10_result.npz"
  161. save_and_check_dict(data1, filename, generate_golden=GENERATE_GOLDEN)
  162. def test_batch_11():
  163. """
  164. Test batch: batch_size=1 and dataset-size=1
  165. """
  166. logger.info("test_batch_11")
  167. # define parameters
  168. batch_size = 1
  169. # apply dataset operations
  170. # Use schema file with 1 row
  171. schema_file = "../data/dataset/testTFTestAllTypes/datasetSchema1Row.json"
  172. data1 = ds.TFRecordDataset(DATA_DIR, schema_file)
  173. data1 = data1.batch(batch_size)
  174. assert sum([1 for _ in data1]) == 1
  175. filename = "batch_11_result.npz"
  176. save_and_check_dict(data1, filename, generate_golden=GENERATE_GOLDEN)
  177. def test_batch_12():
  178. """
  179. Test batch: batch_size boolean value True, treated as valid value 1
  180. """
  181. logger.info("test_batch_12")
  182. # define parameters
  183. batch_size = True
  184. # apply dataset operations
  185. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  186. data1 = data1.batch(batch_size=batch_size)
  187. assert sum([1 for _ in data1]) == 12
  188. filename = "batch_12_result.npz"
  189. save_and_check_dict(data1, filename, generate_golden=GENERATE_GOLDEN)
  190. def test_batch_exception_01():
  191. """
  192. Test batch exception: num_parallel_workers=0
  193. """
  194. logger.info("test_batch_exception_01")
  195. # apply dataset operations
  196. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  197. try:
  198. data1 = data1.batch(batch_size=2, drop_remainder=True, num_parallel_workers=0)
  199. sum([1 for _ in data1])
  200. except Exception as e:
  201. logger.info("Got an exception in DE: {}".format(str(e)))
  202. assert "num_parallel_workers" in str(e)
  203. def test_batch_exception_02():
  204. """
  205. Test batch exception: num_parallel_workers<0
  206. """
  207. logger.info("test_batch_exception_02")
  208. # apply dataset operations
  209. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  210. try:
  211. data1 = data1.batch(3, drop_remainder=True, num_parallel_workers=-1)
  212. sum([1 for _ in data1])
  213. except Exception as e:
  214. logger.info("Got an exception in DE: {}".format(str(e)))
  215. assert "num_parallel_workers" in str(e)
  216. def test_batch_exception_03():
  217. """
  218. Test batch exception: batch_size=0
  219. """
  220. logger.info("test_batch_exception_03")
  221. # apply dataset operations
  222. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  223. try:
  224. data1 = data1.batch(batch_size=0)
  225. sum([1 for _ in data1])
  226. except Exception as e:
  227. logger.info("Got an exception in DE: {}".format(str(e)))
  228. assert "batch_size" in str(e)
  229. def test_batch_exception_04():
  230. """
  231. Test batch exception: batch_size<0
  232. """
  233. logger.info("test_batch_exception_04")
  234. # apply dataset operations
  235. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  236. try:
  237. data1 = data1.batch(batch_size=-1)
  238. sum([1 for _ in data1])
  239. except Exception as e:
  240. logger.info("Got an exception in DE: {}".format(str(e)))
  241. assert "batch_size" in str(e)
  242. def test_batch_exception_05():
  243. """
  244. Test batch exception: batch_size boolean value False, treated as invalid value 0
  245. """
  246. logger.info("test_batch_exception_05")
  247. # apply dataset operations
  248. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  249. try:
  250. data1 = data1.batch(batch_size=False)
  251. sum([1 for _ in data1])
  252. except Exception as e:
  253. logger.info("Got an exception in DE: {}".format(str(e)))
  254. assert "batch_size" in str(e)
  255. def test_batch_exception_07():
  256. """
  257. Test batch exception: drop_remainder wrong type
  258. """
  259. logger.info("test_batch_exception_07")
  260. # apply dataset operations
  261. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  262. try:
  263. data1 = data1.batch(3, drop_remainder=0)
  264. sum([1 for _ in data1])
  265. except Exception as e:
  266. logger.info("Got an exception in DE: {}".format(str(e)))
  267. assert "drop_remainder" in str(e)
  268. def test_batch_exception_08():
  269. """
  270. Test batch exception: num_parallel_workers wrong type
  271. """
  272. logger.info("test_batch_exception_08")
  273. # apply dataset operations
  274. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  275. try:
  276. data1 = data1.batch(3, drop_remainder=True, num_parallel_workers=False)
  277. sum([1 for _ in data1])
  278. except Exception as e:
  279. logger.info("Got an exception in DE: {}".format(str(e)))
  280. assert "num_parallel_workers" in str(e)
  281. def test_batch_exception_09():
  282. """
  283. Test batch exception: Missing mandatory batch_size
  284. """
  285. logger.info("test_batch_exception_09")
  286. # apply dataset operations
  287. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  288. try:
  289. data1 = data1.batch(drop_remainder=True, num_parallel_workers=4)
  290. sum([1 for _ in data1])
  291. except Exception as e:
  292. logger.info("Got an exception in DE: {}".format(str(e)))
  293. assert "batch_size" in str(e)
  294. def test_batch_exception_10():
  295. """
  296. Test batch exception: num_parallel_workers>>1
  297. """
  298. logger.info("test_batch_exception_10")
  299. # apply dataset operations
  300. data1 = ds.TFRecordDataset(DATA_DIR, shuffle=ds.Shuffle.FILES)
  301. try:
  302. data1 = data1.batch(batch_size=4, num_parallel_workers=8192)
  303. sum([1 for _ in data1])
  304. except Exception as e:
  305. logger.info("Got an exception in DE: {}".format(str(e)))
  306. assert "num_parallel_workers" in str(e)
  307. def test_batch_exception_11():
  308. """
  309. Test batch exception: wrong input order, num_parallel_workers wrongly used as drop_remainder
  310. """
  311. logger.info("test_batch_exception_11")
  312. # define parameters
  313. batch_size = 6
  314. num_parallel_workers = 1
  315. # apply dataset operations
  316. data1 = ds.TFRecordDataset(DATA_DIR)
  317. try:
  318. data1 = data1.batch(batch_size, num_parallel_workers)
  319. sum([1 for _ in data1])
  320. except Exception as e:
  321. logger.info("Got an exception in DE: {}".format(str(e)))
  322. assert "drop_remainder" in str(e)
  323. def test_batch_exception_12():
  324. """
  325. Test batch exception: wrong input order, drop_remainder wrongly used as batch_size
  326. """
  327. logger.info("test_batch_exception_12")
  328. # define parameters
  329. batch_size = 1
  330. drop_remainder = True
  331. # apply dataset operations
  332. data1 = ds.TFRecordDataset(DATA_DIR)
  333. try:
  334. data1 = data1.batch(drop_remainder, batch_size)
  335. sum([1 for _ in data1])
  336. except Exception as e:
  337. logger.info("Got an exception in DE: {}".format(str(e)))
  338. assert "drop_remainder" in str(e)
  339. def test_batch_exception_13():
  340. """
  341. Test batch exception: invalid input parameter
  342. """
  343. logger.info("test_batch_exception_13")
  344. # define parameters
  345. batch_size = 4
  346. # apply dataset operations
  347. data1 = ds.TFRecordDataset(DATA_DIR)
  348. try:
  349. data1 = data1.batch(batch_size, shard_id=1)
  350. sum([1 for _ in data1])
  351. except Exception as e:
  352. logger.info("Got an exception in DE: {}".format(str(e)))
  353. assert "shard_id" in str(e)
  354. def test_batch_exception_14():
  355. """
  356. Test per_batch_map and input column name
  357. """
  358. logger.info("test_batch_exception_14")
  359. batch_size = 2
  360. input_columns = ["num"]
  361. data1 = ds.TFRecordDataset(DATA_DIR)
  362. try:
  363. _ = data1.batch(batch_size=batch_size, input_columns=input_columns)
  364. except ValueError as e:
  365. assert "per_batch_map and input_columns need to be passed in together." in str(e)
  366. def test_batch_exception_15():
  367. """
  368. Test batch_size = int32 max value + 1
  369. """
  370. logger.info("test_batch_exception_15")
  371. batch_size = 2147483647 + 1
  372. input_columns = ["num"]
  373. data1 = ds.TFRecordDataset(DATA_DIR)
  374. err_msg = ""
  375. try:
  376. _ = data1.batch(batch_size=batch_size, input_columns=input_columns)
  377. except ValueError as e:
  378. err_msg = str(e)
  379. assert "batch_size is not within the required interval of (1 to 2147483647)" in err_msg
  380. if __name__ == '__main__':
  381. test_batch_01()
  382. test_batch_02()
  383. test_batch_03()
  384. test_batch_04()
  385. test_batch_05()
  386. test_batch_06()
  387. test_batch_07()
  388. test_batch_08()
  389. test_batch_09()
  390. test_batch_10()
  391. test_batch_11()
  392. test_batch_12()
  393. test_batch_exception_01()
  394. test_batch_exception_02()
  395. test_batch_exception_03()
  396. test_batch_exception_04()
  397. test_batch_exception_05()
  398. test_batch_exception_07()
  399. test_batch_exception_08()
  400. test_batch_exception_09()
  401. test_batch_exception_10()
  402. test_batch_exception_11()
  403. test_batch_exception_12()
  404. test_batch_exception_13()
  405. test_batch_exception_14()
  406. test_batch_exception_15()
  407. logger.info('\n')