Skip to content

Commit

Permalink
Merge pull request #832 from insight-platform/830-symmetric-padding-s…
Browse files Browse the repository at this point in the history
…upport

Symmetric padding property support
  • Loading branch information
placccebo authored Aug 7, 2024
2 parents dd8174f + 8059893 commit 2b5e9e4
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion samples/bypass_model/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ A result video can be viewed:
- in a player using `rtsp://127.0.0.1:554/stream/video-with-preprocessed-frame

The video consists of original video stream and the pre-processed video stream side by side from left to right. The white background highlights the original video frame because its size is different from the size of the pre-processed frame.
The pre-processed frame has a black background at the bottom, which is the result of the `maintain_aspect_ratio` flag.
The pre-processed frame has a black background to match the aspect ratio of the original frame, i.e. `maintain_aspect_ratio` flag is set to `true`. The frame is centered on the background, as the `symmetric_padding` flag is set to `true`.

Example output frame:
![](assets/result.jpg)
Expand Down
4 changes: 2 additions & 2 deletions samples/bypass_model/assets/result.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions samples/bypass_model/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pipeline:
shape: ${parameters.result_shape}
# preprocessing settings
maintain_aspect_ratio: true
symmetric_padding: true

# configuration of model output
output:
Expand Down
5 changes: 4 additions & 1 deletion savant/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ class ModelInput:
"""Indicates whether the input preprocessing should maintain image aspect ratio.
"""

# TODO: Add `symmetric-padding` support.
symmetric_padding: bool = False
"""Indicates whether the input preprocessing should symmetrically pad the image when it's scaled.
By default the images are padded asymmetrically.
"""

# TODO: Enhance scaling options
# range: Tuple[] = (0, 255) or (0.0, 1.0)
Expand Down
6 changes: 6 additions & 0 deletions savant/deepstream/nvinfer/file_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ class _FieldMap:
lambda v: bool(int(v)),
0,
),
_FieldMap(
'symmetric-padding',
'input.symmetric_padding',
lambda v: bool(int(v)),
0,
),
_FieldMap('net-scale-factor', 'input.scale_factor', float, 1.0),
_FieldMap(
'offsets',
Expand Down
3 changes: 0 additions & 3 deletions savant/deepstream/nvinfer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ class NvInferModel(Model):
"""Specifies the number of consecutive batches to be skipped for inference."""

# TODO: Add support for Gst-nvinfer props
# symmetric-padding (with maintain-aspect-ratio) -
# Indicates whether to pad image symmetrically while scaling input.
# DeepStream pads the images asymmetrically by default.
# network-input-order - Order of the network input layer

workspace_size: int = 6144
Expand Down

0 comments on commit 2b5e9e4

Please sign in to comment.