rayh commited on
Commit
5957194
·
verified ·
1 Parent(s): 9dc12ca

Upload model.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. model.py +12 -9
model.py CHANGED
@@ -1,13 +1,16 @@
1
- import onnxruntime as ort
2
  import numpy as np
3
  from PIL import Image
4
 
5
- class YOLOSegmentationModel:
6
  def __init__(self, model_path: str):
7
- self.session = ort.InferenceSession(model_path)
8
-
9
- def predict(self, image: Image):
10
- input_data = np.array(image).astype(np.float32)
11
- input_data = np.expand_dims(input_data, axis=0) # Add batch dimension
12
- outputs = self.session.run(None, {"images": input_data})
13
- return outputs
 
 
 
 
1
+ from ultralytics import YOLO
2
  import numpy as np
3
  from PIL import Image
4
 
5
+ class YOLOv8SegmentationModel:
6
  def __init__(self, model_path: str):
7
+ self.model = YOLO(model_path)
8
+
9
+ def predict(self, image: Image.Image):
10
+ # Convert PIL Image to numpy array if needed
11
+ if isinstance(image, Image.Image):
12
+ image = np.array(image)
13
+
14
+ # Run inference
15
+ results = self.model(image, task='segment')
16
+ return results[0] # Return first batch result