diff options
author | Dwight Lidman <dwight.lidman@arm.com> | 2021-10-08 14:26:54 +0200 |
---|---|---|
committer | patrik.gustavsson <patrik.gustavsson@arm.com> | 2021-10-14 05:31:45 +0000 |
commit | 4caf29db9038c610702d3528763314143f2ee1ee (patch) | |
tree | 587987a59e94bb7db1026bd362318236365f244d /ethosu/vela | |
parent | 6bf1613c5894d81849dd12b5be6145c1f24caca2 (diff) | |
download | ethos-u-vela-4caf29db9038c610702d3528763314143f2ee1ee.tar.gz |
MLBEDSW-5361 - Fix per-axis quantization support
This commit fixes a number of bugs where per-axis
quantization would make Vela crash and would not
be properly recognized.
Signed-off-by: Dwight Lidman <dwight.lidman@arm.com>
Change-Id: I50a461d200274b43ec76f3a7357bf66db6d49964
Diffstat (limited to 'ethosu/vela')
-rw-r--r-- | ethosu/vela/tensor.py | 6 | ||||
-rw-r--r-- | ethosu/vela/tflite_model_semantic.py | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/ethosu/vela/tensor.py b/ethosu/vela/tensor.py index 2e70d72e..d62ebc8e 100644 --- a/ethosu/vela/tensor.py +++ b/ethosu/vela/tensor.py @@ -270,12 +270,12 @@ class QuantizationParameters: def is_valid(self) -> bool: # quantisation parameters are consider valid if they have a scale and zero point - return None not in (self.scale_f32, self.zero_point) + return self.scale_f32 is not None and self.zero_point is not None def is_per_axis(self) -> bool: - """Returns True if either the scale, zero point, minimum or maximum values are arrays""" + """Returns True if either the scale, zero point, minimum or maximum values have more than one value""" for attr in ("scale_f32", "zero_point", "min", "max"): - if isinstance(getattr(self, attr), np.ndarray): + if np.size(getattr(self, attr)) > 1: return True return False diff --git a/ethosu/vela/tflite_model_semantic.py b/ethosu/vela/tflite_model_semantic.py index 6e2467bb..51d1f072 100644 --- a/ethosu/vela/tflite_model_semantic.py +++ b/ethosu/vela/tflite_model_semantic.py @@ -282,7 +282,7 @@ class TFLiteSemantic: "Input and Output tensors must have quantization scales that fit within float32 precision" if op.ofm is not None and op.ofm.is_quantized(): ofm_scale = op.ofm.quantization.scale_f32 - if ofm_scale < np.finfo(np.float32).tiny: + if np.any(ofm_scale < np.finfo(np.float32).tiny): return ( False, f"The quantization scale of the output tensor is {ofm_scale}, " @@ -290,7 +290,7 @@ class TFLiteSemantic: ) if op.ifm is not None and op.ifm.is_quantized(): ifm_scale = op.ifm.quantization.scale_f32 - if np.isinf(ifm_scale / ofm_scale): + if np.any(np.isinf(ifm_scale / ofm_scale)): return ( False, f"IFM scale divided by OFM scale is infinite, ifm_scale={ifm_scale} ofm_scale={ofm_scale}", |