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

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright 2021 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. """test dataset helper."""
  16. import pytest
  17. import numpy as np
  18. import mindspore.context as context
  19. from mindspore.train.dataset_helper import DatasetHelper
  20. from ...dataset_mock import MindData
  21. def get_dataset(batch_size=1):
  22. dataset_types = (np.int32, np.int32, np.int32, np.int32, np.int32, np.int32, np.int32)
  23. dataset_shapes = ((batch_size, 128), (batch_size, 128), (batch_size, 128), (batch_size, 1),
  24. (batch_size, 20), (batch_size, 20), (batch_size, 20))
  25. dataset = MindData(size=2, batch_size=batch_size, np_types=dataset_types,
  26. output_shapes=dataset_shapes, input_indexs=(0, 1))
  27. return dataset
  28. @pytest.mark.skipif('context.get_context("enable_ge")')
  29. def test_dataset_iter_ms_loop_sink():
  30. """
  31. Feature: Dataset iter loop sink.
  32. Description: Test dataset iter loop sink.
  33. Expectation: Dataset loop sink succeeds.
  34. """
  35. context.set_context(device_target='Ascend', mode=context.GRAPH_MODE)
  36. dataset = get_dataset(32)
  37. dataset_helper = DatasetHelper(dataset, dataset_sink_mode=True, sink_size=10)
  38. count = 0
  39. for _ in range(2):
  40. for inputs in dataset_helper:
  41. count += 1
  42. assert inputs == tuple()
  43. assert count == 2