Comments (10)
@Ouskit With 55734c7, you can now use quantize_target_type='uint8', hybrid_quantization_from_float=True, hybrid_per_channel=False
to get the desired model.
from tinyneuralnetwork.
@Ouskit Below is the code that sets the op version for CONV_2D.
https://github.com/alibaba/TinyNeuralNetwork/blob/main/tinynn/converter/operators/op_version.py#L35-L49
It seems that you are using hybrid quantization, which is actually supported in TF 1.13.2 with op version = 1 as can be seen using the below links.
https://github.com/tensorflow/tensorflow/blob/v1.13.2/tensorflow/lite/kernels/conv.cc#L644
https://github.com/tensorflow/tensorflow/blob/v1.13.2/tensorflow/lite/kernels/register.cc#L170
So you may update the aforementioned logic to adapt the versioning to your usage.
from tinyneuralnetwork.
@peterjc123 Thank your reply, I change [op_version.py#L35-L49](
TinyNeuralNetwork/tinynn/converter/operators/op_version.py
Lines 35 to 49 in 6bdac3b
But when I want to do dynamic quantization, pass quantize_target_type='int8', hybrid_quantization_from_float=True, hybrid_per_channel=False
to convertr, the tflite inference result is totally wrong in tf 1.13.2
. But in tf 1.15.5
result is normal and ok.
Is there anything I don't notice? Thank you.
from tinyneuralnetwork.
Please try quantize_target_type='uint8'.
from tinyneuralnetwork.
@peterjc123 Thank your instant reply,
I inspected tf 1.13.2
inference result, it is got all 0.
After changing to quantize_target_type='uint8' will show AttributeError: Hybrid kernels supports int8 only
from tinyneuralnetwork.
@Ouskit I change hybrid_quantization_from_float=False, and infernce result is normal, but the model size is remaining the same. Is it normal? Thank you.
from tinyneuralnetwork.
@Ouskit I change hybrid_quantization_from_float=False, and infernce result is normal, but the model size is remaining the same. Is it normal? Thank you.
Yes, it means that you don't use hybrid quantization.
from tinyneuralnetwork.
Please comment out https://github.com/alibaba/TinyNeuralNetwork/blob/main/tinynn/converter/base.py#L96 and change the types in the code in https://github.com/alibaba/TinyNeuralNetwork/blob/main/tinynn/converter/operators/hybrid_quantizer.py#L49 to torch.quint8.
Appreciate your reply,
After I did these changes, the result is from all Nan to very small number, but the model output is not correct
Road Semantic segmentation task output, model output, not correct
from tinyneuralnetwork.
@Ouskit
https://github.com/alibaba/TinyNeuralNetwork/blob/main/tinynn/converter/operators/hybrid_quantizer.py#L47-L53
Please update line 49 in hybrid_quantizer.py
to the following code block.
new_weight = quantize(name, weight, torch.qint8, torch.per_tensor_symmetric, q_type=np.int8)
new_weight.dtype = np.dtype('uint8')
from tinyneuralnetwork.
@Ouskit https://github.com/alibaba/TinyNeuralNetwork/blob/main/tinynn/converter/operators/hybrid_quantizer.py#L47-L53 Please update line 49 in
hybrid_quantizer.py
to the following code block.new_weight = quantize(name, weight, torch.qint8, torch.per_tensor_symmetric, q_type=np.int8) new_weight.dtype = np.dtype('uint8')
@peterjc123 This works! Now the model output is totally correct. Thank you for your helpπ.
from tinyneuralnetwork.
Related Issues (20)
- Meet Detailed error: Tensor-likes are not close! using TFLiteConverter HOT 2
- [Converter] Need transpose optimization HOT 2
- Float model failed to convert to TFLite
- [converter] map gather(+reshape) ops with seperate consecutive indices to split(unpack) ops
- tinynn.converter module not found! HOT 2
- [CI] several tests for modifier failed
- Whether to support pytorch to keras HOT 1
- TransposeConv wrong shape? HOT 15
- change input to INT8 after converting to tflite HOT 2
- [converter] implement torch's `aten::scaled_dot_product_attention` operator HOT 2
- Request: clamp would be more efficient to go to Bounded Relu than Maximum + Minimum HOT 3
- Do not support PReLU module? HOT 5
- torch.max not working HOT 2
- OneShotChannelPruner results in the miss of some operators HOT 4
- KeyError when executing quantization HOT 5
- PyTorch 转 TFLite δ½Ώη¨ int8 ιε HOT 4
- Does tinynn support following int16 quantization? HOT 1
- jit.trace succeed but tinynn tracer failed HOT 1
- It became larger after converting to tflite model HOT 4
- how to do Post-training integer quantization with int16 activation HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinyneuralnetwork.