Skip to content
This repository was archived by the owner on May 12, 2024. It is now read-only.

Commit 5fd9799

Browse files
committed
Fixed the decision logic of INT8 inverse quantization
1 parent c8d3722 commit 5fd9799

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ARG CPVER=cp38
77
ARG OPENVINOVER=2021.4.582
88
ARG OPENVINOROOTDIR=/opt/intel/openvino_2021
99
ARG TENSORRTVER=cuda11.3-trt8.0.1.6-ga-20210626
10-
ARG APPVER=v1.11.3
10+
ARG APPVER=v1.11.4
1111
ARG wkdir=/home/user
1212

1313
# dash -> bash

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
setup(
1212
name="tflite2tensorflow",
1313
scripts=scripts,
14-
version="1.11.3",
14+
version="1.11.4",
1515
description="Generate saved_model, tfjs, tf-trt, EdgeTPU, CoreML, quantized tflite, ONNX, OpenVINO, Myriad Inference Engine blob and .pb from .tflite.",
1616
long_description=long_description,
1717
long_description_content_type="text/markdown",

tflite2tensorflow/tflite2tensorflow.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,13 @@ def get_op_name(name):
495495
return op_name
496496

497497
def backward_quantization(op_detail, op):
498-
scales = np.asarray(op_detail["quantization"][0], dtype=np.float32)
499-
zero_points = np.asarray(op_detail["quantization"][1], dtype=np.float32)
500-
return (op - zero_points) * scales
498+
if not 'quantization' in op_detail or \
499+
(input_detail['quantization'][0] == 0.0 and input_detail['quantization'][1] == 0):
500+
return op
501+
else:
502+
scales = np.asarray(op_detail['quantization'][0], dtype=np.float32)
503+
zero_points = np.asarray(op_detail['quantization'][1], dtype=np.float32)
504+
return (op - zero_points) * scales
501505

502506
def searh_json_tensor_detail(name):
503507
tensor_detail_dict = None
@@ -518,16 +522,16 @@ def searh_json_tensor_detail(name):
518522

519523
for input_detail in input_details:
520524
if not 'quantization' in input_detail or \
521-
(input_detail["quantization"][0] == 0.0 and input_detail["quantization"][1] == 0):
525+
(input_detail['quantization'][0] == 0.0 and input_detail['quantization'][1] == 0):
522526

523527
tensors[input_detail['index']] = tf.placeholder(
524528
dtype=input_detail['dtype'],
525529
shape=input_detail['shape'],
526530
name=get_op_name(input_detail['name']))
527531

528532
else:
529-
scales = np.asarray(input_detail["quantization"][0], dtype=np.float32)
530-
zero_points = np.asarray(input_detail["quantization"][1], dtype=np.float32)
533+
scales = np.asarray(input_detail['quantization'][0], dtype=np.float32)
534+
zero_points = np.asarray(input_detail['quantization'][1], dtype=np.float32)
531535
inp = tf.placeholder(
532536
dtype=np.float32,
533537
shape=input_detail['shape'],

0 commit comments

Comments
 (0)