From 13c95efa74690cace66316f04894ce63b9d11570 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Wed, 3 Apr 2024 09:41:40 +0300 Subject: [PATCH] Merge pull request #25312 from dkurt:dnn_hotfix_tflite Ownership check in TFLite importer #25312 ### Pull Request Readiness Checklist resolves https://github.com/opencv/opencv/issues/25310 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 --- modules/dnn/src/tflite/tflite_importer.cpp | 7 ++++--- modules/dnn/test/test_tflite_importer.cpp | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/dnn/src/tflite/tflite_importer.cpp b/modules/dnn/src/tflite/tflite_importer.cpp index a23bff2545..8850cd9ad2 100644 --- a/modules/dnn/src/tflite/tflite_importer.cpp +++ b/modules/dnn/src/tflite/tflite_importer.cpp @@ -300,6 +300,10 @@ void TFLiteImporter::addLayer(LayerParams& layerParams, const Operator& op) { Mat blob = allTensors[idx]; layerParams.blobs.push_back(blob.u ? blob : blob.clone()); // some tensors are owned by OpenCV } + } else { + for (auto& blob : layerParams.blobs) { + CV_Assert(blob.u); + } } int dtype = CV_32F; @@ -830,9 +834,6 @@ void TFLiteImporter::parseFullyConnected(const Operator& op, const std::string& auto options = op.builtin_options_as_FullyConnectedOptions(); CV_Assert(options); - int idx = op.inputs()->Get(1); - Mat weights = allTensors[idx]; - layerParams.blobs.resize(1, weights); layerParams.set("transB", true); layerParams.set("constB", true); addLayer(layerParams, op); diff --git a/modules/dnn/test/test_tflite_importer.cpp b/modules/dnn/test/test_tflite_importer.cpp index 26f2c373b8..291d1f50d2 100644 --- a/modules/dnn/test/test_tflite_importer.cpp +++ b/modules/dnn/test/test_tflite_importer.cpp @@ -240,8 +240,6 @@ TEST_P(Test_TFLite, split) { } TEST_P(Test_TFLite, fully_connected) { - if (backend == DNN_BACKEND_CUDA) - applyTestTag(CV_TEST_TAG_DNN_SKIP_CUDA, CV_TEST_TAG_DNN_SKIP_CUDA_FP16); if (backend == DNN_BACKEND_VKCOM) applyTestTag(CV_TEST_TAG_DNN_SKIP_VULKAN); testLayer("fully_connected");