diff --git a/src/model_api/models/image_model.py b/src/model_api/models/image_model.py index 906d9cb0..9e5dd138 100644 --- a/src/model_api/models/image_model.py +++ b/src/model_api/models/image_model.py @@ -220,23 +220,32 @@ def preprocess(self, inputs: np.ndarray) -> list[dict]: } - the input metadata, which might be used in `postprocess` method """ - if self._is_dynamic: + original_shape = inputs.shape + + if self.embedded_processing: + processed_image = inputs[None] + if self._is_dynamic: + h, w, c = inputs.shape + resized_shape = (w, h, c) + else: + resized_shape = (self.w, self.h, self.c) + elif self._is_dynamic: h, w, c = inputs.shape resized_shape = (w, h, c) processed_image = self.input_transform(inputs) processed_image = self._change_layout(processed_image) else: + # Fixed model without embedded preprocessing resized_shape = (self.w, self.h, self.c) - if self.embedded_processing: - processed_image = inputs[None] - else: - processed_image = self.input_transform(inputs) - processed_image = self._change_layout(processed_image) + + resized_image = self.resize(inputs, (self.w, self.h), pad_value=self.pad_value) + processed_image = self.input_transform(resized_image) + processed_image = self._change_layout(processed_image) return [ {self.image_blob_name: processed_image}, { - "original_shape": inputs.shape, + "original_shape": original_shape, "resized_shape": resized_shape, }, ] diff --git a/tests/accuracy/images.json b/tests/accuracy/images.json index 4e3ae081..4e023896 100644 --- a/tests/accuracy/images.json +++ b/tests/accuracy/images.json @@ -19,5 +19,8 @@ }, { "name": "images/Slide4.PNG" + }, + { + "name": "images/cards.png" } ] diff --git a/tests/accuracy/prepare_data.py b/tests/accuracy/prepare_data.py index 418b0da4..7cd3d3a7 100644 --- a/tests/accuracy/prepare_data.py +++ b/tests/accuracy/prepare_data.py @@ -11,17 +11,28 @@ import httpx +async def download_single_image(client, url, filename): + image = await client.get(url) + with Path(filename).open("wb") as im: + im.write(image.content) + + async def download_images(data_dir): async with httpx.AsyncClient(timeout=20.0) as client: - COCO128_URL = "https://ultralytics.com/assets/coco128.zip" + COCO128_URL = "https://storage.geti.intel.com/geti_predict/test/images/coco128.zip" archive = await client.get(COCO128_URL, follow_redirects=True) with ZipFile(BytesIO(archive.content)) as zfile: zfile.extractall(data_dir) - image = await client.get( - "https://raw.githubusercontent.com/Shenggan/BCCD_Dataset/master/BCCD/JPEGImages/BloodImage_00007.jpg", - ) - with Path(data_dir / "BloodImage_00007.jpg").open("wb") as im: - im.write(image.content) + + image_downloads = [ + ( + "https://storage.geti.intel.com/geti_predict/test/images/BloodImage_00007.jpg", + data_dir / "BloodImage_00007.jpg", + ), + ("https://storage.geti.intel.com/geti_predict/test/images/cards.png", data_dir / "cards.png"), + ] + + await asyncio.gather(*[download_single_image(client, url, filename) for url, filename in image_downloads]) async def stream_file(client, url, filename): @@ -155,6 +166,7 @@ async def main(): download_otx_model(client, otx_models_dir, "sam_vit_b_zsl_decoder"), download_otx_model(client, otx_models_dir, "rtmpose_tiny"), download_otx_model(client, otx_models_dir, "segnext_t_tiling"), + download_otx_model(client, otx_models_dir, "ssd-card-detection"), download_anomalib_model(client, anomalib_models_dir, "padim"), download_anomalib_model(client, anomalib_models_dir, "stfpm"), download_anomalib_model(client, anomalib_models_dir, "uflow"), diff --git a/tests/accuracy/public_scope.json b/tests/accuracy/public_scope.json index 2d86da05..2544954a 100644 --- a/tests/accuracy/public_scope.json +++ b/tests/accuracy/public_scope.json @@ -477,5 +477,17 @@ ] } ] + }, + { + "name": "otx_models/ssd-card-detection.xml", + "type": "DetectionModel", + "test_data": [ + { + "image": "coco128/images/train2017/000000000074.jpg", + "reference": [ + "79, 281, 318, 371, 1 (Diamonds): 0.700; 0, 75, 172, 333, 1 (Diamonds): 0.575; 109, 6, 625, 224, 3 (Hearts): 0.547; [0]; [0]" + ] + } + ] } ]