Update handler.py
Browse files- handler.py +13 -13
handler.py
CHANGED
@@ -51,15 +51,13 @@ class EndpointHandler:
|
|
51 |
self.annotator = BoxAnnotator()
|
52 |
|
53 |
def __call__(self, data: Dict[str, Any]) -> Any:
|
54 |
-
#
|
55 |
-
#
|
56 |
-
#
|
57 |
-
#
|
58 |
-
#
|
59 |
-
#
|
60 |
-
#
|
61 |
-
# "draw_bboxes": bool,
|
62 |
-
# }
|
63 |
data = data.pop("inputs")
|
64 |
|
65 |
# read image from either url or base64 encoding
|
@@ -198,7 +196,7 @@ class EndpointHandler:
|
|
198 |
def get_som_labeled_img(
|
199 |
self,
|
200 |
image: ImageType,
|
201 |
-
image_size: Optional[
|
202 |
ocr_texts: Optional[List[str]] = None,
|
203 |
ocr_bboxes: Optional[List[List[int]]] = None,
|
204 |
bbox_threshold: float = 0.01,
|
@@ -211,11 +209,13 @@ class EndpointHandler:
|
|
211 |
|
212 |
w, h = image.size
|
213 |
if image_size is None:
|
214 |
-
|
|
|
|
|
215 |
|
216 |
out = self.yolo.predict(
|
217 |
image,
|
218 |
-
imgsz=
|
219 |
conf=bbox_threshold,
|
220 |
iou=iou_threshold or 0.7,
|
221 |
verbose=False,
|
@@ -652,4 +652,4 @@ class BoxAnnotator:
|
|
652 |
text_background_y1,
|
653 |
text_background_x2,
|
654 |
text_background_y2,
|
655 |
-
)
|
|
|
51 |
self.annotator = BoxAnnotator()
|
52 |
|
53 |
def __call__(self, data: Dict[str, Any]) -> Any:
|
54 |
+
# data should contain the following:
|
55 |
+
# "inputs": {
|
56 |
+
# "image": url/base64,
|
57 |
+
# (optional) "image_size": tuple(int, int) / list(int),
|
58 |
+
# (optional) "bbox_threshold": float,
|
59 |
+
# (optional) "iou_threshold": float,
|
60 |
+
# }
|
|
|
|
|
61 |
data = data.pop("inputs")
|
62 |
|
63 |
# read image from either url or base64 encoding
|
|
|
196 |
def get_som_labeled_img(
|
197 |
self,
|
198 |
image: ImageType,
|
199 |
+
image_size: Optional[Dict[Literal["w", "h"], int]] = None,
|
200 |
ocr_texts: Optional[List[str]] = None,
|
201 |
ocr_bboxes: Optional[List[List[int]]] = None,
|
202 |
bbox_threshold: float = 0.01,
|
|
|
209 |
|
210 |
w, h = image.size
|
211 |
if image_size is None:
|
212 |
+
imgsz = {"h": h, "w": w}
|
213 |
+
else:
|
214 |
+
imgsz = [image_size.get("h", h), image_size.get("w", w)]
|
215 |
|
216 |
out = self.yolo.predict(
|
217 |
image,
|
218 |
+
imgsz=imgsz,
|
219 |
conf=bbox_threshold,
|
220 |
iou=iou_threshold or 0.7,
|
221 |
verbose=False,
|
|
|
652 |
text_background_y1,
|
653 |
text_background_x2,
|
654 |
text_background_y2,
|
655 |
+
)
|