aboutsummaryrefslogtreecommitdiff
path: root/python/pyarmnn/examples/common/cv_utils.py
diff options
context:
space:
mode:
authoralexander <alexander.efremov@arm.com>2021-07-16 11:30:56 +0100
committerJim Flynn <jim.flynn@arm.com>2022-02-04 09:55:21 +0000
commitf42f56870c6201a876f025a423eb5540d7438e83 (patch)
treee8e57e371c851cbb9a51a2f3ec35059addd2e93e /python/pyarmnn/examples/common/cv_utils.py
parent9d74ba6e85a043e9603445e062315f5c4965fbd6 (diff)
downloadarmnn-f42f56870c6201a876f025a423eb5540d7438e83.tar.gz
MLECO-2079 Adding the python KWS example
Signed-off-by: Eanna O Cathain <eanna.ocathain@arm.com> Change-Id: Ie1463aaeb5e3cade22df8f560ae99a8e1c4a9c17
Diffstat (limited to 'python/pyarmnn/examples/common/cv_utils.py')
-rw-r--r--python/pyarmnn/examples/common/cv_utils.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/python/pyarmnn/examples/common/cv_utils.py b/python/pyarmnn/examples/common/cv_utils.py
index fd848b8b0f..e12ff50548 100644
--- a/python/pyarmnn/examples/common/cv_utils.py
+++ b/python/pyarmnn/examples/common/cv_utils.py
@@ -1,4 +1,4 @@
-# Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+# Copyright © 2020-2021 Arm Ltd and Contributors. All rights reserved.
# SPDX-License-Identifier: MIT
"""
@@ -14,7 +14,7 @@ import numpy as np
import pyarmnn as ann
-def preprocess(frame: np.ndarray, input_binding_info: tuple):
+def preprocess(frame: np.ndarray, input_binding_info: tuple, is_normalised: bool):
"""
Takes a frame, resizes, swaps channels and converts data type to match
model input layer. The converted frame is wrapped in a const tensor
@@ -23,6 +23,7 @@ def preprocess(frame: np.ndarray, input_binding_info: tuple):
Args:
frame: Captured frame from video.
input_binding_info: Contains shape and data type of model input layer.
+ is_normalised: if the input layer expects normalised data
Returns:
Input tensor.
@@ -34,7 +35,8 @@ def preprocess(frame: np.ndarray, input_binding_info: tuple):
# Expand dimensions and convert data type to match model input
if input_binding_info[1].GetDataType() == ann.DataType_Float32:
data_type = np.float32
- resized_frame = resized_frame.astype("float32")/255
+ if is_normalised:
+ resized_frame = resized_frame.astype("float32")/255
else:
data_type = np.uint8