1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge pull request #28963 from abhishek-gola:custom_layers

Added custom layer support in new DNN engine #28963

Closes: https://github.com/opencv/opencv/issues/26200
Merge with: https://github.com/opencv/opencv_extra/pull/1358

### Pull Request Readiness Checklist

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
This commit is contained in:
Abhishek Gola
2026-05-13 13:01:25 +05:30
committed by GitHub
parent 72e0bc2bf3
commit 914c0b2bc8
3 changed files with 168 additions and 3 deletions
+17 -3
View File
@@ -894,11 +894,12 @@ void ONNXImporter2::parseNode(const opencv_onnx::NodeProto& node_proto)
<< node_proto.output_size() << " outputs from domain '"
<< layer_type_domain << "'");*/
// Unknown domain: still try parseCustomLayer; addLayer() handles the miss.
if (dispatch.empty())
{
CV_LOG_ERROR(NULL, "DNN/ONNX: missing dispatch map for domain='" << layer_type_domain << "'");
rememberMissingOp(layer_type);
return;
CV_LOG_DEBUG(NULL, "DNN/ONNX: no built-in dispatch map for domain='"
<< layer_type_domain << "', trying custom layer for '"
<< layer_type << "'");
}
node_inputs.clear();
@@ -990,8 +991,21 @@ void ONNXImporter2::parseNeg(LayerParams& layerParams, const opencv_onnx::NodePr
addLayer(layerParams, node_proto);
}
// Lookup unknown ONNX ops in the user-side LayerFactory; non-default
// domains are prefixed (e.g. "my.namespace.MyOp"), matching the old engine.
void ONNXImporter2::parseCustomLayer(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto)
{
const std::string& name = layerParams.name;
std::string& layer_type = layerParams.type;
const std::string& layer_type_domain = node_proto.has_domain() ? node_proto.domain() : std::string();
if (!LayerFactory::isLayerRegistered(layer_type))
{
CV_LOG_INFO(NULL, "DNN/ONNX: unknown node type '" << layer_type
<< "' (domain '" << layer_type_domain << "', node '" << name
<< "'). Register a handler via CV_DNN_REGISTER_LAYER_CLASS() or LayerFactory::registerLayer().");
}
parseSimpleLayers(layerParams, node_proto);
}