test_clas_models.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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__ = []
  17. class TestClasModel(TestModel):
  18. DEFAULT_HW = (224, 224)
  19. def check_output(self, output, target):
  20. # target is the expected shape of the output
  21. self.check_output_equal(output.numpy().shape, target)
  22. def set_inputs(self):
  23. def _gen_data(specs):
  24. for spec in specs:
  25. c = spec.get('in_channels', 3)
  26. yield [self.get_randn_tensor(c)]
  27. self.inputs = _gen_data(self.specs)
  28. def set_targets(self):
  29. self.targets = [[self.DEFAULT_BATCH_SIZE, spec.get('num_classes', 2)]
  30. for spec in self.specs]
  31. class TestCondenseNetV2AModel(TestClasModel):
  32. MODEL_CLASS = paddlers.rs_models.clas.CondenseNetV2_A
  33. def set_specs(self):
  34. self.specs = [
  35. dict(in_channels=3, num_classes=2),
  36. dict(in_channels=10, num_classes=2),
  37. dict(in_channels=3, num_classes=100)
  38. ] # yapf: disable
  39. class TestCondenseNetV2BModel(TestClasModel):
  40. MODEL_CLASS = paddlers.rs_models.clas.CondenseNetV2_B
  41. def set_specs(self):
  42. self.specs = [
  43. dict(in_channels=3, num_classes=2),
  44. dict(in_channels=10, num_classes=2),
  45. dict(in_channels=3, num_classes=100)
  46. ] # yapf: disable
  47. class TestCondenseNetV2CModel(TestClasModel):
  48. MODEL_CLASS = paddlers.rs_models.clas.CondenseNetV2_C
  49. def set_specs(self):
  50. self.specs = [
  51. dict(in_channels=3, num_classes=2),
  52. dict(in_channels=10, num_classes=2),
  53. dict(in_channels=3, num_classes=100)
  54. ] # yapf: disable