Skip to content

Commit 26fba65

Browse files
committed
Add command to register local onnx model in mlflow
1 parent 79bb5d9 commit 26fba65

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
3+
from django.conf import settings
4+
import djclick as click
5+
import mlflow
6+
import mlflow.onnx
7+
import onnx
8+
9+
10+
@click.command()
11+
def command():
12+
relative = ('..',) * 5
13+
asset_path = os.path.abspath(os.path.join(__file__, *relative, 'assets'))
14+
onnx_filename = os.path.join(asset_path, 'model.mobilenet.onnx')
15+
onnx_model = onnx.load(onnx_filename)
16+
17+
mlflow.set_tracking_uri(settings.MLFLOW_ENDPOINT)
18+
mlflow.set_experiment('default')
19+
with mlflow.start_run() as run:
20+
run_id = run.info.run_id
21+
click.echo(f'Run ID: {run_id}')
22+
mlflow.onnx.log_model(
23+
onnx_model=onnx_model,
24+
artifact_path='onnx_model',
25+
)
26+
model_uri = f'runs:/{run_id}/onnx_model'
27+
result = mlflow.register_model(model_uri=model_uri, name='prototype')
28+
click.echo(f'Registered {model_uri} version {result.version}')

0 commit comments

Comments
 (0)