@@ -68,12 +68,18 @@ def __init__(self, inference_adapter: InferenceAdapter, configuration: dict = {}
6868 self .embedded_processing : bool
6969 self .labels : list [str ]
7070
71- self ._is_dynamic = False
7271 self .nchw_layout = self .inputs [self .image_blob_name ].layout == "NCHW"
7372 if self .nchw_layout :
7473 self .n , self .c , self .h , self .w = self .inputs [self .image_blob_name ].shape
7574 else :
7675 self .n , self .h , self .w , self .c = self .inputs [self .image_blob_name ].shape
76+
77+ self ._is_dynamic = False
78+ if self .h == - 1 or self .w == - 1 or self .n == - 1 :
79+ self ._is_dynamic = True
80+ if self .n == - 1 :
81+ self .n = 1
82+
7783 self .resize = RESIZE_TYPES [self .resize_type ]
7884 self .input_transform = InputTransform (
7985 self .reverse_input_channels ,
@@ -84,7 +90,7 @@ def __init__(self, inference_adapter: InferenceAdapter, configuration: dict = {}
8490 layout = self .inputs [self .image_blob_name ].layout
8591 if self .embedded_processing :
8692 self .h , self .w = self .orig_height , self .orig_width
87- else :
93+ elif not self . _is_dynamic :
8894 inference_adapter .embed_preprocessing (
8995 layout = layout ,
9096 resize_mode = self .resize_type ,
@@ -231,9 +237,13 @@ def _change_layout(self, image: np.ndarray) -> np.ndarray:
231237 Returns:
232238 - the image with layout aligned with the model layout
233239 """
240+ h , w , c = image .shape if self ._is_dynamic else (self .h , self .w , self .c )
241+
242+ # For fixed models, use the predefined dimensions
234243 if self .nchw_layout :
235244 image = image .transpose ((2 , 0 , 1 )) # HWC->CHW
236- image = image .reshape ((1 , self . c , self . h , self . w ))
245+ image = image .reshape ((1 , c , h , w ))
237246 else :
238- image = image .reshape ((1 , self .h , self .w , self .c ))
247+ image = image .reshape ((1 , h , w , c ))
248+
239249 return image
0 commit comments