-
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.
Open
Changes from all 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,2 @@ | ||
data/ | ||
model/ |
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,23 @@ | ||
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 pip install --no-cache-dir --break-system-packages \ | ||
pandas numpy scikit-learn joblib skl2onnx onnx onnxruntime \ | ||
scikit-learn-intelex==2025.7.0 \ | ||
tritonclient[all] | ||
RUN python3 -m pip install --no-cache-dir --break-system-packages \ | ||
torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu && \ | ||
python3 -m pip install --no-cache-dir --break-system-packages \ | ||
intel-extension-for-pytorch oneccl_bind_pt \ | ||
--extra-index-url https://pytorch-extension.intel.com/release-whl/stable/cpu/us/ | ||
|
||
RUN rm /ovms/lib/libtbb.so* && cp /usr/local/lib/libtbb.so* /ovms/lib/ | ||
|
||
ENTRYPOINT ["/ovms/bin/ovms"] | ||
|
||
|
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,182 @@ | ||
# OVMS Iris Pipeline Example | ||
|
||
This repository demonstrates how to use OpenVINO Model Server (OVMS) with a custom Mediapipe pipeline for the Iris dataset, including both model training and inference through a Python client. | ||
At the moment, it supports Logistic regression and KMeans. | ||
|
||
--- | ||
|
||
## Step 1: Clone the Repository | ||
|
||
```bash | ||
git clone https://github.com/openvinotoolkit/model_server.git | ||
cd model_server/extras/iris_pipeline_project | ||
``` | ||
--- | ||
|
||
|
||
## Step 2: Build and Run OVMS Docker Image | ||
|
||
### 2.1. Build the Docker Image | ||
|
||
```bash | ||
docker build --no-cache -t prototype_iris . | ||
``` | ||
|
||
### 2.2. Run the OVMS Container | ||
|
||
```bash | ||
docker run --rm -it -v $(pwd):/workspace -p 9000:9000 prototype_iris --config_path /workspace/model_config.json --port 9000 --log_level DEBUG | ||
``` | ||
- **Note:** Adjust `$(pwd)` if you are running from a different working directory. | ||
|
||
--- | ||
|
||
## Step 3: Project Structure | ||
|
||
``` | ||
client/ | ||
├── client_inference.py | ||
└── client_train.py | ||
data_folder/ | ||
├── iris_train.csv | ||
└── iris_test.csv | ||
pipeline/ | ||
├── __pycache__/ | ||
├── graph.pbtxt | ||
├── model.py | ||
└── ovmsmodel.py | ||
Dockerfile | ||
model_config.json | ||
kmeans_params.json | ||
hyperparams.json | ||
|
||
``` | ||
|
||
--- | ||
|
||
## Step 4: Run Training and Inference | ||
|
||
### 4.1. Training | ||
|
||
```bash | ||
python client/client_train.py train iris_train.csv Species --params hyperparams.json --encode Species --model_class LogisticRegressionTorch | ||
|
||
python client/client_train.py train iris_train.csv Species --params kmeans_params.json --encode Species --model_class KMeansSkLearn | ||
|
||
|
||
``` | ||
|
||
### 4.2. Inference | ||
|
||
```bash | ||
python client/client_inference.py infer data_folder/iris_test.csv --target_column Species --model_class LogisticRegressionTorch | ||
|
||
python client/client_inference.py infer iris_train_nolabel.csv --target_column Species --model_class KMeansSkLearn | ||
|
||
``` | ||
|
||
--- | ||
|
||
For Enabling accelerator support: | ||
Manually set the ```bool - (use_ipex/use_oneDAL)``` in model.py file under "pipeline" directory to either True/False depending on the necessity. | ||
|
||
## Instructions for preparing the data | ||
Run the command to download the Iris dataset, which is taken to be the hello-world dataset of classification datasets. | ||
|
||
```bash | ||
curl -o iris.csv https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data | ||
``` | ||
|
||
|
||
Command-Line Usage | ||
|
||
The training and inference client supports flexible options for both Logistic Regression and KMeans models. | ||
|
||
Usage | ||
python client/client_train.py <train|infer> <path_to_csv> <target_column (or NONE for KMeans)> \ | ||
[--params <path_to_params_json>] [--encode <col1,col2,...>] [--model_class <ModelClassName>] | ||
|
||
Arguments | ||
|
||
train|infer | ||
Mode of operation. | ||
|
||
train: Train a new model with the provided dataset. | ||
|
||
infer: Run inference using a trained model. | ||
|
||
<path_to_csv> | ||
Path to the dataset in CSV format. | ||
|
||
<target_column> | ||
|
||
For classification (Logistic Regression): name of the target column. | ||
|
||
For clustering (KMeans): use NONE. | ||
|
||
--params <path_to_params_json> (optional) | ||
Path to a JSON file containing model hyperparameters. | ||
Example: | ||
|
||
{ | ||
"max_iter": 300, | ||
"solver": "lbfgs", | ||
"random_state": 42, | ||
"n_clusters": 3 | ||
} | ||
|
||
If not provided, default parameters are used. | ||
|
||
--encode <col1,col2,...> (optional) | ||
Comma-separated list of categorical column names to encode. | ||
|
||
Encoding can also be performed client-side before sending data to the server. | ||
|
||
If omitted, no encoding is applied. | ||
|
||
--model_class <ModelClassName> (optional) | ||
Specify the model class explicitly (e.g., LogisticRegression, KMeans). | ||
|
||
Defaults are inferred from the mode and target column. | ||
|
||
--- | ||
|
||
## Troubleshooting | ||
|
||
- **Logs:** | ||
For debugging, check OVMS container logs: | ||
```bash | ||
docker logs prototype_iris | ||
``` | ||
- **Code Changes:** | ||
After editing `pipeline/ovmsmodel.py`, **restart the OVMS container** for changes to take effect. | ||
|
||
- **If nothing prints from your Python node:** | ||
- Use `flush=True` in your print statements. | ||
- Print to `sys.stderr`. | ||
- Try writing to a file inside the container for debug. | ||
|
||
--- | ||
|
||
## Example Output | ||
For Training: | ||
|
||
``` | ||
Read CSV file successfully | ||
Training mode detected. Preparing data for training... | ||
Connected to OVMS at localhost:9000 | ||
Model trained successfully | ||
|
||
``` | ||
For Inference: | ||
|
||
``` | ||
Read CSV file successfully | ||
Inference mode detected. | ||
Inference predictions: [...] | ||
|
||
``` | ||
|
||
--- | ||
|
||
NOTE: Cluster assignments and centroid details are available in the container logs. Since the terminal is non-GUI, .show() visualization is not supported. |
Oops, something went wrong.
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.
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.
We needed that for benchmarks.In the guide we should not require user to modify the code.
Either remove it completely and use acceleration by default or pass it in hyperparameters JSON.