test_functions.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. class TestMatchHistograms(CpuCommonTest):
  19. def setUp(self):
  20. self.inputs = [
  21. build_input_from_file(
  22. 'data/ssmt/test_mixed_binary.txt', prefix='./data/ssmt')
  23. ]
  24. def test_output_shape(self):
  25. decoder = T.DecodeImg()
  26. for input in copy.deepcopy(self.inputs):
  27. for sample in input:
  28. sample = decoder(sample)
  29. im_out = T.functions.match_histograms(sample['image'],
  30. sample['image2'])
  31. self.check_output_equal(im_out.shape, sample['image2'].shape)
  32. im_out = T.functions.match_histograms(sample['image2'],
  33. sample['image'])
  34. self.check_output_equal(im_out.shape, sample['image'].shape)
  35. class TestMatchByRegression(CpuCommonTest):
  36. def setUp(self):
  37. self.inputs = [
  38. build_input_from_file(
  39. 'data/ssmt/test_mixed_binary.txt', prefix='./data/ssmt')
  40. ]
  41. def test_output_shape(self):
  42. decoder = T.DecodeImg()
  43. for input in copy.deepcopy(self.inputs):
  44. for sample in input:
  45. sample = decoder(sample)
  46. im_out = T.functions.match_by_regression(sample['image'],
  47. sample['image2'])
  48. self.check_output_equal(im_out.shape, sample['image2'].shape)
  49. im_out = T.functions.match_by_regression(sample['image2'],
  50. sample['image'])
  51. self.check_output_equal(im_out.shape, sample['image'].shape)