test_seg_models.py 1.8 KB

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