예제 #1
0
    def test_SameOperatorContainer_op_weights_str(self):
        class TestOperator(ops.Operator):
            def process_input_image(self, image):
                pass

        def get_op(name, score_weight):
            return TestOperator(score_weight=score_weight)

        names = [str(idx) for idx in range(3)]
        op_weights_config = ("sum", "mean")

        desireds = (float(len(names)), 1.0)
        for op_weights, desired in zip(op_weights_config, desireds):
            same_operator_container = ops.SameOperatorContainer(
                names, get_op, op_weights=op_weights)
            actual = sum([
                getattr(same_operator_container, name).score_weight
                for name in names
            ])
            self.assertFloatAlmostEqual(actual, desired)

        with self.assertRaises(ValueError):
            ops.SameOperatorContainer(
                names,
                get_op,
                op_weights="invalid",
            )
예제 #2
0
    def test_SameOperatorContainer(self):
        class TestOperator(ops.Operator):
            def process_input_image(self, image):
                pass

        def get_op(name, score_weight):
            return TestOperator()

        names = [str(idx) for idx in range(3)]
        same_operator_container = ops.SameOperatorContainer(names, get_op)

        for name in names:
            op = getattr(same_operator_container, name)
            self.assertIsInstance(op, TestOperator)
예제 #3
0
    def test_SameOperatorContainer_op_weights_seq(self):
        class TestOperator(ops.Operator):
            def process_input_image(self, image):
                pass

        def get_op(name, score_weight):
            return TestOperator(score_weight=score_weight)

        names, op_weights = zip(*[(str(idx), float(idx) + 1.0)
                                  for idx in range(3)])

        same_operator_container = ops.SameOperatorContainer(
            names, get_op, op_weights=op_weights)

        for name, score_weight in zip(names, op_weights):
            actual = getattr(same_operator_container, name).score_weight
            desired = score_weight
            self.assertFloatAlmostEqual(actual, desired)