Skip to content

dnn: improve logging, catch import errors#21322

Merged
opencv-pushbot merged 3 commits intoopencv:3.4from
alalek:dnn_catch_errors
Dec 23, 2021
Merged

dnn: improve logging, catch import errors#21322
opencv-pushbot merged 3 commits intoopencv:3.4from
alalek:dnn_catch_errors

Conversation

@alalek
Copy link
Copy Markdown
Member

@alalek alalek commented Dec 23, 2021

relates #19347 (debug helper for the issue)
relates #18145 (incomplete dynamic shapes support)

force_builders=Custom,Custom Win,Custom Mac

build_image:Custom=ubuntu-openvino-2021.4.0:20.04
Xbuild_image:Custom=ubuntu-openvino-2021.3.0:20.04
Xbuild_image:Custom=ubuntu-openvino-2021.2.0:20.04
Xbuild_image:Custom=ubuntu-openvino-2020.3.0:16.04
build_image:Custom Win=openvino-2021.4.2
Xbuild_image:Custom Win=openvino-2021.3.0-vc16
build_image:Custom Mac=openvino-2021.4.0

test_modules:Custom=dnn,python2,python3,java
test_modules:Custom Win=dnn,python2,python3,java
test_modules:Custom Mac=dnn,python2,python3,java

buildworker:Custom=linux-1
test_opencl:Custom=ON
test_bigdata:Custom=1
test_filter:Custom=*

buildworker:Custom Win=windows-3
test_opencl:Custom Win=ON
test_bigdata:Custom Win=1
test_filter:Custom Win=*

allow_multiple_commits=1

static const DispatchMap buildDispatchMap();

int onnx_opset; // OperatorSetIdProto for 'onnx' domain
void parseOperatorSet();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rogday Added ONNX opset field here.

else
{
// OpenCV don't know other opsets
CV_LOG_WARNING(NULL, "DNN/ONNX: unsupported opset[" << i << "]: name='" << domain << "' version=" << version);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we emit error here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change the condition to domain.empty() || domain == "ai.onnx" and emit the error if running normally, otherwise we should keep going(if DNN_DIAGNOSTICS_RUN is true).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is 3.4 branch, there is no DNN_DIAGNOSTICS_RUN

CV_LOG_WARNING(NULL, "DNN/ONNX: can't handle node with " << node_proto.input_size() << " inputs and " << node_proto.output_size() << " outputs: "
<< cv::format("[%s@%s]:(%s)", layer_type.c_str(), layer_type_domain.c_str(), name.c_str())
);
CV_Error(Error::StsNotImplemented, cv::format("ONNX: unsupported domain: %s", layer_type_domain.c_str()));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added error for non-ONNX domain.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to skip CV_Error if DNN_DIAGNOSTICS_RUN is true.

layerParams.set("mode", "opencv_linear");

// input = [X, scales], [X, roi, scales] or [x, roi, scales, sizes]
int foundScaleId = hasDynamicShapes ? node_proto.input_size() - 1
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid using of hasDynamicShapes checks.
Such checks should be eliminated.

Copy link
Copy Markdown
Member

@rogday rogday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contribution!


void ONNXImporter::parseOperatorSet()
{
int ir_version = model_proto.has_ir_version() ? (int)model_proto.ir_version() : -1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(int) -> static_cast() ?

else
{
// OpenCV don't know other opsets
CV_LOG_WARNING(NULL, "DNN/ONNX: unsupported opset[" << i << "]: name='" << domain << "' version=" << version);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change the condition to domain.empty() || domain == "ai.onnx" and emit the error if running normally, otherwise we should keep going(if DNN_DIAGNOSTICS_RUN is true).

CV_LOG_WARNING(NULL, "DNN/ONNX: can't handle node with " << node_proto.input_size() << " inputs and " << node_proto.output_size() << " outputs: "
<< cv::format("[%s@%s]:(%s)", layer_type.c_str(), layer_type_domain.c_str(), name.c_str())
);
CV_Error(Error::StsNotImplemented, cv::format("ONNX: unsupported domain: %s", layer_type_domain.c_str()));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to skip CV_Error if DNN_DIAGNOSTICS_RUN is true.

for (int j = 0; j < inpShape.size(); ++j)
shapeMat.at<int>(j) = inpShape[j];
bool isDynamicShape = false;
for (int j = 0; j < (int)inpShape.size(); ++j)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static_cast?

// opset-11: input = [X, roi, scales] or [x, roi, scales, sizes]
int foundScaleId = node_proto.input_size() == 2 ? 1 : 2;

Mat scales = getBlob(node_proto, foundScaleId);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't getBlob fail, if it doesn't find scales blob?
The condition below seems fragile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scales can be empty. getBlob() doesn't fail in that case.

https://github.com/onnx/onnx/blob/master/docs/Operators.md#Resize

The number of elements of 'scales' should be the same as the rank of input 'X'. One of 'scales' and 'sizes' MUST be specified and it is an error if both are specified. If 'sizes' is needed, the user can use an empty string as the name of 'scales' in this operator's input list.


" == 4" condition looks wrong. Reworked for better error messages.

@alalek
Copy link
Copy Markdown
Member Author

alalek commented Dec 23, 2021

👍

@opencv-pushbot opencv-pushbot merged commit f558944 into opencv:3.4 Dec 23, 2021
This was referenced Dec 24, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug category: dnn (onnx) ONNX suport issues in DNN module category: dnn

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants