def save_model(keras_model, path, conda_env=None, mlflow_model=None, custom_objects=None, keras_module=None, signature: ModelSignature=None, input_example: ModelInputExample=None, **kwargs):
    '\n    Save a Keras model to a path on the local file system.\n\n    :param keras_model: Keras model to be saved.\n    :param path: Local path where the model is to be saved.\n    :param conda_env: Either a dictionary representation of a Conda environment or the path to a\n                      Conda environment yaml file. If provided, this decsribes the environment\n                      this model should be run in. At minimum, it should specify the\n                      dependencies contained in :func:`get_default_conda_env()`. If\n                      ``None``, the default :func:`get_default_conda_env()` environment is\n                      added to the model. The following is an *example* dictionary\n                      representation of a Conda environment::\n\n                        {\n                            \'name\': \'mlflow-env\',\n                            \'channels\': [\'defaults\'],\n                            \'dependencies\': [\n                                \'python=3.7.0\',\n                                \'keras=2.2.4\',\n                                \'tensorflow=1.8.0\'\n                            ]\n                        }\n    :param mlflow_model: MLflow model config this flavor is being added to.\n    :param custom_objects: A Keras ``custom_objects`` dictionary mapping names (strings) to\n                           custom classes or functions associated with the Keras model. MLflow saves\n                           these custom layers using CloudPickle and restores them automatically\n                           when the model is loaded with :py:func:`mlflow.keras.load_model` and\n                           :py:func:`mlflow.pyfunc.load_model`.\n    :param keras_module: Keras module to be used to save / load the model\n                         (``keras`` or ``tf.keras``). If not provided, MLflow will\n                         attempt to infer the Keras module based on the given model.\n    :param kwargs: kwargs to pass to ``keras_model.save`` method.\n\n    :param signature: (Experimental) :py:class:`ModelSignature <mlflow.models.ModelSignature>`\n                      describes model input and output :py:class:`Schema <mlflow.types.Schema>`.\n                      The model signature can be :py:func:`inferred <mlflow.models.infer_signature>`\n                      from datasets with valid model input (e.g. the training dataset with target\n                      column omitted) and valid model output (e.g. model predictions generated on\n                      the training dataset), for example:\n\n                      .. code-block:: python\n\n                        from mlflow.models.signature import infer_signature\n                        train = df.drop_column("target_label")\n                        predictions = ... # compute model predictions\n                        signature = infer_signature(train, predictions)\n    :param input_example: (Experimental) Input example provides one or several instances of valid\n                          model input. The example can be used as a hint of what data to feed the\n                          model. The given example will be converted to a Pandas DataFrame and then\n                          serialized to json using the Pandas split-oriented format. Bytes are\n                          base64-encoded.\n\n    .. code-block:: python\n        :caption: Example\n\n        import mlflow\n        # Build, compile, and train your model\n        keras_model = ...\n        keras_model_path = ...\n        keras_model.compile(optimizer="rmsprop", loss="mse", metrics=["accuracy"])\n        results = keras_model.fit(\n            x_train, y_train, epochs=20, batch_size = 128, validation_data=(x_val, y_val))\n        # Save the model as an MLflow Model\n        mlflow.keras.save_model(keras_model, keras_model_path)\n    '
    if (keras_module is None):

        def _is_plain_keras(model):
            try:
                import keras.engine.network
                return isinstance(model, keras.engine.network.Network)
            except ImportError:
                return False

        def _is_tf_keras(model):
            try:
                import tensorflow.keras.models
                return isinstance(model, tensorflow.keras.models.Model)
            except ImportError:
                return False
        if _is_plain_keras(keras_model):
            keras_module = importlib.import_module('keras')
        elif _is_tf_keras(keras_model):
            keras_module = importlib.import_module('tensorflow.keras')
        else:
            raise MlflowException("Unable to infer keras module from the model, please specify which keras module ('keras' or 'tensorflow.keras') is to be used to save and load the model.")
    elif (type(keras_module) == str):
        keras_module = importlib.import_module(keras_module)
    path = os.path.abspath(path)
    if os.path.exists(path):
        raise MlflowException("Path '{}' already exists".format(path))
    data_subpath = 'data'
    data_path = os.path.join(path, data_subpath)
    os.makedirs(data_path)
    if (mlflow_model is None):
        mlflow_model = Model()
    if (signature is not None):
        mlflow_model.signature = signature
    if (input_example is not None):
        _save_example(mlflow_model, input_example, path)
    if (custom_objects is not None):
        _save_custom_objects(data_path, custom_objects)
    with open(os.path.join(data_path, _KERAS_MODULE_SPEC_PATH), 'w') as f:
        f.write(keras_module.__name__)
    model_subpath = os.path.join(data_subpath, _MODEL_SAVE_PATH)
    model_path = os.path.join(path, model_subpath)
    if path.startswith('/dbfs/'):
        with tempfile.NamedTemporaryFile(suffix='.h5') as f:
            keras_model.save(f.name, **kwargs)
            f.flush()
            shutil.copyfile(src=f.name, dst=model_path)
    else:
        keras_model.save(model_path, **kwargs)
    mlflow_model.add_flavor(FLAVOR_NAME, keras_module=keras_module.__name__, keras_version=keras_module.__version__, data=data_subpath)
    if (conda_env is None):
        conda_env = get_default_conda_env(include_cloudpickle=(custom_objects is not None), keras_module=keras_module)
    elif (not isinstance(conda_env, dict)):
        with open(conda_env, 'r') as f:
            conda_env = yaml.safe_load(f)
    with open(os.path.join(path, _CONDA_ENV_SUBPATH), 'w') as f:
        yaml.safe_dump(conda_env, stream=f, default_flow_style=False)
    pyfunc.add_to_model(mlflow_model, loader_module='mlflow.keras', data=data_subpath, env=_CONDA_ENV_SUBPATH)
    mlflow_model.save(os.path.join(path, 'MLmodel'))
Save a Keras model to a path on the local file system.

:param keras_model: Keras model to be saved.
:param path: Local path where the model is to be saved.
:param conda_env: Either a dictionary representation of a Conda environment or the path to a
                  Conda environment yaml file. If provided, this decsribes the environment
                  this model should be run in. At minimum, it should specify the
                  dependencies contained in :func:`get_default_conda_env()`. If
                  ``None``, the default :func:`get_default_conda_env()` environment is
                  added to the model. The following is an *example* dictionary
                  representation of a Conda environment::

                    {
                        'name': 'mlflow-env',
                        'channels': ['defaults'],
                        'dependencies': [
                            'python=3.7.0',
                            'keras=2.2.4',
                            'tensorflow=1.8.0'
                        ]
                    }
:param mlflow_model: MLflow model config this flavor is being added to.
:param custom_objects: A Keras ``custom_objects`` dictionary mapping names (strings) to
                       custom classes or functions associated with the Keras model. MLflow saves
                       these custom layers using CloudPickle and restores them automatically
                       when the model is loaded with :py:func:`mlflow.keras.load_model` and
                       :py:func:`mlflow.pyfunc.load_model`.
:param keras_module: Keras module to be used to save / load the model
                     (``keras`` or ``tf.keras``). If not provided, MLflow will
                     attempt to infer the Keras module based on the given model.
:param kwargs: kwargs to pass to ``keras_model.save`` method.

:param signature: (Experimental) :py:class:`ModelSignature <mlflow.models.ModelSignature>`
                  describes model input and output :py:class:`Schema <mlflow.types.Schema>`.
                  The model signature can be :py:func:`inferred <mlflow.models.infer_signature>`
                  from datasets with valid model input (e.g. the training dataset with target
                  column omitted) and valid model output (e.g. model predictions generated on
                  the training dataset), for example:

                  .. code-block:: python

                    from mlflow.models.signature import infer_signature
                    train = df.drop_column("target_label")
                    predictions = ... # compute model predictions
                    signature = infer_signature(train, predictions)
:param input_example: (Experimental) Input example provides one or several instances of valid
                      model input. The example can be used as a hint of what data to feed the
                      model. The given example will be converted to a Pandas DataFrame and then
                      serialized to json using the Pandas split-oriented format. Bytes are
                      base64-encoded.

.. code-block:: python
    :caption: Example

    import mlflow
    # Build, compile, and train your model
    keras_model = ...
    keras_model_path = ...
    keras_model.compile(optimizer="rmsprop", loss="mse", metrics=["accuracy"])
    results = keras_model.fit(
        x_train, y_train, epochs=20, batch_size = 128, validation_data=(x_val, y_val))
    # Save the model as an MLflow Model
    mlflow.keras.save_model(keras_model, keras_model_path)
def save_model(keras_model, path, conda_env=None, mlflow_model=None, custom_objects=None, keras_module=None, signature: ModelSignature=None, input_example: ModelInputExample=None, **kwargs):
    '\n    Save a Keras model to a path on the local file system.\n\n    :param keras_model: Keras model to be saved.\n    :param path: Local path where the model is to be saved.\n    :param conda_env: Either a dictionary representation of a Conda environment or the path to a\n                      Conda environment yaml file. If provided, this decsribes the environment\n                      this model should be run in. At minimum, it should specify the\n                      dependencies contained in :func:`get_default_conda_env()`. If\n                      ``None``, the default :func:`get_default_conda_env()` environment is\n                      added to the model. The following is an *example* dictionary\n                      representation of a Conda environment::\n\n                        {\n                            \'name\': \'mlflow-env\',\n                            \'channels\': [\'defaults\'],\n                            \'dependencies\': [\n                                \'python=3.7.0\',\n                                \'keras=2.2.4\',\n                                \'tensorflow=1.8.0\'\n                            ]\n                        }\n    :param mlflow_model: MLflow model config this flavor is being added to.\n    :param custom_objects: A Keras ``custom_objects`` dictionary mapping names (strings) to\n                           custom classes or functions associated with the Keras model. MLflow saves\n                           these custom layers using CloudPickle and restores them automatically\n                           when the model is loaded with :py:func:`mlflow.keras.load_model` and\n                           :py:func:`mlflow.pyfunc.load_model`.\n    :param keras_module: Keras module to be used to save / load the model\n                         (``keras`` or ``tf.keras``). If not provided, MLflow will\n                         attempt to infer the Keras module based on the given model.\n    :param kwargs: kwargs to pass to ``keras_model.save`` method.\n\n    :param signature: (Experimental) :py:class:`ModelSignature <mlflow.models.ModelSignature>`\n                      describes model input and output :py:class:`Schema <mlflow.types.Schema>`.\n                      The model signature can be :py:func:`inferred <mlflow.models.infer_signature>`\n                      from datasets with valid model input (e.g. the training dataset with target\n                      column omitted) and valid model output (e.g. model predictions generated on\n                      the training dataset), for example:\n\n                      .. code-block:: python\n\n                        from mlflow.models.signature import infer_signature\n                        train = df.drop_column("target_label")\n                        predictions = ... # compute model predictions\n                        signature = infer_signature(train, predictions)\n    :param input_example: (Experimental) Input example provides one or several instances of valid\n                          model input. The example can be used as a hint of what data to feed the\n                          model. The given example will be converted to a Pandas DataFrame and then\n                          serialized to json using the Pandas split-oriented format. Bytes are\n                          base64-encoded.\n\n    .. code-block:: python\n        :caption: Example\n\n        import mlflow\n        # Build, compile, and train your model\n        keras_model = ...\n        keras_model_path = ...\n        keras_model.compile(optimizer="rmsprop", loss="mse", metrics=["accuracy"])\n        results = keras_model.fit(\n            x_train, y_train, epochs=20, batch_size = 128, validation_data=(x_val, y_val))\n        # Save the model as an MLflow Model\n        mlflow.keras.save_model(keras_model, keras_model_path)\n    '
    if (keras_module is None):

        def _is_plain_keras(model):
            try:
                import keras.engine.network
                return isinstance(model, keras.engine.network.Network)
            except ImportError:
                return False

        def _is_tf_keras(model):
            try:
                import tensorflow.keras.models
                return isinstance(model, tensorflow.keras.models.Model)
            except ImportError:
                return False
        if _is_plain_keras(keras_model):
            keras_module = importlib.import_module('keras')
        elif _is_tf_keras(keras_model):
            keras_module = importlib.import_module('tensorflow.keras')
        else:
            raise MlflowException("Unable to infer keras module from the model, please specify which keras module ('keras' or 'tensorflow.keras') is to be used to save and load the model.")
    elif (type(keras_module) == str):
        keras_module = importlib.import_module(keras_module)
    path = os.path.abspath(path)
    if os.path.exists(path):
        raise MlflowException("Path '{}' already exists".format(path))
    data_subpath = 'data'
    data_path = os.path.join(path, data_subpath)
    os.makedirs(data_path)
    if (mlflow_model is None):
        mlflow_model = Model()
    if (signature is not None):
        mlflow_model.signature = signature
    if (input_example is not None):
        _save_example(mlflow_model, input_example, path)
    if (custom_objects is not None):
        _save_custom_objects(data_path, custom_objects)
    with open(os.path.join(data_path, _KERAS_MODULE_SPEC_PATH), 'w') as f:
        f.write(keras_module.__name__)
    model_subpath = os.path.join(data_subpath, _MODEL_SAVE_PATH)
    model_path = os.path.join(path, model_subpath)
    if path.startswith('/dbfs/'):
        with tempfile.NamedTemporaryFile(suffix='.h5') as f:
            keras_model.save(f.name, **kwargs)
            f.flush()
            shutil.copyfile(src=f.name, dst=model_path)
    else:
        keras_model.save(model_path, **kwargs)
    mlflow_model.add_flavor(FLAVOR_NAME, keras_module=keras_module.__name__, keras_version=keras_module.__version__, data=data_subpath)
    if (conda_env is None):
        conda_env = get_default_conda_env(include_cloudpickle=(custom_objects is not None), keras_module=keras_module)
    elif (not isinstance(conda_env, dict)):
        with open(conda_env, 'r') as f:
            conda_env = yaml.safe_load(f)
    with open(os.path.join(path, _CONDA_ENV_SUBPATH), 'w') as f:
        yaml.safe_dump(conda_env, stream=f, default_flow_style=False)
    pyfunc.add_to_model(mlflow_model, loader_module='mlflow.keras', data=data_subpath, env=_CONDA_ENV_SUBPATH)
    mlflow_model.save(os.path.join(path, 'MLmodel'))