Parcourir la source

Add tool unittests

Bobholamovic il y a 2 ans
Parent
commit
04f86364c9

+ 13 - 0
tests/deploy/test_export.py

@@ -0,0 +1,13 @@
+# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.

+ 13 - 0
tests/deploy/test_predict.py

@@ -0,0 +1,13 @@
+# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.

+ 77 - 72
tests/rs_models/test_model.py

@@ -15,75 +15,80 @@
 import paddle
 import numpy as np
 
-from test_utils import CommonTest
-
-
-class TestModel(CommonTest):
-    MODEL_CLASS = None
-    DEFAULT_HW = (256, 256)
-    DEFAULT_BATCH_SIZE = 2
-
-    def setUp(self):
-        self.set_specs()
-        self.set_inputs()
-        self.set_targets()
-        self.set_models()
-
-    def test_forward(self):
-        for i, (input, model, target
-                ) in enumerate(zip(self.inputs, self.models, self.targets)):
-            with self.subTest(i=i):
-                output = model(input)
-                self.check_output(output, target)
-
-    def check_output(self, output, target):
-        pass
-
-    def set_specs(self):
-        self.specs = []
-
-    def set_models(self):
-        self.models = (self.build_model(spec) for spec in self.specs)
-
-    def set_inputs(self):
-        self.inputs = []
-
-    def set_targets(self):
-        self.targets = []
-
-    def build_model(self, spec):
-        if '_phase' in spec:
-            phase = spec.pop('_phase')
-        else:
-            phase = 'train'
-        if '_stop_grad' in spec:
-            stop_grad = spec.pop('_stop_grad')
-        else:
-            stop_grad = False
-
-        model = self.MODEL_CLASS(**spec)
-
-        if phase == 'train':
-            model.train()
-        elif phase == 'eval':
-            model.eval()
-            if stop_grad:
-                for p in model.parameters():
-                    p.stop_gradient = True
-
-        return model
-
-    def get_shape(self, c, b=None, h=None, w=None):
-        if h is None or w is None:
-            h, w = self.DEFAULT_HW
-        if b is None:
-            b = self.DEFAULT_BATCH_SIZE
-        return (b, c, h, w)
-
-    def get_zeros_array(self, c, b=None, h=None, w=None):
-        shape = self.get_shape(c, b, h, w)
-        return np.zeros(shape)
-
-    def get_randn_tensor(self, c, b=None, h=None, w=None):
-        shape = self.get_shape(c, b, h, w)
-        return paddle.randn(shape)
+from testing_utils import CommonTest
+
+
+class _TestModelNamespace:
+    class TestModel(CommonTest):
+        MODEL_CLASS = None
+        DEFAULT_HW = (256, 256)
+        DEFAULT_BATCH_SIZE = 2
+
+        def setUp(self):
+            self.set_specs()
+            self.set_inputs()
+            self.set_targets()
+            self.set_models()
+
+        def test_forward(self):
+            for i, (
+                    input, model, target
+            ) in enumerate(zip(self.inputs, self.models, self.targets)):
+                with self.subTest(i=i):
+                    output = model(input)
+                    self.check_output(output, target)
+
+        def check_output(self, output, target):
+            pass
+
+        def set_specs(self):
+            self.specs = []
+
+        def set_models(self):
+            self.models = (self.build_model(spec) for spec in self.specs)
+
+        def set_inputs(self):
+            self.inputs = []
+
+        def set_targets(self):
+            self.targets = []
+
+        def build_model(self, spec):
+            if '_phase' in spec:
+                phase = spec.pop('_phase')
+            else:
+                phase = 'train'
+            if '_stop_grad' in spec:
+                stop_grad = spec.pop('_stop_grad')
+            else:
+                stop_grad = False
+
+            model = self.MODEL_CLASS(**spec)
+
+            if phase == 'train':
+                model.train()
+            elif phase == 'eval':
+                model.eval()
+                if stop_grad:
+                    for p in model.parameters():
+                        p.stop_gradient = True
+
+            return model
+
+        def get_shape(self, c, b=None, h=None, w=None):
+            if h is None or w is None:
+                h, w = self.DEFAULT_HW
+            if b is None:
+                b = self.DEFAULT_BATCH_SIZE
+            return (b, c, h, w)
+
+        def get_zeros_array(self, c, b=None, h=None, w=None):
+            shape = self.get_shape(c, b, h, w)
+            return np.zeros(shape)
+
+        def get_randn_tensor(self, c, b=None, h=None, w=None):
+            shape = self.get_shape(c, b, h, w)
+            return paddle.randn(shape)
+
+
+TestModel = _TestModelNamespace.TestModel

+ 0 - 0
tests/tools/test_coco2mask.py


+ 0 - 0
tests/tools/test_geojson2mask.py


+ 0 - 0
tests/tools/test_match.py


+ 0 - 0
tests/tools/test_oif.py


+ 0 - 0
tests/tools/test_pca.py


+ 0 - 0
tests/tools/test_raster2vector.py


+ 0 - 0
tests/tools/test_split.py