diff --git a/docs/machine_learning.rst b/docs/machine_learning.rst index 69f315e1b..40527922c 100644 --- a/docs/machine_learning.rst +++ b/docs/machine_learning.rst @@ -89,7 +89,6 @@ Finally execute this whole training flow as a batch job:: training_job = model.create_job() training_job.start_and_wait() - Inference ---------- @@ -97,22 +96,35 @@ When the batch job finishes successfully, the trained model can then be used with the ``predict_random_forest`` process on the raster data cube (or another cube with the same band structure) to classify all the pixels. +We inspect the result metadata of the training job to obtain the STAC Item URL of the trained model:: + + + results = training_job.get_results() + links = results.get_metadata()['links'] + ml_model_metadata_url = [link for link in links if 'ml_model_metadata.json' in link['href']][0]['href'] + print(ml_model_metadata_url) + + +Next, load the model from the URL:: + + model = connection.load_ml_model(id=ml_model_metadata_url) + Technically, the openEO ``predict_random_forest`` process has to be used as a reducer function inside a ``reduce_dimension`` call, but the openEO Python client library makes it a bit easier by providing a :py:meth:`~openeo.rest.datacube.DataCube.predict_random_forest` method directly on the :py:class:`~openeo.rest.datacube.DataCube` class, so that you can just do:: predicted = cube.predict_random_forest( - model=training_job.job_id, + model=model, dimension="bands" ) predicted.download("predicted.GTiff") - -We specified the model here by batch job id (string), +We specified the model here by URL corresponding to the +STAC Item that implements the ml-model extension, but it can also be specified in other ways: as :py:class:`~openeo.rest.job.BatchJob` instance, -as URL to the corresponding STAC Item that implements the `ml-model` extension, +as job_id of training job (string), or as :py:class:`~openeo.rest.mlmodel.MlModel` instance (e.g. loaded through -:py:meth:`~openeo.rest.connection.Connection.load_ml_model`). +:py:meth:`~openeo.rest.connection.Connection.load_ml_model`). \ No newline at end of file