Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/model_api/models/image_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
]
Expand Down
3 changes: 3 additions & 0 deletions tests/accuracy/images.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
},
{
"name": "images/Slide4.PNG"
},
{
"name": "images/cards.png"
}
]
24 changes: 18 additions & 6 deletions tests/accuracy/prepare_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"),
Expand Down
12 changes: 12 additions & 0 deletions tests/accuracy/public_scope.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
]
}
]
}
]