Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions iris_pipeline_project/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM openvino/model_server:latest

USER root

ENV LD_LIBRARY_PATH=/ovms/lib
ENV PYTHONPATH=/ovms/lib/python

RUN apt update && apt install -y python3-pip git \
build-essential python3-dev libatlas-base-dev
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need those packages?
Since we only want to download a few python packages, they don't look necessary.


RUN pip3 install --break-system-packages numpy pandas scikit-learn
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using --break-system-packages?



COPY pipeline/graph.pbtxt /models/iris_pipeline/
COPY pipeline/ovmsmodel.py /models/iris_pipeline/
COPY model/model.pkl /models/iris_pipeline/
COPY model_config.json /model_config.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop those lines. Eventually we would like to have a Dockerfile for multiple models, datasets etc. so users would build the image with all required packages and mount their data while launching the container.


ENTRYPOINT [ "/ovms/bin/ovms" ]
24 changes: 24 additions & 0 deletions iris_pipeline_project/convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from sklearn.datasets import load_iris
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire file should be wrapped in OvmsPythonModel with training done in execute method

from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
import joblib
import os
import openvino as ov

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

model = LogisticRegression(max_iter=200)
model.fit(X_train, y_train)

joblib.dump(model, 'logreg_model.pkl')

from skl2onnx import to_onnx

onx = to_onnx(model, X_train[:1], target_opset=12)
ov.convert_model('logreg_model.onnx')

import onnx
model = onnx.load("model/iris_logreg/1/logreg_model.onnx")
print("Inputs:", [i.name for i in model.graph.input])
print("Outputs:", [o.name for o in model.graph.output])
Binary file not shown.
10 changes: 10 additions & 0 deletions iris_pipeline_project/model_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"custom_node_library_config_list": [],
"graph_config_list": [
{
"name": "iris_pipeline",
"base_path": "/models/iris_pipeline",
"graph_path": "graph.pbtxt"
}
]
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

29 changes: 29 additions & 0 deletions iris_pipeline_project/ovmsmodel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pandas as pd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is unnecessary. After exporting model to ONNX we can use native KServe API support.

import numpy as np
import joblib
import os
from pyovms import Tensor

class OvmsPythonModel:
def initialize(self, kwargs):
print("Initializing model")
model_path = os.path.join(os.path.dirname(__file__), 'model.pkl')
self.model = joblib.load(model_path)
print("Model loaded successfully.")

def execute(self, inputs):
print("Executing inference...")
input_tensor = inputs[0]
input_data = input_tensor.as_numpy()

csv_data = input_data.tobytes().decode('utf-8')
df = pd.read_csv(pd.compat.StringIO(csv_data))

features = df.iloc[:, :-1]
preds = self.model.predict(features)

output = Tensor.from_numpy(np.array(preds, dtype=np.int32))
return [output]

def finalize(self):
print("Finalizing model")
14 changes: 14 additions & 0 deletions iris_pipeline_project/pipeline/graph.pbtxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
input_stream: "inference_input"
output_stream: "inference_output"

node {
calculator: "InferenceCalculator"
input_stream: "inference_input"
output_stream: "inference_output"
options: {
[type.googleapis.com/openvino.CalculatorOptions] {
model_name: "iris_pipeline"
signature_name: "serving_default"
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.