Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork56.4k
Modified Caffe parser to support the new dnn engine#26208
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
811b6ea tobea0503CompareNew dnn engine#26056This is the 1st PR with the new engine; CI is green and PR is ready to be merged, I think.Merge together withopencv/opencv_contrib#3794---**Known limitations:*** [solved] OpenVINO is temporarily disabled, but is probably easy to restore (it's not a deal breaker to merge this PR, I guess)* The new engine does not support any backends nor any targets except for the default CPU implementation. But it's possible to choose the old engine when loading a model, then all the functionality is available.* [Caffe patch is here:#26208] The new engine only supports ONNX. When a model is constructed manually or is loaded from a file of different format (.tf, .tflite, .caffe, .darknet), the old engine is used.* Even in the case of ONNX some layers are not supported by the new engine, such as all quantized layers (including DequantizeLinear, QuantizeLinear, QLinearConv etc.), LSTM, GRU, .... It's planned, of course, to have full support for ONNX by OpenCV 5.0 gold release. When a loaded model contains unsupported layers, we switch to the old engine automatically (at ONNX parsing time, not at `forward()` time).* Some layers , e.g. Expat, are only partially supported by the new engine. In the case of unsupported flavours it switches to the old engine automatically (at ONNX parsing time, not at `forward()` time).* 'Concat' graph optimization is disabled. The optimization eliminates Concat layer and instead makes the layers that generate tensors to be concatenated to write the outputs to the final destination. Of course, it's only possible when `axis=0` or `axis=N=1`. The optimization is not compatible with dynamic shapes since we need to know in advance where to store the tensors. Because some of the layer implementations have been modified to become more compatible with the new engine, the feature appears to be broken even when the old engine is used.* Some `dnn::Net` API is not available with the new engine. Also, shape inference may return false if some of the output or intermediate tensors' shapes cannot be inferred without running the model. Probably this can be fixed by a dummy run of the model with zero inputs.* Some overloads of `dnn::Net::getFLOPs()` and `dnn::Net::getMemoryConsumption()` are not exposed any longer in wrapper generators; but the most useful overloads are exposed (and checked by Java tests).* [in progress] A few Einsum tests related to empty shapes have been disabled due to crashes in the tests and in Einsum implementations. The code and the tests need to be repaired.* OpenCL implementation of Deconvolution is disabled. It's very bad and very slow anyway; need to be completely revised.* Deconvolution3D test is now skipped, because it was only supported by CUDA and OpenVINO backends, both of which are not supported by the new engine.* Some tests, such as FastNeuralStyle, checked that the in the case of CUDA backend there is no fallback to CPU. Currently all layers in the new engine are processed on CPU, so there are many fallbacks. The checks, therefore, have been temporarily disabled.---- [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- [ ] There is a reference to the original bug report and related work- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name.- [ ] The feature is well documented and sample code can be built with the project CMake
bea0503 to4a318f7Compareasmorkalov commentedOct 19, 2024
@alexlyulkov I rebased your branch on top of 5.x and fixed conflicts. The original version is available in my fork:https://github.com/asmorkalov/opencv/tree/al/new-engine-caffe-parser |
asmorkalov commentedOct 21, 2024
vpisarev commentedOct 21, 2024
Looks good to me, and it's cool that you managed to combine two Caffe importers, the old one and the new one, in one source file. But it looks like some of the tests fail. |
asmorkalov commentedOct 21, 2024
With the new engine: |
asmorkalov commentedOct 21, 2024
Also there are a lot of test failures like this: I propose to revise test code and replace forward calls where it makes sense. |
a8b4f23 to51f6d14CompareUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
| CaffeImportercaffeImporter(prototxt.c_str(), caffeModel.c_str()); | ||
| Net net; | ||
| caffeImporter.populateNet(net); | ||
| caffeImporter.populateNet(net, engine == ENGINE_NEW || engine == ENGINE_AUTO); |
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.
What about fallback, if the new engine cannot handle the model?
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.
Look like it is unnecessary. The parser doesn't fall in tests
| CaffeImportercaffeImporter(bufferProto, lenProto, bufferModel, lenModel); | ||
| Net net; | ||
| caffeImporter.populateNet(net); | ||
| caffeImporter.populateNet(net, engine == ENGINE_NEW || engine == ENGINE_AUTO); |
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.
the same here.
asmorkalov commentedOct 23, 2024
Remaining test failures: |
asmorkalov commentedOct 26, 2024
@alexlyulkov Please take a look on Python test failures: |
asmorkalov commentedOct 28, 2024
a2fa1d4 intoopencv:5.xUh oh!
There was an error while loading.Please reload this page.
Now the Caffe parser supports both the old and the new engine. It can be selected using newEngine argument in PopulateNet.
All cpu Caffe tests work fine except:
Both these tests doesn't work because of the bug in the new net.forward function. The function takes the name of the desired target last layer, but uses this name as the name of the desired output tensor.
Also Colorization test contains a strange model with a Silence layer in the end, so it doesn't have outputs. The old parser just ignored it. I think, the proper solution is to run this model until the (number_of_layers - 2) layer using proper net.forward arguments in the test.
Pull Request Readiness Checklist
See details athttps://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.