test_seg_models.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. if isinstance(o, list):
  24. self.check_output(o, t)
  25. else:
  26. o = o.numpy()
  27. self.check_output_equal(o.shape, t.shape)
  28. def set_inputs(self):
  29. def _gen_data(specs):
  30. for spec in specs:
  31. c = spec.get('in_channels', 3)
  32. yield self.get_randn_tensor(c)
  33. self.inputs = _gen_data(self.specs)
  34. def set_targets(self):
  35. def _gen_data(specs):
  36. for spec in specs:
  37. c = spec.get('num_classes', 2)
  38. yield [self.get_zeros_array(c)]
  39. self.targets = _gen_data(self.specs)
  40. class TestFarSegModel(TestSegModel):
  41. MODEL_CLASS = paddlers.rs_models.seg.FarSeg
  42. def set_specs(self):
  43. self.specs = [
  44. dict(), dict(
  45. in_channels=6, num_classes=10), dict(
  46. backbone='resnet18', backbone_pretrained=False), dict(
  47. fpn_out_channels=128,
  48. fsr_out_channels=64,
  49. decoder_out_channels=32), dict(scale_aware_proj=False)
  50. ]
  51. def set_targets(self):
  52. self.targets = [[self.get_zeros_array(16)], [self.get_zeros_array(10)],
  53. [self.get_zeros_array(16)], [self.get_zeros_array(16)],
  54. [self.get_zeros_array(16)]]