test_seg_models.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 paddlers
  15. from rs_models.test_model import TestModel
  16. __all__ = ['TestFarSegModel']
  17. class TestSegModel(TestModel):
  18. DEFAULT_HW = (512, 512)
  19. def check_output(self, output, target):
  20. self.assertIsInstance(output, list)
  21. self.check_output_equal(len(output), len(target))
  22. for o, t in zip(output, target):
  23. o = o.numpy()
  24. self.check_output_equal(o.shape[0], t.shape[0])
  25. self.check_output_equal(len(o.shape), 4)
  26. self.check_output_equal(o.shape[2:], t.shape[2:])
  27. def set_inputs(self):
  28. def _gen_data(specs):
  29. for spec in specs:
  30. c = spec.get('in_channels', 3)
  31. yield self.get_randn_tensor(c)
  32. self.inputs = _gen_data(self.specs)
  33. def set_targets(self):
  34. def _gen_data(specs):
  35. for spec in specs:
  36. c = spec.get('num_classes', 2)
  37. yield [self.get_zeros_array(c)]
  38. self.targets = _gen_data(self.specs)
  39. class TestFarSegModel(TestSegModel):
  40. MODEL_CLASS = paddlers.rs_models.seg.FarSeg
  41. def set_specs(self):
  42. self.specs = [
  43. dict(), dict(num_classes=20), dict(encoder_pretrained=False)
  44. ]