Exemplo n.º 1
0
    def test_pipeline_classifier_set_training_inputs(self):
        builder = self.create_base_builder()
        builder.spec.isUpdatable = False
        training_input = [("input", datatypes.Array(3)), ("target", "String")]

        # fails due to missing sub-models
        p_classifier = PipelineClassifier(self.input_features,
                                          self.output_names)
        p_classifier.set_training_input(training_input)
        with self.assertRaises(ValueError):
            p_classifier.make_updatable()
        self.assertEqual(p_classifier.spec.isUpdatable, False)

        # fails due to sub-model being not updatable
        p_classifier.add_model(builder.spec)
        with self.assertRaises(ValueError):
            p_classifier.make_updatable()
        self.assertEqual(p_classifier.spec.isUpdatable, False)

        builder.spec.isUpdatable = True
        p_classifier.add_model(builder.spec)

        self.assertEqual(p_classifier.spec.isUpdatable, False)
        p_classifier.make_updatable()
        self.assertEqual(p_classifier.spec.isUpdatable, True)
        self.assertEqual(p_classifier.spec.description.trainingInput[0].name,
                         "input")
        self.assertEqual(
            p_classifier.spec.description.trainingInput[0].type.WhichOneof(
                "Type"),
            "multiArrayType",
        )
        self.assertEqual(p_classifier.spec.description.trainingInput[1].name,
                         "target")
        self.assertEqual(
            p_classifier.spec.description.trainingInput[1].type.WhichOneof(
                "Type"),
            "stringType",
        )

        # fails since once updatable does not allow adding new models
        with self.assertRaises(ValueError):
            p_classifier.add_model(builder.spec)
        self.assertEqual(p_classifier.spec.isUpdatable, True)
Exemplo n.º 2
0
    def test_pipeline_classifier_make_updatable(self):
        builder = self.create_base_builder()
        builder.spec.isUpdatable = False
        training_input = [('input', datatypes.Array(3)), ('target', 'String')]

        # fails due to missing sub-models
        p_classifier = PipelineClassifier(self.input_features,
                                          self.output_names,
                                          training_features=training_input)
        with self.assertRaises(ValueError):
            p_classifier.make_updatable()
        self.assertEqual(p_classifier.spec.isUpdatable, False)

        # fails due to sub-model being not updatable
        p_classifier.add_model(builder.spec)
        with self.assertRaises(ValueError):
            p_classifier.make_updatable()
        self.assertEqual(p_classifier.spec.isUpdatable, False)

        builder.spec.isUpdatable = True
        p_classifier.add_model(builder.spec)

        self.assertEqual(p_classifier.spec.isUpdatable, False)
        p_classifier.make_updatable()
        self.assertEqual(p_classifier.spec.isUpdatable, True)
        self.assertEqual(p_classifier.spec.description.trainingInput[0].name,
                         'input')
        self.assertEqual(
            p_classifier.spec.description.trainingInput[0].type.WhichOneof(
                'Type'), 'multiArrayType')
        self.assertEqual(p_classifier.spec.description.trainingInput[1].name,
                         'target')
        self.assertEqual(
            p_classifier.spec.description.trainingInput[1].type.WhichOneof(
                'Type'), 'stringType')

        # fails since once updatable does not allow adding new models
        with self.assertRaises(ValueError):
            p_classifier.add_model(builder.spec)
        self.assertEqual(p_classifier.spec.isUpdatable, True)