Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
df317c5
Created a model download + Openvino IR format conversion script, used…
Raghavyadav17 Jun 9, 2025
730d0d1
Add image embedding pipeline with model conversion, preprocessing, po…
Raghavyadav17 Jun 23, 2025
39e7126
Fix: Use numpy<2.0.0 in Dockerfile for compatibility
Raghavyadav17 Jun 23, 2025
9c3be96
Cleanup: Removed venvs and config/make.save files per mentor feedback
Raghavyadav17 Jun 24, 2025
ad2151f
Removed stray convert_clip.py from old PR (not needed)
Raghavyadav17 Jun 24, 2025
9c61416
Fix: updated MediaPipe graph based on mentor feedback
Raghavyadav17 Jun 24, 2025
df9413d
Updated files corrected under Damian's supervision in the meeting
Raghavyadav17 Jul 2, 2025
30bc6a9
Restore Dockerfile.ubuntu after accidental deletion
Raghavyadav17 Jul 2, 2025
38ad1f3
fully functional grpc client + requirements.txt
Raghavyadav17 Jul 22, 2025
f92dd9c
Conversion scripts for dino and laion models to openvino IR
Raghavyadav17 Jul 22, 2025
11c17b5
Updated pre.py
Raghavyadav17 Aug 2, 2025
d2519fa
Updated post.py
Raghavyadav17 Aug 2, 2025
012583a
updated .json file for all models and their respective mediapipe
Raghavyadav17 Aug 2, 2025
a2d7460
Final grpc script, updated clip conversion script, updated requiremen…
Raghavyadav17 Aug 27, 2025
b835e8a
Demo images folder which contains all the images required to build ve…
Raghavyadav17 Aug 27, 2025
709e1f7
mediapipe for clip model
Raghavyadav17 Aug 27, 2025
e119826
mediapipe for dino
Raghavyadav17 Aug 27, 2025
a2fd941
mediapipe for laion
Raghavyadav17 Aug 27, 2025
b0368b2
demo image
Raghavyadav17 Aug 28, 2025
629fa64
search logic
Raghavyadav17 Aug 28, 2025
12bb4a6
demo frontend
Raghavyadav17 Aug 28, 2025
57b2bc9
config json for the project
Raghavyadav17 Aug 30, 2025
8367268
readme for the project
Raghavyadav17 Aug 30, 2025
04f4a53
Final grpc script with cli argument + loading bar as discussed in the…
Raghavyadav17 Aug 30, 2025
259e4ac
demo img for testing
Raghavyadav17 Aug 30, 2025
24196cb
final dino conversion script based on copilot suggestions
Raghavyadav17 Aug 30, 2025
cfc063a
final pre.py based on copilt suggestion
Raghavyadav17 Aug 30, 2025
d1f24b4
fixed dockerfile
Raghavyadav17 Aug 30, 2025
1a5129b
Merge branch 'main' into raghav/image-embedding
Raghavyadav17 Aug 30, 2025
00c8fb2
Merge branch 'main' into raghav/image-embedding
Raghavyadav17 Sep 1, 2025
6e0f4d0
Update demos/python_demos/image_embeddings/Readme.md
Raghavyadav17 Sep 1, 2025
212485d
Update demos/python_demos/image_embeddings/Readme.md
Raghavyadav17 Sep 1, 2025
0aeb55e
Merge branch 'main' into raghav/image-embedding
Raghavyadav17 Sep 2, 2025
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
4 changes: 2 additions & 2 deletions Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ RUN apt-get update ; \
curl -L -O https://github.com/intel/linux-npu-driver/releases/download/v1.16.0/intel-driver-compiler-npu_1.16.0.20250328-14132024782_ubuntu24.04_amd64.deb ; \
curl -L -O https://github.com/intel/linux-npu-driver/releases/download/v1.16.0/intel-fw-npu_1.16.0.20250328-14132024782_ubuntu24.04_amd64.deb ; \
curl -L -O https://github.com/intel/linux-npu-driver/releases/download/v1.16.0/intel-level-zero-npu_1.16.0.20250328-14132024782_ubuntu24.04_amd64.deb ; \
curl -L -O https://github.com/oneapi-src/level-zero/releases/download/v1.20.2/level-zero_1.20.2+u24.04_amd64.deb ; \
fi ; \
curl -L -O https://github.com/oneapi-src/level-zero/releases/download/v1.20.2/level-zero_1.20.2+u24.04_amd64.deb ; \
Copy link
Collaborator

Choose a reason for hiding this comment

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

please don't edit Dockerfile.ubuntu in this pull request (this makes conflicts and is really not required)

fi ; \
dpkg -i ./*.deb && rm -Rf /tmp/npu_deps ; \
fi ; \
apt-get clean ; \
Expand Down
82 changes: 82 additions & 0 deletions demos/python_demos/image_embeddings/grpc_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import sys
sys.path.append("../../common/python")
import tritonclient.grpc as grpcclient
from tritonclient.grpc import service_pb2
from tritonclient.grpc import service_pb2_grpc
from tritonclient.utils import serialize_byte_tensor

import argparse
import datetime
import numpy as np
from client_utils import print_statistics
from urllib.request import urlretrieve
from pathlib import Path
import os
import grpc
import time

parser = argparse.ArgumentParser(description='GRPC client for clip example')

parser.add_argument('--timeout', required=False, default='15',
help='Specify timeout to wait for models readiness on the server in seconds. default 15 seconds.')
parser.add_argument('--url', required=False, default='localhost:9000',
help='Specify url to grpc service. default:localhost:9000')

parser.add_argument('--image_url', required=False, default='https://images.unsplash.com/photo-1716467891152-1b43a96de578?q=80&w=1481&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
help='Specify image_url to send to the CLIP model. default:https://images.unsplash.com/photo-1716467891152-1b43a96de578?q=80&w=1481&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D')

args = vars(parser.parse_args())

iterations = args.get('iterations')
iteration = 0

timeout = int(args.get('timeout'))
# Check models ready
client = grpcclient.InferenceServerClient(args['url'])
channel = grpc.insecure_channel(args['url'])
grpc_stub = service_pb2_grpc.GRPCInferenceServiceStub(channel)

while(timeout):
request = service_pb2.ServerReadyRequest()
response = grpc_stub.ServerReady(request)
print("Server Ready: {}".format(response.ready))
if response.ready:
break
time.sleep(1)
timeout-=1

if not response.ready:
print("Models are not ready. Increase timeout or check server setup and errors.")
exit(-1)

image_url = args['image_url']
print(f"Using image_url:\n{image_url}\n")

input_name = image_url.split("/")[-1]
sample_path = Path(os.path.join("data", input_name))
if not os.path.exists(sample_path):
sample_path.parent.mkdir(parents=True, exist_ok=True)
urlretrieve(
image_url,
sample_path,
)

with open(sample_path, "rb") as f:
image_data = f.read()

image_np = np.array([image_data], dtype=np.object_)

# Set up inference input correctly
image_input = grpcclient.InferInput("image", [1], "BYTES")
image_input.set_data_from_numpy(image_np)

processing_times = []
start_time = datetime.datetime.now()
results = client.infer("python_model", [image_input])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
results = client.infer("python_model", [image_input])
results = client.infer(args['model'], [image_input])

please add --model CLI param. with this, user will not need to modify client code, but simply select model with --model dino_graph for example. you can keep some default for easier of use. im sure current python_model will not work, since you serve:

  • clip_graph
  • dino_graph
  • laion_graph

Copy link
Author

Choose a reason for hiding this comment

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

@dkalinowski sure i will do this

end_time = datetime.datetime.now()
duration = (end_time - start_time).total_seconds() * 1000
processing_times.append(int(duration))
print(f"Detection:\n{results.as_numpy('embedding')}\n")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
print(f"Detection:\n{results.as_numpy('embedding')}\n")
print(f"Embeddings:\n{results.as_numpy('embedding')}\n")


print_statistics(np.array(processing_times,int), batch_size = 1)

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from transformers import CLIPProcessor, CLIPModel
from PIL import Image
import openvino as ov
import os

model_id="openai/clip-vit-base-patch32"
print(f"Downloading pretrained model {model_id}...")

full_model=CLIPModel.from_pretrained(model_id)
model=full_model.vision_model
processor=CLIPProcessor.from_pretrained(model_id)

image=Image.new("RGB",(224,224))
inputs=processor(images=image,return_tensors="pt")["pixel_values"]

print("Converting model...")
ov_model=ov.convert_model(model,example_input=inputs)
ov.save_model(ov_model,"clip_image_encoder.xml")
print("Model saved!")

mod_path="saved_mod/1"
os.makedirs(mod_path,exist_ok=True)
os.replace("clip_image_encoder.xml", f"{mod_path}/clip_image_encoder.xml")
os.replace("clip_image_encoder.bin", f"{mod_path}/clip_image_encoder.bin")
print("Model ready for OVMS")




Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from transformers import AutoImageProcessor, AutoModel
from PIL import Image
import openvino as ov
import os

model_id="facebook/dinov2-base"
print(f"Downloading pretrained model {model_id}...")

model=AutoModel.from_pretrained(model_id)
processor=AutoImageProcessor.from_pretrained(model_id)

image=Image.new("RGB",(224,224))
inputs=processor(images=image,return_tensors="pt")["pixel_values"]

print("Converting models...")
ov_model=ov.convert_model(model,example_input=inputs)
ov.save_model(ov_model,"dino_image_encoder.xml")
print("Model saved!")

mod_path="saved_mod/dino/1"
os.makedirs(mod_path,exist_ok=True)
Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Missing spaces around assignment operators and after commas throughout the file. Should follow PEP 8 spacing conventions.

Suggested change
model_id="facebook/dinov2-base"
print(f"Downloading pretrained model {model_id}...")
model=AutoModel.from_pretrained(model_id)
processor=AutoImageProcessor.from_pretrained(model_id)
image=Image.new("RGB",(224,224))
inputs=processor(images=image,return_tensors="pt")["pixel_values"]
print("Converting models...")
ov_model=ov.convert_model(model,example_input=inputs)
ov.save_model(ov_model,"dino_image_encoder.xml")
print("Model saved!")
mod_path="saved_mod/dino/1"
os.makedirs(mod_path,exist_ok=True)
model_id = "facebook/dinov2-base"
print(f"Downloading pretrained model {model_id}...")
model = AutoModel.from_pretrained(model_id)
processor = AutoImageProcessor.from_pretrained(model_id)
image = Image.new("RGB", (224, 224))
inputs = processor(images=image, return_tensors="pt")["pixel_values"]
print("Converting models...")
ov_model = ov.convert_model(model, example_input=inputs)
ov.save_model(ov_model, "dino_image_encoder.xml")
print("Model saved!")
mod_path = "saved_mod/dino/1"
os.makedirs(mod_path, exist_ok=True)

Copilot uses AI. Check for mistakes.

Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Missing spaces around assignment operators and after commas throughout the file. Should follow PEP 8 spacing conventions.

Suggested change
model_id="facebook/dinov2-base"
print(f"Downloading pretrained model {model_id}...")
model=AutoModel.from_pretrained(model_id)
processor=AutoImageProcessor.from_pretrained(model_id)
image=Image.new("RGB",(224,224))
inputs=processor(images=image,return_tensors="pt")["pixel_values"]
print("Converting models...")
ov_model=ov.convert_model(model,example_input=inputs)
ov.save_model(ov_model,"dino_image_encoder.xml")
print("Model saved!")
mod_path="saved_mod/dino/1"
os.makedirs(mod_path,exist_ok=True)
model_id = "facebook/dinov2-base"
print(f"Downloading pretrained model {model_id}...")
model = AutoModel.from_pretrained(model_id)
processor = AutoImageProcessor.from_pretrained(model_id)
image = Image.new("RGB", (224, 224))
inputs = processor(images=image, return_tensors="pt")["pixel_values"]
print("Converting models...")
ov_model = ov.convert_model(model, example_input=inputs)
ov.save_model(ov_model, "dino_image_encoder.xml")
print("Model saved!")
mod_path = "saved_mod/dino/1"
os.makedirs(mod_path, exist_ok=True)

Copilot uses AI. Check for mistakes.

Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Missing spaces around assignment operators and after commas throughout the file. Should follow PEP 8 spacing conventions.

Suggested change
model_id="facebook/dinov2-base"
print(f"Downloading pretrained model {model_id}...")
model=AutoModel.from_pretrained(model_id)
processor=AutoImageProcessor.from_pretrained(model_id)
image=Image.new("RGB",(224,224))
inputs=processor(images=image,return_tensors="pt")["pixel_values"]
print("Converting models...")
ov_model=ov.convert_model(model,example_input=inputs)
ov.save_model(ov_model,"dino_image_encoder.xml")
print("Model saved!")
mod_path="saved_mod/dino/1"
os.makedirs(mod_path,exist_ok=True)
model_id = "facebook/dinov2-base"
print(f"Downloading pretrained model {model_id}...")
model = AutoModel.from_pretrained(model_id)
processor = AutoImageProcessor.from_pretrained(model_id)
image = Image.new("RGB", (224, 224))
inputs = processor(images=image, return_tensors="pt")["pixel_values"]
print("Converting models...")
ov_model = ov.convert_model(model, example_input=inputs)
ov.save_model(ov_model, "dino_image_encoder.xml")
print("Model saved!")
mod_path = "saved_mod/dino/1"
os.makedirs(mod_path, exist_ok=True)

Copilot uses AI. Check for mistakes.

Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Missing spaces around assignment operators and after commas throughout the file. Should follow PEP 8 spacing conventions.

Suggested change
model_id="facebook/dinov2-base"
print(f"Downloading pretrained model {model_id}...")
model=AutoModel.from_pretrained(model_id)
processor=AutoImageProcessor.from_pretrained(model_id)
image=Image.new("RGB",(224,224))
inputs=processor(images=image,return_tensors="pt")["pixel_values"]
print("Converting models...")
ov_model=ov.convert_model(model,example_input=inputs)
ov.save_model(ov_model,"dino_image_encoder.xml")
print("Model saved!")
mod_path="saved_mod/dino/1"
os.makedirs(mod_path,exist_ok=True)
model_id = "facebook/dinov2-base"
print(f"Downloading pretrained model {model_id}...")
model = AutoModel.from_pretrained(model_id)
processor = AutoImageProcessor.from_pretrained(model_id)
image = Image.new("RGB", (224, 224))
inputs = processor(images=image, return_tensors="pt")["pixel_values"]
print("Converting models...")
ov_model = ov.convert_model(model, example_input=inputs)
ov.save_model(ov_model, "dino_image_encoder.xml")
print("Model saved!")
mod_path = "saved_mod/dino/1"
os.makedirs(mod_path, exist_ok=True)

Copilot uses AI. Check for mistakes.

Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Missing spaces around assignment operators and after commas throughout the file. Should follow PEP 8 spacing conventions.

Suggested change
model_id="facebook/dinov2-base"
print(f"Downloading pretrained model {model_id}...")
model=AutoModel.from_pretrained(model_id)
processor=AutoImageProcessor.from_pretrained(model_id)
image=Image.new("RGB",(224,224))
inputs=processor(images=image,return_tensors="pt")["pixel_values"]
print("Converting models...")
ov_model=ov.convert_model(model,example_input=inputs)
ov.save_model(ov_model,"dino_image_encoder.xml")
print("Model saved!")
mod_path="saved_mod/dino/1"
os.makedirs(mod_path,exist_ok=True)
model_id = "facebook/dinov2-base"
print(f"Downloading pretrained model {model_id}...")
model = AutoModel.from_pretrained(model_id)
processor = AutoImageProcessor.from_pretrained(model_id)
image = Image.new("RGB", (224, 224))
inputs = processor(images=image, return_tensors="pt")["pixel_values"]
print("Converting models...")
ov_model = ov.convert_model(model, example_input=inputs)
ov.save_model(ov_model, "dino_image_encoder.xml")
print("Model saved!")
mod_path = "saved_mod/dino/1"
os.makedirs(mod_path, exist_ok=True)

Copilot uses AI. Check for mistakes.

os.replace("dino_image_encoder.xml", f"{mod_path}/dino_image_encoder.xml")
os.replace("dino_image_encoder.bin", f"{mod_path}/dino_image_encoder.bin")
print("Model ready for OVMS")



Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from transformers import CLIPProcessor, CLIPModel
from PIL import Image
import openvino as ov
import torch
import os

# Replace this with your LAION model
model_id = "laion/CLIP-ViT-B-32-laion2B-s34B-b79K"
print(f"Downloading pretrained model: {model_id}")

# Load processor and model
processor = CLIPProcessor.from_pretrained(model_id)
full_model = CLIPModel.from_pretrained(model_id)
image_encoder = full_model.vision_model
image_encoder.eval()

# Dummy image input for tracing
image = Image.new("RGB", (224, 224))
inputs = processor(images=image, return_tensors="pt")["pixel_values"]

# Convert to OpenVINO IR
print("Converting image encoder to OpenVINO IR...")
ov_model = ov.convert_model(image_encoder, example_input=inputs)
ov.save_model(ov_model, "clip_image_encoder.xml")
print("Model saved!")

# Move to proper OVMS path
mod_path = "saved_mod/laion/1"
os.makedirs(mod_path, exist_ok=True)
os.replace("clip_image_encoder.xml", f"{mod_path}/clip_image_encoder.xml")
os.replace("clip_image_encoder.bin", f"{mod_path}/clip_image_encoder.bin")
print(f"Model ready at {mod_path} for OpenVINO Model Server")
2 changes: 2 additions & 0 deletions demos/python_demos/image_embeddings/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tritonclient[all]==2.51.0
numpy<2.0.0
36 changes: 36 additions & 0 deletions demos/python_demos/image_embeddings/servable/config_model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"model_config_list": [
{
"config": {
"name": "clip",
"base_path": "/saved_mod/clip"
}
},
{
"config": {
"name": "dino",
"base_path": "/saved_mod/dino"
}
},
{
"config": {
"name": "laion",
"base_path": "/saved_mod/laion"
}
}
],
"mediapipe_config_list": [
{
"name": "clip_graph",
"graph_path": "/workspace/graph_clip.pbtxt"
},
{
"name": "dino_graph",
"graph_path": "/workspace/graph_dino.pbtxt"
},
{
"name": "laion_graph",
"graph_path": "/workspace/graph_laion.pbtxt"
}
]
}
81 changes: 81 additions & 0 deletions demos/python_demos/image_embeddings/servable/graph_pipeline.pbtxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
input_stream: "OVMS_PY_TENSOR:image"
output_stream: "OVMS_PY_TENSOR:embedding"

node{
name: "ImagePreprocessor"
calculator: "PythonExecutorCalculator"
input_side_packet: "PYTHON_NODE_RESOURCES:py"
input_stream: "OVMS_PY_TENSOR:image"
output_stream: "OVMS_PY_TENSOR:pixel_values"
node_options:{
[type.googleapis.com/mediapipe.PythonExecutorCalculatorOptions]:{
handler_path: "/workspace/pre.py"
}
}
}

node{
name: "PixelValuesConverter"
calculator: "PyTensorOvTensorConverterCalculator"
input_stream: "OVMS_PY_TENSOR:pixel_values"
output_stream: "OVTENSOR:image_em"
}

node {
calculator: "OpenVINOModelServerSessionCalculator"
output_side_packet: "SESSION:session"
node_options: {
[type.googleapis.com/mediapipe.OpenVINOModelServerSessionCalculatorOptions]: {
servable_name: "clip"
servable_version: "1"
}
}
}

node {
calculator: "OpenVINOInferenceCalculator"
input_side_packet: "SESSION:session"
input_stream: "OVTENSOR:image_em"
output_stream: "OVTENSOR:pooler_output"
node_options: {
[type.googleapis.com/mediapipe.OpenVINOInferenceCalculatorOptions]: {
tag_to_input_tensor_names {
key: "OVTENSOR"
value: "40"
}
tag_to_output_tensor_names {
key: "OVTENSOR"
value: "pooler_output"
}
}
}
}


node {
name: "EmbeddingConverter"
calculator: "PyTensorOvTensorConverterCalculator"
input_stream: "OVTENSOR:pooler_output"
output_stream: "OVMS_PY_TENSOR:pooler_output_em"
node_options: {
[type.googleapis.com/mediapipe.PyTensorOvTensorConverterCalculatorOptions]: {
tag_to_output_tensor_names{
key: "OVMS_PY_TENSOR"
value: "pooler_output_em"
}
}
}
}

node {
name: "Postprocessor"
calculator: "PythonExecutorCalculator"
input_side_packet: "PYTHON_NODE_RESOURCES:py"
input_stream: "OVMS_PY_TENSOR:pooler_output_em"
output_stream: "OVMS_PY_TENSOR:embedding"
node_options: {
[type.googleapis.com/mediapipe.PythonExecutorCalculatorOptions]: {
handler_path: "/workspace/post.py"
}
}
}
25 changes: 25 additions & 0 deletions demos/python_demos/image_embeddings/servable/post.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pyovms import Tensor
import numpy as np

class OvmsPythonModel:
def initialize(self, kwargs: dict):
self.node_name = kwargs.get("node_name", "")
if "clip" in self.node_name.lower():
self.mode = "clip"
Copy link
Collaborator

Choose a reason for hiding this comment

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

is self.mode really needed?

elif "dino" in self.node_name.lower():
self.mode = "dino"
elif "laion" in self.node_name.lower():
self.mode = "laion"
else:
raise ValueError(f"Unsupported model type in node name: {self.node_name}")

def execute(self, inputs: list) -> list:
try:
tensor = inputs[0]
embedding = np.frombuffer(tensor.data, dtype=np.float32).reshape(tensor.shape)
norm = np.linalg.norm(embedding, axis=1, keepdims=True) + 1e-10
normalized = embedding / norm
return [Tensor(name="embedding", buffer=normalized.astype(np.float32))]
except Exception as e:
print(">>> ERROR in Postprocessor:", str(e))
raise
33 changes: 33 additions & 0 deletions demos/python_demos/image_embeddings/servable/pre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pyovms import Tensor
from transformers import CLIPProcessor,AutoImageProcessor
Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Missing space after comma in import statement. Should be CLIPProcessor, AutoImageProcessor.

Suggested change
from transformers import CLIPProcessor,AutoImageProcessor
from transformers import CLIPProcessor, AutoImageProcessor

Copilot uses AI. Check for mistakes.

from PIL import Image
import numpy as np
from io import BytesIO
from tritonclient.utils import deserialize_bytes_tensor

class OvmsPythonModel:
def initialize(self, kwargs:dict):
self.node_name=kwargs.get("node_name","")
Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Missing spaces around assignment operator and after comma. Should be self.node_name = kwargs.get(\"node_name\", \"\").

Suggested change
self.node_name=kwargs.get("node_name","")
self.node_name = kwargs.get("node_name", "")

Copilot uses AI. Check for mistakes.


if "clip" in self.node_name.lower():
self.processor=CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
self.mode="clip"
Copy link
Collaborator

Choose a reason for hiding this comment

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

is self.mode really needed?


elif "dino" in self.node_name.lower():
self.processor=AutoImageProcessor.from_pretrained("facebook/dinov2-base")
self.mode="dino"

elif "laion" in self.node_name.lower():
self.processor=CLIPProcessor.from_pretrained("laion/CLIP-ViT-B-32-laion2B-s34B-b79K")
self.mode="laion"
Comment on lines +10 to +22
Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Missing spaces around assignment operators throughout the method. Should be self.processor = ... and self.mode = ....

Suggested change
self.node_name=kwargs.get("node_name","")
if "clip" in self.node_name.lower():
self.processor=CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
self.mode="clip"
elif "dino" in self.node_name.lower():
self.processor=AutoImageProcessor.from_pretrained("facebook/dinov2-base")
self.mode="dino"
elif "laion" in self.node_name.lower():
self.processor=CLIPProcessor.from_pretrained("laion/CLIP-ViT-B-32-laion2B-s34B-b79K")
self.mode="laion"
self.node_name = kwargs.get("node_name", "")
if "clip" in self.node_name.lower():
self.processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
self.mode = "clip"
elif "dino" in self.node_name.lower():
self.processor = AutoImageProcessor.from_pretrained("facebook/dinov2-base")
self.mode = "dino"
elif "laion" in self.node_name.lower():
self.processor = CLIPProcessor.from_pretrained("laion/CLIP-ViT-B-32-laion2B-s34B-b79K")
self.mode = "laion"

Copilot uses AI. Check for mistakes.

Comment on lines +10 to +22
Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Missing spaces around assignment operators throughout the method. Should be self.processor = ... and self.mode = ....

Suggested change
self.node_name=kwargs.get("node_name","")
if "clip" in self.node_name.lower():
self.processor=CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
self.mode="clip"
elif "dino" in self.node_name.lower():
self.processor=AutoImageProcessor.from_pretrained("facebook/dinov2-base")
self.mode="dino"
elif "laion" in self.node_name.lower():
self.processor=CLIPProcessor.from_pretrained("laion/CLIP-ViT-B-32-laion2B-s34B-b79K")
self.mode="laion"
self.node_name = kwargs.get("node_name", "")
if "clip" in self.node_name.lower():
self.processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
self.mode = "clip"
elif "dino" in self.node_name.lower():
self.processor = AutoImageProcessor.from_pretrained("facebook/dinov2-base")
self.mode = "dino"
elif "laion" in self.node_name.lower():
self.processor = CLIPProcessor.from_pretrained("laion/CLIP-ViT-B-32-laion2B-s34B-b79K")
self.mode = "laion"

Copilot uses AI. Check for mistakes.

Comment on lines +10 to +22
Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Missing spaces around assignment operators throughout the method. Should be self.processor = ... and self.mode = ....

Suggested change
self.node_name=kwargs.get("node_name","")
if "clip" in self.node_name.lower():
self.processor=CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
self.mode="clip"
elif "dino" in self.node_name.lower():
self.processor=AutoImageProcessor.from_pretrained("facebook/dinov2-base")
self.mode="dino"
elif "laion" in self.node_name.lower():
self.processor=CLIPProcessor.from_pretrained("laion/CLIP-ViT-B-32-laion2B-s34B-b79K")
self.mode="laion"
self.node_name = kwargs.get("node_name", "")
if "clip" in self.node_name.lower():
self.processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
self.mode = "clip"
elif "dino" in self.node_name.lower():
self.processor = AutoImageProcessor.from_pretrained("facebook/dinov2-base")
self.mode = "dino"
elif "laion" in self.node_name.lower():
self.processor = CLIPProcessor.from_pretrained("laion/CLIP-ViT-B-32-laion2B-s34B-b79K")
self.mode = "laion"

Copilot uses AI. Check for mistakes.

else:
raise ValueError(f"Unsupported model type in node name: {self.node_name}")

def execute(self,inputs: list):
Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Missing space after comma in function parameter. Should be execute(self, inputs: list).

Suggested change
def execute(self,inputs: list):
def execute(self, inputs: list):

Copilot uses AI. Check for mistakes.

image_bytes = deserialize_bytes_tensor(bytes(inputs[0]))[0]

image=Image.open(BytesIO(image_bytes)).convert("RGB")
processed=self.processor(images=image,return_tensors="np")
pixel_values=processed["pixel_values"].astype(np.float32)
return[Tensor(name="pixel_values",buffer=pixel_values)]
Comment on lines +10 to +32
Copy link
Preview

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

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

Missing spaces around assignment operators and after commas. Should be image = Image.open(...), processed = self.processor(images=image, return_tensors=\"np\"), pixel_values = processed[...], and return [Tensor(name=\"pixel_values\", buffer=pixel_values)].

Suggested change
self.node_name=kwargs.get("node_name","")
if "clip" in self.node_name.lower():
self.processor=CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
self.mode="clip"
elif "dino" in self.node_name.lower():
self.processor=AutoImageProcessor.from_pretrained("facebook/dinov2-base")
self.mode="dino"
elif "laion" in self.node_name.lower():
self.processor=CLIPProcessor.from_pretrained("laion/CLIP-ViT-B-32-laion2B-s34B-b79K")
self.mode="laion"
else:
raise ValueError(f"Unsupported model type in node name: {self.node_name}")
def execute(self,inputs: list):
image_bytes = deserialize_bytes_tensor(bytes(inputs[0]))[0]
image=Image.open(BytesIO(image_bytes)).convert("RGB")
processed=self.processor(images=image,return_tensors="np")
pixel_values=processed["pixel_values"].astype(np.float32)
return[Tensor(name="pixel_values",buffer=pixel_values)]
self.node_name = kwargs.get("node_name", "")
if "clip" in self.node_name.lower():
self.processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
self.mode = "clip"
elif "dino" in self.node_name.lower():
self.processor = AutoImageProcessor.from_pretrained("facebook/dinov2-base")
self.mode = "dino"
elif "laion" in self.node_name.lower():
self.processor = CLIPProcessor.from_pretrained("laion/CLIP-ViT-B-32-laion2B-s34B-b79K")
self.mode = "laion"
else:
raise ValueError(f"Unsupported model type in node name: {self.node_name}")
def execute(self, inputs: list):
image_bytes = deserialize_bytes_tensor(bytes(inputs[0]))[0]
image = Image.open(BytesIO(image_bytes)).convert("RGB")
processed = self.processor(images=image, return_tensors="np")
pixel_values = processed["pixel_values"].astype(np.float32)
return [Tensor(name="pixel_values", buffer=pixel_values)]

Copilot uses AI. Check for mistakes.