-
Notifications
You must be signed in to change notification settings - Fork 218
Optimized serving endpoint for classical ML models #3377
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
Open
darksapien23151
wants to merge
71
commits into
openvinotoolkit:main
Choose a base branch
from
darksapien23151:logreg-patch1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,378
−0
Open
Changes from 13 commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
86b224e
Logistic Regression-patch2
darksapien23151 8921c90
Merge branch 'main' into logreg-patch1
darksapien23151 297909d
Update extras/iris_pipeline_project/model_config.json
darksapien23151 620ae60
Update extras/iris_pipeline_project/pipeline/ovmsmodel.py
darksapien23151 e5af86b
Update model_config.json
darksapien23151 96c1953
Update Dockerfile
darksapien23151 e64e7a1
Update graph.pbtxt
darksapien23151 5e1439e
Update ovmsmodel.py
darksapien23151 930aaa8
Create .gitignore
darksapien23151 ca366ca
Delete extras/iris_pipeline_project/data directory
darksapien23151 8a3097d
Update .gitignore
darksapien23151 3cdf97c
Add files via upload
darksapien23151 f938740
Removed data folder
hvssmanne b28a63e
Create README.md
darksapien23151 e7a6f1f
Update client_train.py
darksapien23151 d70052e
Update ovmsmodel.py
darksapien23151 0bf9bee
Update ovmsmodel.py
darksapien23151 1053f5f
Update README.md
darksapien23151 860a889
Update Dockerfile
darksapien23151 f56008b
Update .gitignore
darksapien23151 dc5f52e
Update client_train.py
darksapien23151 66d5966
Update client_inference.py
darksapien23151 0b6cbc0
Update ovmsmodel.py
darksapien23151 daaf522
Update ovmsmodel.py
darksapien23151 3dd60cc
Modified files and removed model/
hvssmanne a783d99
Merge branch 'openvinotoolkit:main' into logreg-patch1
darksapien23151 59031cf
Merge remote-tracking branch 'origin/logreg-patch1' and resolve confl…
hvssmanne c49bf22
Update README.md
darksapien23151 a31c177
Update README.md
darksapien23151 59a66a0
Update README.md
darksapien23151 b1e6ad0
Update README.md
darksapien23151 36689ab
Create data_preprocess.py
darksapien23151 f2049be
Update .gitignore
darksapien23151 ffcb534
Update ovmsmodel.py
darksapien23151 7c00c27
Update ovmsmodel.py
darksapien23151 bc42ce7
Update Dockerfile
darksapien23151 f102453
Update ovmsmodel.py
darksapien23151 82d5f0c
Update client_train.py
darksapien23151 8821147
Add files via upload
darksapien23151 a614ae5
Update extras/iris_pipeline_project/Dockerfile
darksapien23151 49ee303
Update .gitignore
darksapien23151 1f1b8b4
Update ovmsmodel.py
darksapien23151 b61cbe1
Update data_preprocess.py
darksapien23151 4c68c8b
Update data_preprocess.py
darksapien23151 53a79b1
Merge branch 'main' into logreg-patch1
darksapien23151 60db5be
Update client_inference.py
darksapien23151 c16a94c
Update client_train.py
darksapien23151 c2174e9
Update README.md
darksapien23151 1a21d72
Update README.md
darksapien23151 17f77b7
Update README.md
darksapien23151 d0b01cf
Update Dockerfile
darksapien23151 43b985e
Update client_train.py
darksapien23151 f616db7
Update ovmsmodel.py
darksapien23151 701ef29
Create labelmap.json
darksapien23151 b76cbda
Update model_config.json
darksapien23151 6737047
Update client_inference.py
darksapien23151 7845c64
Update ovmsmodel.py
darksapien23151 e1dd8cb
Update Dockerfile
darksapien23151 2c28d8b
Update Dockerfile
darksapien23151 35aada3
Create model.py
darksapien23151 4b9784b
Update ovmsmodel.py
darksapien23151 0c1202f
Add hyperparameters
hvssmanne 11e3673
Add KMeans support
hvssmanne 02915c8
Update README.md
darksapien23151 bd2e780
Update README.md
darksapien23151 e566762
Update README.md
darksapien23151 79e0d3b
Update extras/iris_pipeline_project/pipeline/ovmsmodel.py
darksapien23151 95447f3
Update extras/iris_pipeline_project/pipeline/model.py
darksapien23151 b7db421
Update extras/iris_pipeline_project/client/client_inference.py
darksapien23151 040f0c5
Update extras/iris_pipeline_project/client/client_inference.py
darksapien23151 9f7d3a0
Update README.md
darksapien23151 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
data/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM openvino/model_server:latest | ||
|
||
USER root | ||
|
||
ENV LD_LIBRARY_PATH=/ovms/lib | ||
ENV PYTHONPATH=/ovms/lib/python | ||
|
||
RUN apt-get update && apt-get install -y python3-pip | ||
RUN pip3 install --break-system-packages pandas numpy scikit-learn joblib skl2onnx onnx onnxruntime | ||
|
||
|
||
WORKDIR /workspace | ||
ENTRYPOINT ["/ovms/bin/ovms", "--config_path", "/model_config.json", "--grpc_port", "9000"] | ||
darksapien23151 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import numpy as np | ||
import tritonclient.grpc as grpcclient | ||
import pandas as pd | ||
|
||
|
||
X_test = pd.read_csv("/home/harshitha/iris_pipeline_project/data/iris_test.csv") | ||
darksapien23151 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
X_test = X_test.values.astype(np.float32) | ||
darksapien23151 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
input_name = "input" | ||
output_name = "output_label" | ||
|
||
inputs = [] | ||
infer_input = grpcclient.InferInput(input_name, X_test.shape, "FP32") | ||
infer_input.set_data_from_numpy(X_test) | ||
inputs.append(infer_input) | ||
|
||
outputs = [grpcclient.InferRequestedOutput(output_name)] | ||
|
||
client = grpcclient.InferenceServerClient(url="localhost:9000") | ||
|
||
model_name = "iris_logreg" | ||
response = client.infer(model_name=model_name, inputs=inputs, outputs=outputs) | ||
|
||
predictions = response.as_numpy(output_name) | ||
print("Predictions:", predictions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import numpy as np | ||
darksapien23151 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import pandas as pd | ||
import tritonclient.grpc as grpcclient | ||
|
||
data = pd.read_csv("/home/harshitha/iris_pipeline_project/data/iris_train.csv") | ||
darksapien23151 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
df = pd.DataFrame(data) | ||
|
||
csv_str = df.to_csv(index=False) | ||
csv_bytes = np.frombuffer(csv_str.encode('utf-8'), dtype=np.uint8) | ||
|
||
input_name = "input" | ||
input = [] | ||
infer_input = grpcclient.InferInput(input_name, csv_bytes.shape, "UINT8") | ||
infer_input.set_data_from_numpy(csv_bytes) | ||
input.append(infer_input) | ||
|
||
output_name = "output_label" | ||
output_label = [grpcclient.InferRequestedOutput(output_name)] | ||
|
||
client = grpcclient.InferenceServerClient(url="localhost:9000") | ||
|
||
model_name = "iris_pipeline" | ||
response = client.infer(model_name=model_name, inputs=input, outputs=output_label) | ||
|
||
result = response.as_numpy(output_name) | ||
print("Training result:", result) |
darksapien23151 marked this conversation as resolved.
Show resolved
Hide resolved
|
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"model_config_list": [], | ||
"mediapipe_config_list": [ | ||
{ | ||
"name": "pipeline", | ||
"graph_path": "/workspace/pipeline/graph.pbtxt" | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
input_stream: "OVMS_PY_TENSOR:pipeline_input" | ||
output_stream: "OVMS_PY_TENSOR:pipeline_output" | ||
|
||
node { | ||
name: "python_node" | ||
calculator: "PythonExecutorCalculator" | ||
input_side_packet: "PYTHON_NODE_RESOURCES:py" | ||
input_stream: "PIPELINE_INPUT:pipeline_input" | ||
output_stream: "PIPELINE_OUTPUT:pipeline_output" | ||
node_options: { | ||
[type.googleapis.com/mediapipe.PythonExecutorCalculatorOptions]: { | ||
handler_path: "/workspace/pipeline/ovmsmodel.py" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import numpy as np | ||
import pandas as pd | ||
import os | ||
import json | ||
from skl2onnx import convert_sklearn | ||
from skl2onnx.common.data_types import FloatTensorType | ||
from sklearn.linear_model import LogisticRegression | ||
import onnxruntime as ort | ||
|
||
MODEL_PATH = "/workspace/model/iris_logreg/1/model.onnx" | ||
LABEL_COLUMN = "species" | ||
|
||
class OvmsPythonModel: | ||
def initialize(self, kwargs): | ||
print("Training handler initialized.") | ||
|
||
def execute(self, inputs, outputs, parameters, context): | ||
# Expecting a dict: {"mode": "train" or "infer", "data": <CSV string>} | ||
input_bytes = inputs["pipeline_input"] | ||
try: | ||
input_str = input_bytes.tobytes().decode('utf-8') | ||
input_obj = json.loads(input_str) | ||
mode = input_obj.get("mode") | ||
csv_str = input_obj.get("data") | ||
except Exception as e: | ||
outputs["pipeline_output"] = np.array([f"ERROR: Invalid input format: {e}"], dtype=object) | ||
return | ||
|
||
try: | ||
df = pd.read_csv(pd.compat.StringIO(csv_str)) | ||
except Exception as e: | ||
outputs["pipeline_output"] = np.array([f"ERROR: Could not parse CSV: {e}"], dtype=object) | ||
return | ||
|
||
if mode == "train": | ||
if LABEL_COLUMN not in df.columns: | ||
outputs["pipeline_output"] = np.array([f"ERROR: Training data must include label column '{LABEL_COLUMN}'"], dtype=object) | ||
return | ||
X = df.drop(columns=[LABEL_COLUMN]) | ||
y = df[LABEL_COLUMN] | ||
model = LogisticRegression(max_iter=200) | ||
model.fit(X, y) | ||
os.makedirs(os.path.dirname(MODEL_PATH), exist_ok=True) | ||
initial_type = [('float_input', FloatTensorType([None, X.shape[1]]))] | ||
onnx_model = convert_sklearn(model, initial_types=initial_type) | ||
with open(MODEL_PATH, "wb") as f: | ||
f.write(onnx_model.SerializeToString()) | ||
outputs["pipeline_output"] = np.array(["training complete"], dtype=object) | ||
elif mode == "infer": | ||
if not os.path.exists(MODEL_PATH): | ||
outputs["pipeline_output"] = np.array(["ERROR: Model not trained yet"], dtype=object) | ||
return | ||
X = df.values.astype(np.float32) | ||
sess = ort.InferenceSession(MODEL_PATH) | ||
input_name = sess.get_inputs()[0].name | ||
preds = sess.run(None, {input_name: X})[0] | ||
outputs["pipeline_output"] = preds | ||
else: | ||
outputs["pipeline_output"] = np.array([f"ERROR: Unknown mode '{mode}'"], dtype=object) | ||
|
||
def finalize(self): | ||
print("Training handler finalized.") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.