Upload model.py with huggingface_hub
Browse files
model.py
CHANGED
@@ -1,13 +1,16 @@
|
|
1 |
-
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
|
5 |
-
class
|
6 |
def __init__(self, model_path: str):
|
7 |
-
self.
|
8 |
-
|
9 |
-
def predict(self, image: Image):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
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
|