From 6b3dc62f32f07f4d2c16527e96503ea2f9460409 Mon Sep 17 00:00:00 2001 From: UltralyticsAssistant Date: Wed, 9 Oct 2024 16:26:02 +0000 Subject: [PATCH] Auto-format by https://ultralytics.com/actions --- ultralytics/solutions/serve.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ultralytics/solutions/serve.py b/ultralytics/solutions/serve.py index a8e31a81c3..ddc265f48f 100644 --- a/ultralytics/solutions/serve.py +++ b/ultralytics/solutions/serve.py @@ -14,6 +14,7 @@ from ultralytics.engine.results import Results class UltralyticsRequest(BaseModel): image: str + class UltralyticsResponse(BaseModel): status: str = "success" results: List[List[Dict]] @@ -24,7 +25,7 @@ class YOLOServe(ls.LitAPI): """ Litserve API for YOLO model: Call order is: - setup -> batch -> decode_request -> predict -> unbatch -> encode_response + setup -> batch -> decode_request -> predict -> unbatch -> encode_response. Args: model (str): Model name to use @@ -34,7 +35,7 @@ class YOLOServe(ls.LitAPI): def setup(self, device): self.model = YOLO(model=self.model_name) - + def batch(self, inputs): return list(inputs) @@ -44,18 +45,16 @@ class YOLOServe(ls.LitAPI): image = Image.open(io.BytesIO(img_data)) image_array = np.array(image) return image_array - + def predict(self, x): result = self.model(x) return result def unbatch(self, output): return list(output) - + def encode_response(self, result: List[Results]) -> UltralyticsResponse: return UltralyticsResponse(results=[r.to_dict() for r in result]) - - def run(args):