Skip to content

DNN: support GreaterOrEqual and LessOrEqual op in ONNX#22611

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
zihaomu:greaterOrEqual
Oct 10, 2022
Merged

DNN: support GreaterOrEqual and LessOrEqual op in ONNX#22611
asmorkalov merged 1 commit intoopencv:4.xfrom
zihaomu:greaterOrEqual

Conversation

@zihaomu
Copy link
Copy Markdown
Member

@zihaomu zihaomu commented Oct 8, 2022

Related test data: PR at opencv_extra.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@zihaomu zihaomu requested review from fengyuentau and rogday and removed request for fengyuentau October 8, 2022 07:54
@zihaomu zihaomu added the category: dnn (onnx) ONNX suport issues in DNN module label Oct 8, 2022
@zihaomu zihaomu linked an issue Oct 8, 2022 that may be closed by this pull request
@asmorkalov asmorkalov added this to the 4.7.0 milestone Oct 8, 2022
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.

Looks good, one question though.

Copy link
Copy Markdown
Member

@fengyuentau fengyuentau left a comment

Choose a reason for hiding this comment

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

Looks good. But how do we deal with the output type? In the model from opencv/opencv_zoo#82, the GreaterOrEqual operator is followed by a Cast operator, which casts the boolean output from GreaterOrEqual to float. I dont think this casting problem can be solved with this pull request, isnt it?

@zihaomu
Copy link
Copy Markdown
Member Author

zihaomu commented Oct 9, 2022

the GreaterOrEqual operator is followed by a Cast operator, which casts the boolean output from GreaterOrEqual to float. I dont think this casting problem can be solved with this pull request, isnt it?

For now, the GreaterOrEqual output the float32 instead of boolean format. So the cast do nothing. I am not sure if I am correct. More details can be found at this part.

@fengyuentau
Copy link
Copy Markdown
Member

So the cast do nothing

I just checked parseCast. It should do nothing indeed (see line 2608).

void ONNXImporter::parseCast(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto)
{
if (constBlobs.find(node_proto.input(0)) != constBlobs.end())
{
Mat blob = getBlob(node_proto, 0);
if (constBlobsExtraInfo.find(node_proto.input(0)) != constBlobsExtraInfo.end())
{
constBlobsExtraInfo.insert(std::make_pair(node_proto.output(0), getBlobExtraInfo(node_proto, 0)));
}
int type;
switch (layerParams.get<int>("to"))
{
case opencv_onnx::TensorProto_DataType_FLOAT: type = CV_32F; break;
case opencv_onnx::TensorProto_DataType_UINT8: type = CV_8U; break;
case opencv_onnx::TensorProto_DataType_UINT16: type = CV_16U; break;
case opencv_onnx::TensorProto_DataType_FLOAT16: type = CV_16S; break;
case opencv_onnx::TensorProto_DataType_INT8:
case opencv_onnx::TensorProto_DataType_INT16:
case opencv_onnx::TensorProto_DataType_INT32:
case opencv_onnx::TensorProto_DataType_INT64: type = CV_32S; break;
default: type = blob.type();
}
Mat dst;
blob.convertTo(dst, type);
dst.dims = blob.dims;
addConstant(node_proto.output(0), dst);
return;
}
else
layerParams.type = "Identity";
addLayer(layerParams, node_proto);
}

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.

👍

Copy link
Copy Markdown
Member

@fengyuentau fengyuentau left a comment

Choose a reason for hiding this comment

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

👍👍

@asmorkalov asmorkalov merged commit 3419e64 into opencv:4.x Oct 10, 2022
@alalek alalek mentioned this pull request Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DNN: need support of the GreaterOrEqual operator from ONNX

5 participants