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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. import numpy as np
  16. import mindspore.dataset as ds
  17. import mindspore.dataset.vision.c_transforms as C
  18. DATA_DIR = "../data/dataset/testPK/data"
  19. def test_offload():
  20. """
  21. Feature: test map offload flag.
  22. Description: Input is image dataset.
  23. Expectation: Output should be same with activated or deactivated offload.
  24. """
  25. # Dataset with offload activated.
  26. dataset_0 = ds.ImageFolderDataset(DATA_DIR)
  27. dataset_0 = dataset_0.map(operations=[C.Decode()], input_columns="image")
  28. dataset_0 = dataset_0.map(operations=[C.HWC2CHW()], input_columns="image", offload=True)
  29. dataset_0 = dataset_0.batch(8, drop_remainder=True)
  30. # Dataset with offload not activated.
  31. dataset_1 = ds.ImageFolderDataset(DATA_DIR)
  32. dataset_1 = dataset_1.map(operations=[C.Decode()], input_columns="image")
  33. dataset_1 = dataset_1.map(operations=[C.HWC2CHW()], input_columns="image")
  34. dataset_1 = dataset_1.batch(8, drop_remainder=True)
  35. for (img_0, _), (img_1, _) in zip(dataset_0.create_tuple_iterator(num_epochs=1, output_numpy=True),
  36. dataset_1.create_tuple_iterator(num_epochs=1, output_numpy=True)):
  37. np.testing.assert_array_equal(img_0, img_1)
  38. if __name__ == "__main__":
  39. test_offload()