Skip to content

Commit

Permalink
Fixing unit tests and code related recent PySDK input shape refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-nn committed Dec 31, 2024
1 parent b50ad82 commit d467c34
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 32 deletions.
8 changes: 5 additions & 3 deletions degirum_tools/compound_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,12 @@ def _adjust_bbox(self, bbox, image_sz):
bbox: bbox coordinates in [x1, y1, x2, y2] format
image_sz: image size in (width, height) format
"""

_, h, w, _ = self.model2.input_shape[0]
return extend_bbox(
bbox,
self._crop_extent_option,
self._crop_extent,
self.model2.model_info.InputW[0] / self.model2.model_info.InputH[0],
w / h,
image_sz,
)

Expand Down Expand Up @@ -548,7 +548,9 @@ def _finalize_current_result(self, result1):
)

if isinstance(self._current_result.info, FrameInfo):
self._current_result._frame_info = self._current_result.info.original_info
self._current_result._frame_info = (
self._current_result.info.original_info
)

return self._current_result
return None
Expand Down
13 changes: 8 additions & 5 deletions degirum_tools/tile_compound_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
NmsOptions,
MotionDetectOptions,
CroppingAndDetectingCompoundModel,
detect_motion)
detect_motion,
)


class _TileInfo:
Expand Down Expand Up @@ -98,9 +99,9 @@ def __getattr__(self, attr):
return getattr(self._model2, attr)

def _calculate_tile_parameters(self) -> List[float]:
model_aspect_ratio = (
self._model2.model_info.InputW[0] / self._model2.model_info.InputH[0]
)

_, h, w, _ = self._model2.input_shape[0]
model_aspect_ratio = w / h

tile_width = self._width / (
self._cols - self._overlap_percent * (self._cols - 1)
Expand Down Expand Up @@ -694,7 +695,9 @@ def _finalize_current_result(self, result1):
)

if isinstance(self._current_result.info, FrameInfo):
self._current_result._frame_info = self._current_result.info.original_info
self._current_result._frame_info = (
self._current_result.info.original_info
)

return self._current_result
return None
Expand Down
7 changes: 7 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def zoo_dir():
return os.path.join(os.path.dirname(__file__), "model-zoo")


@pytest.fixture()
def dummy_model(zoo_dir):
"""Load dummy model from local zoo"""
with dg.load_model("dummy", dg.LOCAL, zoo_dir) as model:
yield model


@pytest.fixture()
def detection_model_name():
"""Detection model name"""
Expand Down
29 changes: 5 additions & 24 deletions test/test_tiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def test_bf():
assert len(fusion_result) == 1


def test_generate_tiles():
def test_generate_tiles(dummy_model):
import degirum as dg

"""
Tests for generating tiles.
Includes variations of aspect ratios for the model and tiles, rows/cols, and overlap percentages.
Expand All @@ -73,29 +75,8 @@ def test_generate_tiles():
overlap_tolerance = 0.01
aspect_ratio_tolerance = 0.002

class DummyModelParams:
InputW = [640]
InputH = [640]
InputC = [3]
InputImgFmt = ["RAW"]
InputRawDataType = ["DG_UINT8"]
InputColorSpace = ["RGB"]

class DummyModel:
image_backend = "auto"
input_image_format = "RAW"
_model_parameters = DummyModelParams()
model_info = _model_parameters
overlay_color = (0, 0, 0)
overlay_line_width = 1.0
overlay_show_labels = True
overlay_show_probabilities = True
overlay_alpha = False
overlay_font_scale = 1.0
input_letterbox_fill_color = (0, 0, 0)
label_dictionary = {0: 0}

dummy_model = DummyModel()
dummy_model._model_parameters.InputW = [640]
dummy_model._model_parameters.InputH = [640]

# 1 x 1 no overlap square, matching aspect ratio, aspect ratio = 1
tile_extractor = TileExtractorPseudoModel(1, 1, 0.0, dummy_model)
Expand Down

0 comments on commit d467c34

Please sign in to comment.