diff options
Diffstat (limited to 'python/pyarmnn/examples/common/cv_utils.py')
-rw-r--r-- | python/pyarmnn/examples/common/cv_utils.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/python/pyarmnn/examples/common/cv_utils.py b/python/pyarmnn/examples/common/cv_utils.py index 61aa46c3d7..fd848b8b0f 100644 --- a/python/pyarmnn/examples/common/cv_utils.py +++ b/python/pyarmnn/examples/common/cv_utils.py @@ -32,7 +32,12 @@ def preprocess(frame: np.ndarray, input_binding_info: tuple): resized_frame = resize_with_aspect_ratio(frame, input_binding_info) # Expand dimensions and convert data type to match model input - data_type = np.float32 if input_binding_info[1].GetDataType() == ann.DataType_Float32 else np.uint8 + if input_binding_info[1].GetDataType() == ann.DataType_Float32: + data_type = np.float32 + resized_frame = resized_frame.astype("float32")/255 + else: + data_type = np.uint8 + resized_frame = np.expand_dims(np.asarray(resized_frame, dtype=data_type), axis=0) assert resized_frame.shape == tuple(input_binding_info[1].GetShape()) @@ -40,6 +45,7 @@ def preprocess(frame: np.ndarray, input_binding_info: tuple): return input_tensors + def resize_with_aspect_ratio(frame: np.ndarray, input_binding_info: tuple): """ Resizes frame while maintaining aspect ratio, padding any empty space. |