Update handler.py
Browse files- handler.py +14 -22
handler.py
CHANGED
@@ -1,28 +1,20 @@
|
|
1 |
-
import
|
2 |
-
from
|
3 |
|
4 |
-
class
|
5 |
-
def __init__(self):
|
6 |
-
|
7 |
-
self.
|
8 |
|
9 |
-
def
|
10 |
-
#
|
11 |
-
|
12 |
-
self.processor = AutoProcessor.from_pretrained(model_dir)
|
13 |
-
|
14 |
-
def preprocess(self, request):
|
15 |
-
# 解析輸入資料
|
16 |
-
inputs = request.get("inputs")
|
17 |
-
return self.processor(images=inputs, return_tensors="pt")
|
18 |
|
19 |
def inference(self, inputs):
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
return outputs
|
24 |
|
25 |
def postprocess(self, outputs):
|
26 |
-
#
|
27 |
-
|
28 |
-
return {"predictions": results}
|
|
|
1 |
+
from ultralytics import YOLO
|
2 |
+
from huggingface_inference_toolkit.handler import BaseHandler
|
3 |
|
4 |
+
class CustomYOLOHandler(BaseHandler):
|
5 |
+
def __init__(self, model_dir, *args, **kwargs):
|
6 |
+
super().__init__(*args, **kwargs)
|
7 |
+
self.model = YOLO(f"{model_dir}/model.pt")
|
8 |
|
9 |
+
def preprocess(self, inputs):
|
10 |
+
# Preprocess inputs for YOLO
|
11 |
+
return inputs
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
def inference(self, inputs):
|
14 |
+
# Perform inference
|
15 |
+
results = self.model(inputs)
|
16 |
+
return results
|
|
|
17 |
|
18 |
def postprocess(self, outputs):
|
19 |
+
# Convert YOLO results to HuggingFace pipeline outputs
|
20 |
+
return outputs
|
|