@@ -197,8 +197,18 @@ class ONNXImporter
197
197
void parseOperatorSet ();
198
198
199
199
const std::string str_domain_ai_onnx = " ai.onnx" ;
200
+
201
+
202
+ bool useLegacyNames;
203
+ bool getParamUseLegacyNames ()
204
+ {
205
+ bool param = utils::getConfigurationParameterBool (" OPENCV_DNN_ONNX_USE_LEGACY_NAMES" , false );
206
+ return param;
207
+ }
208
+ const std::string extractNodeName (const opencv_onnx::NodeProto& node_proto);
200
209
};
201
210
211
+
202
212
class ONNXLayerHandler : public detail ::LayerHandler
203
213
{
204
214
public:
@@ -233,6 +243,7 @@ ONNXImporter::ONNXImporter(Net& net, const char *onnxFile)
233
243
: layerHandler(DNN_DIAGNOSTICS_RUN ? new ONNXLayerHandler(this ) : nullptr )
234
244
, dstNet(net)
235
245
, onnx_opset(0 )
246
+ , useLegacyNames(getParamUseLegacyNames())
236
247
{
237
248
hasDynamicShapes = false ;
238
249
CV_Assert (onnxFile);
@@ -256,6 +267,7 @@ ONNXImporter::ONNXImporter(Net& net, const char* buffer, size_t sizeBuffer)
256
267
: layerHandler(DNN_DIAGNOSTICS_RUN ? new ONNXLayerHandler(this ) : nullptr )
257
268
, dstNet(net)
258
269
, onnx_opset(0 )
270
+ , useLegacyNames(getParamUseLegacyNames())
259
271
{
260
272
hasDynamicShapes = false ;
261
273
CV_LOG_DEBUG (NULL , " DNN/ONNX: processing in-memory ONNX model (" << sizeBuffer << " bytes)" );
@@ -278,6 +290,7 @@ ONNXImporter::ONNXImporter(Net& net, const char* buffer, size_t sizeBuffer)
278
290
populateNet ();
279
291
}
280
292
293
+
281
294
inline void replaceLayerParam (LayerParams& layerParams, const String& oldKey, const String& newKey)
282
295
{
283
296
if (layerParams.has (oldKey)) {
@@ -909,11 +922,14 @@ const ONNXImporter::DispatchMap& ONNXImporter::getDispatchMap(const opencv_onnx:
909
922
return it->second ;
910
923
}
911
924
912
- const std::string& extractNodeName (const opencv_onnx::NodeProto& node_proto)
925
+ const std::string ONNXImporter:: extractNodeName (const opencv_onnx::NodeProto& node_proto)
913
926
{
927
+ // We need to rework DNN outputs API, this is a workaround for #21698
914
928
if (node_proto.has_name () && !node_proto.name ().empty ())
915
929
{
916
- return node_proto.name ();
930
+ if (useLegacyNames)
931
+ return node_proto.name ();
932
+ return cv::format (" onnx_node!%s" , node_proto.name ().c_str ());
917
933
}
918
934
for (int i = 0 ; i < node_proto.output_size (); ++i)
919
935
{
@@ -923,7 +939,9 @@ const std::string& extractNodeName(const opencv_onnx::NodeProto& node_proto)
923
939
// the second method is to use an empty string in place of an input or output name.
924
940
if (!name.empty ())
925
941
{
926
- return name;
942
+ if (useLegacyNames)
943
+ return name.c_str ();
944
+ return cv::format (" onnx_node_output_%d!%s" , i, name.c_str ());
927
945
}
928
946
}
929
947
CV_Error (Error::StsAssert, " Couldn't deduce Node name." );
0 commit comments