From 36009059e7f837b247025519043ca77b198a77ee Mon Sep 17 00:00:00 2001 From: luxuhui Date: Mon, 2 Mar 2020 09:03:54 +0800 Subject: [PATCH] fix prelu&validate bug N/A Signed-off-by: Luxuhui --- tools/python/transform/transformer.py | 2 +- tools/validate.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/python/transform/transformer.py b/tools/python/transform/transformer.py index 9b26d487..a10b8701 100644 --- a/tools/python/transform/transformer.py +++ b/tools/python/transform/transformer.py @@ -963,7 +963,7 @@ class Transformer(base_converter.ConverterInterface): if consumer_op.type == MaceOp.Activation.name \ and ConverterUtil.get_arg( consumer_op, - MaceKeyword.mace_activation_type_str).s != 'PRELU': + MaceKeyword.mace_activation_type_str).s != b'PRELU': # noqa print("Fold activation: %s(%s)" % (op.name, op.type)) op.name = consumer_op.name op.output[0] = consumer_op.output[0] diff --git a/tools/validate.py b/tools/validate.py index 9980a0a9..8b8a9e82 100644 --- a/tools/validate.py +++ b/tools/validate.py @@ -64,7 +64,16 @@ def calculate_similarity(u, v, data_type=np.float64): u = u.astype(data_type) if v.dtype is not data_type: v = v.astype(data_type) - return np.dot(u, v) / (np.linalg.norm(u) * np.linalg.norm(v)) + u_norm = np.linalg.norm(u) + v_norm = np.linalg.norm(v) + norm = u_norm * v_norm + if norm == 0: + if u_norm == 0 and v_norm == 0: + return 1 + else: + return 0 + else: + return np.dot(u, v) / norm def calculate_pixel_accuracy(out_value, mace_out_value): -- GitLab