mlflow.models
The mlflow.models
module provides an API for saving machine learning models in
“flavors” that can be understood by different downstream tools.
The built-in flavors are:
For details, see MLflow Models.
-
class
mlflow.models.
FlavorBackend
(config, **kwargs) Bases:
object
Abstract class for Flavor Backend. This class defines the API interface for local model deployment of MLflow model flavors.
-
can_build_image
() Returns: True if this flavor has a build_image method defined for building a docker container capable of serving the model, False otherwise.
-
can_score_model
() Check whether this flavor backend can be deployed in the current environment.
Returns: True if this flavor backend can be applied int he current environment.
-
predict
(model_uri, input_path, output_path, content_type, json_format) Generate predictions using a saved MLflow model referenced by the given URI. Input and output are read from and written to a file or stdin / stdout.
Parameters: - model_uri – URI pointing to the MLflow model to be used for scoring.
- input_path – Path to the file with input data. If not specified, data is read from stdin.
- output_path – Path to the file with output predictions. If not specified, data is written to stdout.
- content_type – Specifies the input format. Can be one of {‘json’, ‘csv’}
- json_format – Only applies if content_type == ‘json’. Specifies how is the input data
encoded in json. Can be one of {‘split’, ‘records’} mirroring the
behavior of Pandas orient attribute. The default is ‘split’ which
expects dict like data:
{'index' -> [index], 'columns' -> [columns], 'data' -> [values]}
, where index is optional. For more information see “https://pandas.pydata.org/ pandas-docs/stable/reference/api/pandas.read_json.html”
-
-
class
mlflow.models.
Model
(artifact_path=None, run_id=None, utc_time_created=None, flavors=None) Bases:
object
An MLflow Model that can support multiple model flavors. Provides APIs for implementing new Model flavors.
-
classmethod
log
(artifact_path, flavor, **kwargs) Log model using supplied flavor module.
Parameters: - artifact_path – Run relative path identifying the model.
- flavor – Flavor module to save the model with. The module must have
the
save_model
function that will persist the model as a valid MLflow model. - kwargs – Extra args passed to the model flavor.
-
classmethod