diff --git a/deepomatic/api/inputs.py b/deepomatic/api/inputs.py index 5f0a338..4655ae4 100644 --- a/deepomatic/api/inputs.py +++ b/deepomatic/api/inputs.py @@ -25,6 +25,7 @@ import sys import copy import base64 +import json from deepomatic.api.exceptions import DeepomaticException @@ -102,6 +103,9 @@ def get_input(self): } if self.bbox is not None: image['bbox'] = self.bbox + if self.need_multipart and isinstance(image['bbox'], dict): + # Convert the bbox to a string to allow serialization + image['bbox'] = json.dumps(image['bbox']) if self.polygon is not None: image['polygon'] = self.polygon return { diff --git a/tests/test_client.py b/tests/test_client.py index d02b315..bb5e935 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -18,6 +18,7 @@ from deepomatic.api.http_retry import HTTPRetry from deepomatic.api.inputs import ImageInput from deepomatic.api.version import __title__, __version__ +from io import BytesIO from requests.exceptions import ConnectionError, MissingSchema from tenacity import RetryError, stop_after_delay @@ -259,6 +260,15 @@ def test_create_custom_reco_and_infer(self, client, custom_network): max_predictions=3) assert inference_schema(3, 0, 'golden retriever', 0.5) == result + # Test a binary image via multipart + response = requests.get(DEMO_URL) + img_data = BytesIO(response.content) + result = version.inference(inputs=[ImageInput(img_data, encoding='binary', + bbox={"xmin": 0.2, "ymin": 0.2, "xmax": 0.8, "ymax": 0.8})], + show_discarded=True, + max_predictions=3) + assert inference_schema(3, 0, 'golden retriever', 0.5) == result + versions = spec.versions() assert versions.count() > 0 data = versions.data()