forked from opencv/opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opencv#20494 from rogday:onnx_diagnostic_fix
fix ONNXImporter diagnostic mode layer registration issue * fix layer registration, thread unsafe access and align the behavior of DNN_DIAGNOSTICS_RUN between onnx and tf importers * move skipModelInput * print all missing layers * address TF issue
- Loading branch information
Showing
9 changed files
with
321 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// This file is part of OpenCV project. | ||
// It is subject to the license terms in the LICENSE file found in the top-level directory | ||
// of this distribution and at http://opencv.org/license.html. | ||
|
||
#ifndef OPENCV_DNN_UTILS_DEBUG_UTILS_HPP | ||
#define OPENCV_DNN_UTILS_DEBUG_UTILS_HPP | ||
|
||
#include "../dnn.hpp" | ||
|
||
namespace cv { namespace dnn { | ||
CV__DNN_INLINE_NS_BEGIN | ||
|
||
/** | ||
* @brief Skip model import after diagnostic run in readNet() functions. | ||
* @param[in] skip Indicates whether to skip the import. | ||
* | ||
* This is an internal OpenCV function not intended for users. | ||
*/ | ||
CV_EXPORTS void skipModelImport(bool skip); | ||
|
||
CV__DNN_INLINE_NS_END | ||
}} // namespace | ||
|
||
#endif // OPENCV_DNN_UTILS_DEBUG_UTILS_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// This file is part of OpenCV project. | ||
// It is subject to the license terms in the LICENSE file found in the top-level directory | ||
// of this distribution and at http://opencv.org/license.html. | ||
|
||
#include "precomp.hpp" | ||
|
||
#include <sstream> | ||
|
||
#include <opencv2/dnn/layer_reg.private.hpp> | ||
#include <opencv2/dnn/utils/debug_utils.hpp> | ||
#include <opencv2/core/utils/logger.hpp> | ||
|
||
namespace cv { namespace dnn { | ||
CV__DNN_INLINE_NS_BEGIN | ||
|
||
bool DNN_DIAGNOSTICS_RUN = false; | ||
bool DNN_SKIP_REAL_IMPORT = false; | ||
|
||
void enableModelDiagnostics(bool isDiagnosticsMode) | ||
{ | ||
DNN_DIAGNOSTICS_RUN = isDiagnosticsMode; | ||
|
||
if (DNN_DIAGNOSTICS_RUN) | ||
{ | ||
detail::NotImplemented::Register(); | ||
} | ||
else | ||
{ | ||
detail::NotImplemented::unRegister(); | ||
} | ||
} | ||
|
||
void skipModelImport(bool skip) | ||
{ | ||
DNN_SKIP_REAL_IMPORT = skip; | ||
} | ||
|
||
void detail::LayerHandler::addMissing(const std::string& name, const std::string& type) | ||
{ | ||
cv::AutoLock lock(getLayerFactoryMutex()); | ||
auto& registeredLayers = getLayerFactoryImpl(); | ||
|
||
// If we didn't add it, but can create it, it's custom and not missing. | ||
if (layers.find(type) == layers.end() && registeredLayers.find(type) != registeredLayers.end()) | ||
{ | ||
return; | ||
} | ||
|
||
layers[type].insert(name); | ||
} | ||
|
||
bool detail::LayerHandler::contains(const std::string& type) const | ||
{ | ||
return layers.find(type) != layers.end(); | ||
} | ||
|
||
void detail::LayerHandler::printMissing() | ||
{ | ||
if (layers.empty()) | ||
{ | ||
return; | ||
} | ||
|
||
std::stringstream ss; | ||
ss << "DNN: Not supported types:\n"; | ||
for (const auto& type_names : layers) | ||
{ | ||
const auto& type = type_names.first; | ||
ss << "Type='" << type << "', affected nodes:\n["; | ||
for (const auto& name : type_names.second) | ||
{ | ||
ss << "'" << name << "', "; | ||
} | ||
ss.seekp(-2, std::ios_base::end); | ||
ss << "]\n"; | ||
} | ||
CV_LOG_ERROR(NULL, ss.str()); | ||
} | ||
|
||
LayerParams detail::LayerHandler::getNotImplementedParams(const std::string& name, const std::string& op) | ||
{ | ||
LayerParams lp; | ||
lp.name = name; | ||
lp.type = "NotImplemented"; | ||
lp.set("type", op); | ||
|
||
return lp; | ||
} | ||
|
||
CV__DNN_INLINE_NS_END | ||
}} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.