test_seg_models.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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, t.shape)
  25. def set_inputs(self):
  26. def _gen_data(specs):
  27. for spec in specs:
  28. c = spec.get('in_channels', 3)
  29. yield self.get_randn_tensor(c)
  30. self.inputs = _gen_data(self.specs)
  31. def set_targets(self):
  32. def _gen_data(specs):
  33. for spec in specs:
  34. c = spec.get('num_classes', 2)
  35. yield [self.get_zeros_array(c)]
  36. self.targets = _gen_data(self.specs)
  37. class TestFarSegModel(TestSegModel):
  38. MODEL_CLASS = paddlers.rs_models.seg.FarSeg
  39. def set_specs(self):
  40. self.specs = [
  41. dict(), dict(num_classes=20), dict(encoder_pretrained=False)
  42. ]
  43. def set_targets(self):
  44. self.targets = [[self.get_zeros_array(16)], [self.get_zeros_array(20)],
  45. [self.get_zeros_array(16)]]