Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tflite:Error in post process calculation #7451

Open
ai-libo opened this issue Aug 15, 2019 · 6 comments
Open

Tflite:Error in post process calculation #7451

ai-libo opened this issue Aug 15, 2019 · 6 comments
Assignees
Labels
models:research models that come under research directory

Comments

@ai-libo
Copy link

ai-libo commented Aug 15, 2019

System information

Model_Task:models-master/research/object_detection
MODEL_name : mobilenetV2_ssdlite_fakequantization
OS:centos 7

== check python ===================================================
python version: 3.6.6
python compiler version: GCC 4.8.5 20150623 (Red Hat 4.8.5-36)
python implementation: CPython
== check os platform ===============================================
os: Linux
os kernel version: #1 SMP Fri Apr 20 16:44:24 UTC 2018
os release version: 3.10.0-862.el7.x86_64
os platform: Linux-3.10.0-862.el7.x86_64-x86_64-with-centos-7.5.1804-Core
linux distribution: ('CentOS Linux', '7.5.1804', 'Core')
linux os distribution: ('centos', '7.5.1804', 'Core')
uname: uname_result(system='Linux', node='VM_12_5_centos', release='3.10.0-862.el7.x86_64', version='#1 SMP Fri Apr 20 16:44:24 UTC 2018', machine='x86_64', processor='x86_64')
architecture: ('64bit', 'ELF')
machine: x86_64
== are we in docker =============================================
No
== compiler =====================================================
c++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
== check pips ===================================================
numpy 1.14.5
protobuf 3.7.1
tensorflow-gpu 1.10.0
== check for virtualenv =========================================
False
== tensorflow import ============================================
tf.version.VERSION = 1.10.0
tf.version.COMPILER_VERSION = 4.8.5
Sanity check: array([1], dtype=int32)
== cuda libs ===================================================
/usr/local/python3/lib/python3.6/site-packages/torch/lib/libcudart-f7fdd8d7.so.9.0
/usr/local/cuda-9.0/doc/man/man7/libcudart.so.7
/usr/local/cuda-9.0/doc/man/man7/libcudart.7
/usr/local/cuda-9.0/lib64/libcudart_static.a
/usr/local/cuda-9.0/lib64/libcudart.so.9.0.103
CUDA Version 9.0.103
cudnn version:7.0.5
== tensorflow installed from info ==================

== python version ==============================================
(major, minor, micro, releaselevel, serial)
(3, 6, 6, 'final', 0)

== bazel version ===============================================
Build label: 0.28.1
Build time: Fri Jul 19 00:00:00 2019 (1563494400)
Build timestamp: 1563494400
Build timestamp as int: 1563494400

Describe the problem

First of all, the files frozen_inference_graph.pb I generated on the server side can be correctly reasoned out and properly post-processed
result:
test_1
However, when I generated the tflite file, I found wrong results. After analyzing the conat and concat_1 layer, that is, before post-processing, the calculated results were correct in tflite, but after post-processing, the values would become abnormal.
The script and results are as follows:
toco --graph_def_file=./tflite_graph_300_300.pb --output_file=./detect_300_300_quantize.tflite --input_shapes=1,300,300,3 --input_arrays=normalized_input_image_tensor --output_arrays='TFLite_Detection_PostProcess','TFLite_Detection_PostProcess:1','TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3' --inference_type=QUANTIZED_UINT8 --inference_input_type=QUANTIZED_UINT8 --output_format=TFLITE --dump_graphviz_dir=./ --default_ranges_min=0 --default_ranges_max=6 --mean_values=128 --std_dev_values=127
8d139d5b8d8f48c3d01e77b7150b1c9
image
Meanwhile, I also tried to generate in different versions of tf. Since I used CUDA9.0, before the main test of 1.13.1, even though I used --allow_custom_ops, there would still be" Op type not registered 'TFLite_Detection_PostProcess' in 1.10.0" .Therefore, I upgraded to 1.11.0, 1.12.0 and 1.14.0. The conversion of error resolution was normal, but after positioning, I found that the calculation results of the post-processing All the above were wrong.But it does make sense to run the official demo.
This is a problem with both quantization and floating inference point reasoning, I suspect "--allow_custom_ops" is successfully converted in tflite, but there are still BUGS causing incorrect calculations, so does anyone have this problem?Your comments are welcome

The tflite_test file / test Code

test_file.zip
this is my test code:
`interpreter = tf.contrib.lite.Interpreter(model_path=model_path)
interpreter.allocate_tensors()

input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
image_np = cv2.imread(image_path)
b,g,r = np.split(image_np,3,axis = 2)
image_np = np.concatenate((r,g,b),axis = 2)
image_np_org = image_np
image_np = cv2.resize(image_np,(400,300))
image_np = np.reshape(image_np,(1,300,400,3))
image_np_org = image_np
interpreter.set_tensor(input_details[0]['index'], image_np)
#Running inference and timing it
interpreter.invoke()
output_dict['detection_scores']=interpreter.get_tensor(xx)
output_dict['detection_boxes']=interpreter.get_tensor(xx)
`

@tensorflowbutler tensorflowbutler added the stat:awaiting response Waiting on input from the contributor label Aug 16, 2019
@tensorflowbutler
Copy link
Member

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks.
What is the top-level directory of the model you are using
Have I written custom code
OS Platform and Distribution
TensorFlow installed from
TensorFlow version
Bazel version
CUDA/cuDNN version
GPU model and memory
Exact command to reproduce

@ai-libo
Copy link
Author

ai-libo commented Aug 16, 2019

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks.
What is the top-level directory of the model you are using
Have I written custom code
OS Platform and Distribution
TensorFlow installed from
TensorFlow version
Bazel version
CUDA/cuDNN version
GPU model and memory
Exact command to reproduce

Thank you for your attention. I have added some additional environmental information and my tflite file. Please check whether it is enough

@tensorflowbutler tensorflowbutler removed the stat:awaiting response Waiting on input from the contributor label Aug 17, 2019
@gowthamkpr gowthamkpr added the models:research models that come under research directory label Sep 10, 2019
@srjoglekar246
Copy link
Contributor

We would probably need more information about your model. Was it trained with quantization? Or is it a floating point model?

@ai-libo
Copy link
Author

ai-libo commented Sep 14, 2019 via email

@zheyangshi
Copy link

Same problem.

@srjoglekar246
Copy link
Contributor

Sorry about the late reply :-).

Can you remove the default_ranges_min & default_ranges_min flags in your conversion command? And instead add change_concat_input_ranges=false?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
models:research models that come under research directory
Projects
None yet
Development

No branches or pull requests

5 participants