同步操作将从 Gitee 极速下载/MLflow 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
In this example we demonstrate how to train and deploy image classification models with MLflow.
We train a VGG16 deep learning model to classify flower species from photos using a tensorflow.org. Note that although we use Keras to train the model in this case,
a similar approach can be applied to other deep learning frameworks such as PyTorch.
The MLflow model produced by running this example can be deployed to any MLflow supported endpoints. All the necessary image preprocessing is packaged with the model. The model can therefore be applied to image data directly. All that is required in order to pass new data to the model is to encode the image binary data as base64 encoded string in pandas DataFrame (standard interface for MLflow python function models). The included Python scripts demonstrate how the model can be deployed to a REST API endpoint for realtime evaluation or to Spark for batch scoring..
In order to include custom image pre-processing logic with the model, we define the model as a custom python function model wrapping around the underlying Keras model. The wrapper provides necessary preprocessing to convert input data into multidimensional arrays expected by the Keras model. The preprocessing logic is stored with the model as a code dependency. Here is an example of the output model directory layout:
tree model
model ├── MLmodel ├── code │ └── image_pyfunc.py ├── data │ └── image_model │ ├── conf.yaml │ └── keras_model │ ├── MLmodel │ ├── conda.yaml │ └── model.h5 └── mlflow_env.yml
The example contains the following files:
- MLproject Contains definition of this project. Contains only one entry point to train the model.
- conda.yaml Defines project dependencies. NOTE: You might want to change tensorflow package to tensorflow-gpu if you have gpu(s) available.
- train.py Main entry point of the projects. Handles command line arguments and possibly downloads the dataset.
- keras_image_classifier.py The implementation of the model train and also of the outputed custom python flavor model. Note that the same preprocessing code that is used during model training is packaged with the output model and is used during scoring.
- score_images_rest.py Score an image or a directory of images using a model deployed to a REST endpoint.
- score_images_spark.py Score an image or a directory of images using model deployed to Spark.
To train the model, run the example as a standard MLflow project:
mlflow run examples/flower_classifier
This will download the training dataset from tensorflow.org, train a classifier using Keras and
log results with Mlflow.
To test your model, run the included scoring scripts. For example, say your model was trained with
run_id 101.
To test REST api scoring do the following two steps:
# deploy the model to local REST api endpoint
mlflow pyfunc serve -p 54321 -r 101 -m model
# score the deployed model
python score_images_rest.py --port 54321 http://127.0.0.1 ./my_images_to_score
To test batch scoring in Spark, run score_images_spark.py to score the model in Spark like this:
python score_images_spark.py ./my_images_to_score model --run-id 101
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。