From 65d5d2ddf77c69e76643e40440aa986defe6d0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89anna=20=C3=93=20Cath=C3=A1in?= Date: Fri, 20 Aug 2021 14:41:38 +0100 Subject: MLECO-2207 Fix issue with the PyArmNN OD example, for FP32 models. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I6b8887f0b3e23c0c1529719e20b17a9f55ccf4e7 Signed-off-by: Éanna Ó Catháin --- python/pyarmnn/examples/common/cv_utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'python') 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. -- cgit v1.2.1