-
Notifications
You must be signed in to change notification settings - Fork 218
Logistic Regression #3329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Logistic Regression #3329
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
RUN pip3 install --break-system-packages numpy pandas scikit-learn | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why using |
||
|
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from sklearn.datasets import load_iris | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This entire file should be wrapped in OvmsPythonModel with training done in |
||
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]) |
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" | ||
} | ||
] | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This format is not correct. See: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pandas as pd | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") |
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" | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not work. See: for reference |
There was a problem hiding this comment.
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.