Example #1
0
    def test_rename_input(self):
        utils.rename_feature(self.spec,
                             "feature_1",
                             "renamed_feature",
                             rename_inputs=True)
        model = MLModel(self.spec)

        package = tempfile.TemporaryDirectory(suffix=".mlpackage")
        package.cleanup()

        model.save(package.name)
        loaded_model = MLModel(package.name)

        if utils._macos_version() >= (12, 0):
            preds = loaded_model.predict({
                "renamed_feature": 1.0,
                "feature_2": 1.0
            })
            assert preds is not None
            assert preds["output"] == 3.1

        # reset the spec for next run
        utils.rename_feature(self.spec,
                             "renamed_feature",
                             "feature_1",
                             rename_inputs=True)

        # cleanup
        _remove_path(package.name)
## Used to change the name of input and output to give a good name.

from coremltools import utils

spec = utils.load_spec("FacialExpressionAnalysis.mlmodel")
##utils.rename_feature(spec,"UglyInputName","image",rename_outputs = True)
utils.rename_feature(spec,
                     "input.1",
                     "data",
                     rename_inputs=True,
                     rename_outputs=False)
#utils.rename_feature(spec,"198","result",rename_inputs = False,rename_outputs = True)
utils.save_spec(spec, "FacialExpressionAnalysis.mlmodel")