From b279844cae93353410210597535fdbf495cd0498 Mon Sep 17 00:00:00 2001 From: Tim Hall Date: Thu, 24 Jun 2021 19:31:38 +0100 Subject: MLBEDSW-4819: MLCE: weight_compressor int has no attribute astype - Added type checking so that the correct type conversion can be used Signed-off-by: Tim Hall Change-Id: Ia83f46029fac7bad63844c090b87d23c2072b105 --- ethosu/vela/weight_compressor.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ethosu/vela') diff --git a/ethosu/vela/weight_compressor.py b/ethosu/vela/weight_compressor.py index 5f211393..4ba3dee3 100644 --- a/ethosu/vela/weight_compressor.py +++ b/ethosu/vela/weight_compressor.py @@ -315,7 +315,12 @@ def encode_weight_and_scale_tensor( # Early zero-point correction quant_buf = weight_tens.quant_values.astype(np.int16) - weights = quant_buf - weight_tens.quantization.zero_point.astype(np.int16) + # the zero point can be either a native or numpy type + if isinstance(weight_tens.quantization.zero_point, (int, float)): + zero_point = np.int16(weight_tens.quantization.zero_point) + else: + zero_point = weight_tens.quantization.zero_point.astype(np.int16) + weights = quant_buf - zero_point if len(weights.shape) == 2: weights = np.expand_dims(np.expand_dims(weights, axis=0), axis=0) -- cgit v1.2.1