Skip to content

Commit 8b7457a

Browse files
authored
fix: GETI-422 ssd dynamic model with prepropcessing fix (#430)
* fix * tests
1 parent 599ddc2 commit 8b7457a

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

src/model_api/models/image_model.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,23 +220,32 @@ def preprocess(self, inputs: np.ndarray) -> list[dict]:
220220
}
221221
- the input metadata, which might be used in `postprocess` method
222222
"""
223-
if self._is_dynamic:
223+
original_shape = inputs.shape
224+
225+
if self.embedded_processing:
226+
processed_image = inputs[None]
227+
if self._is_dynamic:
228+
h, w, c = inputs.shape
229+
resized_shape = (w, h, c)
230+
else:
231+
resized_shape = (self.w, self.h, self.c)
232+
elif self._is_dynamic:
224233
h, w, c = inputs.shape
225234
resized_shape = (w, h, c)
226235
processed_image = self.input_transform(inputs)
227236
processed_image = self._change_layout(processed_image)
228237
else:
238+
# Fixed model without embedded preprocessing
229239
resized_shape = (self.w, self.h, self.c)
230-
if self.embedded_processing:
231-
processed_image = inputs[None]
232-
else:
233-
processed_image = self.input_transform(inputs)
234-
processed_image = self._change_layout(processed_image)
240+
241+
resized_image = self.resize(inputs, (self.w, self.h), pad_value=self.pad_value)
242+
processed_image = self.input_transform(resized_image)
243+
processed_image = self._change_layout(processed_image)
235244

236245
return [
237246
{self.image_blob_name: processed_image},
238247
{
239-
"original_shape": inputs.shape,
248+
"original_shape": original_shape,
240249
"resized_shape": resized_shape,
241250
},
242251
]

tests/accuracy/images.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
},
2020
{
2121
"name": "images/Slide4.PNG"
22+
},
23+
{
24+
"name": "images/cards.png"
2225
}
2326
]

tests/accuracy/prepare_data.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,28 @@
1111
import httpx
1212

1313

14+
async def download_single_image(client, url, filename):
15+
image = await client.get(url)
16+
with Path(filename).open("wb") as im:
17+
im.write(image.content)
18+
19+
1420
async def download_images(data_dir):
1521
async with httpx.AsyncClient(timeout=20.0) as client:
16-
COCO128_URL = "https://ultralytics.com/assets/coco128.zip"
22+
COCO128_URL = "https://storage.geti.intel.com/geti_predict/test/images/coco128.zip"
1723
archive = await client.get(COCO128_URL, follow_redirects=True)
1824
with ZipFile(BytesIO(archive.content)) as zfile:
1925
zfile.extractall(data_dir)
20-
image = await client.get(
21-
"https://raw.githubusercontent.com/Shenggan/BCCD_Dataset/master/BCCD/JPEGImages/BloodImage_00007.jpg",
22-
)
23-
with Path(data_dir / "BloodImage_00007.jpg").open("wb") as im:
24-
im.write(image.content)
26+
27+
image_downloads = [
28+
(
29+
"https://storage.geti.intel.com/geti_predict/test/images/BloodImage_00007.jpg",
30+
data_dir / "BloodImage_00007.jpg",
31+
),
32+
("https://storage.geti.intel.com/geti_predict/test/images/cards.png", data_dir / "cards.png"),
33+
]
34+
35+
await asyncio.gather(*[download_single_image(client, url, filename) for url, filename in image_downloads])
2536

2637

2738
async def stream_file(client, url, filename):
@@ -155,6 +166,7 @@ async def main():
155166
download_otx_model(client, otx_models_dir, "sam_vit_b_zsl_decoder"),
156167
download_otx_model(client, otx_models_dir, "rtmpose_tiny"),
157168
download_otx_model(client, otx_models_dir, "segnext_t_tiling"),
169+
download_otx_model(client, otx_models_dir, "ssd-card-detection"),
158170
download_anomalib_model(client, anomalib_models_dir, "padim"),
159171
download_anomalib_model(client, anomalib_models_dir, "stfpm"),
160172
download_anomalib_model(client, anomalib_models_dir, "uflow"),

tests/accuracy/public_scope.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,5 +477,17 @@
477477
]
478478
}
479479
]
480+
},
481+
{
482+
"name": "otx_models/ssd-card-detection.xml",
483+
"type": "DetectionModel",
484+
"test_data": [
485+
{
486+
"image": "coco128/images/train2017/000000000074.jpg",
487+
"reference": [
488+
"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]"
489+
]
490+
}
491+
]
480492
}
481493
]

0 commit comments

Comments
 (0)