Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(3.4) dnn: fix API - explicit ctors, const methods #21429

Merged
merged 1 commit into from Jan 21, 2022

Conversation

alalek
Copy link
Member

@alalek alalek commented Jan 12, 2022

Validate:

  • samples/dnn/dasiamrpn_tracker.py
  • Halide build configuration
  • OpenVINO build configuration
  • OpenVINO build configuration (NN builder - 2019r3.0)
force_builders=Custom,Custom Win,Custom Mac

buildworker:Docs=linux-4,linux-6
build_image:Docs=docs-js:18.04


build_image:Custom=halide:16.04
Xbuild_image:Custom=ubuntu-openvino-2019r3.0:16.04
Xbuild_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.2

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-6
Xbuildworker:Custom=linux-5
test_opencl:Custom=OFF
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=*

Copy link
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!

Comment on lines +1402 to 1410
LayerData& getLayerData(int id) const
{
MapIdToLayerData::iterator it = layers.find(id);
MapIdToLayerData::const_iterator it = layers.find(id);

if (it == layers.end())
CV_Error(Error::StsObjectNotFound, format("Layer with requested id=%d not found", id));

return it->second;
return const_cast<LayerData&>(it->second);
}
Copy link
Member

Choose a reason for hiding this comment

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

We are returning non-const reference from const method. Why do we need that?

Copy link
Member Author

Choose a reason for hiding this comment

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

This change requires too much changes due to current.
Unfortunately LayerData is not not preserved unmodified. It is part of "graph" model and manages graph connections too.

{
int lid = (layerName.empty()) ? 0 : getLayerId(layerName);

std::vector<LayerPin> pins;

for (int i = 0; i < layers[lid].outputBlobs.size(); i++)
for (int i = 0; i < const_cast<MapIdToLayerData&>(layers)[lid].outputBlobs.size(); i++)
Copy link
Member

Choose a reason for hiding this comment

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

I think, we either should check that lid exists in layers, or mark layers as mutable, or don't mark this method as const. I think, the use of const_cast is unjustified here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

Comment on lines 3195 to 3204
const LayerData &ld = const_cast<MapIdToLayerData&>(layers)[pin.lid];
if ((size_t)pin.oid >= ld.outputBlobs.size())
Copy link
Member

Choose a reason for hiding this comment

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

If we create [pin.lid] in layers in previous line, its outputBlobs.size() is zero and the condition is true, so we can get rid of const_cast.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

@alalek
Copy link
Member Author

alalek commented Jan 21, 2022

👍

@opencv-pushbot opencv-pushbot merged commit f811ba8 into opencv:3.4 Jan 21, 2022
@alalek alalek mentioned this pull request Jan 28, 2022
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants