Skip to content

Conversation

@leoheim
Copy link
Contributor

@leoheim leoheim commented Aug 19, 2025

Summary

Mentor: '@SHIVAMBASIA'

This PR adds comprehensive scikit-learn and PyTorch model wrappers with OpenVINO optimization for the GSoC 2025 "AI PC Model Training Kit" project. These wrappers enable developers to train, evaluate, and deploy classical ML and deep learning models locally using OpenVINO's optimized backend.

Key features:

  • scikit-learn wrappers for classification, regression, clustering, decomposition, and neighbors
  • PyTorch wrappers for classification, regression, segmentation, and detection
  • Automatic OpenVINO optimization via sklearnex and Intel Extension for PyTorch (IPEX)
  • Model persistence: joblib for scikit-learn, checkpointing for PyTorch
  • OpenVINO IR export for supported models

Supported models:

  • scikit-learn: LogisticRegression, RandomForestClassifier, KNeighborsClassifier, SVC, NuSVC, LinearRegression, Ridge, ElasticNet, Lasso, RandomForestRegressor, KNeighborsRegressor, SVR, NuSVR, KMeans, DBSCAN, PCA, IncrementalPCA, TSNE, NearestNeighbors
  • PyTorch: Any nn.Module (e.g., ResNet, UNet) via wrappers for classification, regression, segmentation, detection

How to test

scikit-learn example

from ov_training_kit.sklearn import LogisticRegression
from sklearn.datasets import make_classification

X, y = make_classification(n_samples=1000, n_features=20, random_state=42)
model = LogisticRegression()
model.fit(X, y)
model.save_model("test_model.joblib")
model.load_model("test_model.joblib")
model.convert_to_ir(X, model_name="test_model")

PyTorch example

import torch
from torchvision.models import resnet18
from ov_training_kit.pytorch import ClassificationWrapper

model = resnet18(pretrained=True)
model.fc = torch.nn.Linear(model.fc.in_features, 10)
wrapper = ClassificationWrapper(model)

X = torch.randn(32, 3, 224, 224)
y = torch.randint(0, 10, (32,))
loader = torch.utils.data.DataLoader(list(zip(X, y)), batch_size=8)

from torch import nn, optim
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(wrapper.model.parameters())
wrapper.train(loader, criterion, optimizer, num_epochs=1, device="cpu")

wrapper.compile()

def accuracy_metric(preds, targets):
    return (preds.argmax(dim=1) == targets).float().mean().item()
score = wrapper.evaluate(loader, accuracy_metric, device="cpu")
print("Accuracy:", score)

See the README files in src/sklearn and src/pytorch for more details and usage examples.

@leoheim leoheim requested a review from a team as a code owner August 19, 2025 03:06
@SHIVAMBASIA
Copy link

@alvoron Can you please review the code and provide your feedback?

Copy link
Contributor

@alvoron alvoron left a comment

Choose a reason for hiding this comment

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

@leoheim
Copy link
Contributor Author

leoheim commented Aug 20, 2025

@alvoron I've updated the Pr with the changes, thanks!

@alvoron alvoron merged commit b6f74bf into openvinotoolkit:master Aug 28, 2025
1 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants