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
Import and inference INT8 quantized TFLite model #23409
Conversation
Ubuntu 20.04:
|
8a10784
to
166890b
Compare
@@ -56,25 +56,32 @@ class TFLiteImporter { | |||
// Wrap TFLite Tensor to OpenCV Mat without data copying | |||
Mat parseTensor(const Tensor& tensor); | |||
|
|||
typedef void (TFLiteImporter::*TFLiteImporterNodeParser)(const Operator&, const std::string&, LayerParams&); | |||
typedef void (TFLiteImporter::*TFLiteImporterNodeParser)(const Operator&, const std::string&, LayerParams&, LayerParams&); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be a common change.
Many handlers just don't use activParams
at all.
Compiler warnings are disabled in dnn module, many warnings are really generated here for that change.
|
||
// Connect layer to inputs | ||
int i = 0; | ||
for (int idx : layerInputs) { | ||
std::vector<DataLayout> inpLayouts; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem of handlers API is here.
We should not have any heavy postprocessing after the handler call.
Post-processing should be done in the handler itself (because handler defines post-processing steps).
Provide a method for registration of DNN layers to be called from handlers.
See ONNX importer implementation for reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I reworked both fused activations logic and created an addLayer
method. Here is a graph for EfficientDet I used to verify that activations were added correctly: efficientdet.dot (efficientdet.pdf). Unfortunately, for this model they work as identity function and even with unconnected activations, test passes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done 👍 Thank you!
@opencv-alalek, thanks for the review! |
Import and inference INT8 quantized TFLite model opencv#23409 ### Pull Request Readiness Checklist * Support quantized TFLite models * Enable fused activations (FP32, INT8) **Merge with extra**: opencv/opencv_extra#1048 ![res](https://user-images.githubusercontent.com/25801568/231433201-566b4bd6-ccff-462c-9e74-adbdcdf3648b.png) on the image, green boxes are from TFLite and red boxes from OpenCV See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
Pull Request Readiness Checklist
Merge with extra: opencv/opencv_extra#1048
on the image, green boxes are from TFLite and red boxes from OpenCV
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.