test_functions.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
  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. import copy
  15. import paddlers.transforms as T
  16. from testing_utils import CpuCommonTest
  17. from data import build_input_from_file
  18. __all__ = ['TestMatchHistograms', 'TestMatchByRegression']
  19. class TestMatchHistograms(CpuCommonTest):
  20. def setUp(self):
  21. self.inputs = [
  22. build_input_from_file(
  23. "data/ssmt/test_mixed_binary.txt", prefix="./data/ssmt")
  24. ]
  25. def test_output_shape(self):
  26. decoder = T.DecodeImg()
  27. for input in copy.deepcopy(self.inputs):
  28. for sample in input:
  29. sample = decoder(sample)
  30. im_out = T.functions.match_histograms(sample['image'],
  31. sample['image2'])
  32. self.check_output_equal(im_out.shape, sample['image2'].shape)
  33. im_out = T.functions.match_histograms(sample['image2'],
  34. sample['image'])
  35. self.check_output_equal(im_out.shape, sample['image'].shape)
  36. class TestMatchByRegression(CpuCommonTest):
  37. def setUp(self):
  38. self.inputs = [
  39. build_input_from_file(
  40. "data/ssmt/test_mixed_binary.txt", prefix="./data/ssmt")
  41. ]
  42. def test_output_shape(self):
  43. decoder = T.DecodeImg()
  44. for input in copy.deepcopy(self.inputs):
  45. for sample in input:
  46. sample = decoder(sample)
  47. im_out = T.functions.match_by_regression(sample['image'],
  48. sample['image2'])
  49. self.check_output_equal(im_out.shape, sample['image2'].shape)
  50. im_out = T.functions.match_by_regression(sample['image2'],
  51. sample['image'])
  52. self.check_output_equal(im_out.shape, sample['image'].shape)