Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Adapt YOLOv5 pipeline to handle models with dynamic HxW #967

Merged
merged 2 commits into from
Mar 21, 2023
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
6 changes: 6 additions & 0 deletions src/deepsparse/yolo/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ class properties into an inference ready onnx file to be compiled by the
model_path = model_to_path(self.model_path)
if self._image_size is None:
self._image_size = get_onnx_expected_image_shape(onnx.load(model_path))
if self._image_size == (0, 0):
raise ValueError(
"The model does not have a static image size shape. "
"Specify the expected image size by passing the"
"`image_size` argument to the pipeline."
)
else:
# override model input shape to given image size
if isinstance(self._image_size, int):
Expand Down
2 changes: 2 additions & 0 deletions src/deepsparse/yolo/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ def modify_yolo_onnx_input_shape(
model_input = model.graph.input[0]

initial_x, initial_y = get_onnx_expected_image_shape(model)
if initial_x == initial_y == 0:
initial_x, initial_y = image_shape

if not (isinstance(initial_x, int) and isinstance(initial_y, int)):
return model_path, None # model graph does not have static integer input shape
Expand Down