Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6403 Discussions

[nGraph] Failed to implement v1::Topk, always get value but not index as output

Mingming_X_Intel
Employee
1,375 Views

I tried to implement argmax via TopK-1
as codes attached below , but no matter I set sort to "value" or "index", no matter I use const auto result = std::make_shared<op::Result>(topk->output(1).get_node_shared_ptr()) or const auto result = std::make_shared<op::Result>(topk->output(0).get_node_shared_ptr()), I can't get the index as output, I always get value as output. I think there is something wrong with the TopK-1. Please help, thanks very much!

const auto k = op::Constant::create(element::i64, Shape{}, {1});
auto topk = std::make_shared<op::v1::TopK>(inputNode, k, 1, "max", "index");
const auto result = std::make_shared<op::Result>(topk->output(1).get_node_shared_ptr());

 

0 Kudos
1 Solution
Mingming_X_Intel
Employee
1,266 Views

Hi, Munesh,

Thanks for your great help. I just solved this problem already. I share the method with you as below.

 

auto A = make_shared<op::Parameter>(element::f32, shape);
const auto k = op::Constant::create(element::i32, Shape{}, {2});
auto B = make_shared<op::v1::TopK>(A, k, 1, "max", "value", element::i32);
auto fun = make_shared<Function>(OutputVector{B->output(0), B->output(1)}, ParameterVector{A});

 

 If we want to implement ArgMax with TopK, We should use the codes above to add TopK node, and then the second output of TopK 

B->output(1)

will show the result of ArgMax. But if I used the 

B->output(1)

to make function as below

auto fun = make_shared<Function>(OutputVector{B->output(0)}, ParameterVector{A})

will failed. That's the root cause why I failed.

And deeplabv3 model for segmentation demo has been validated successfully.

Thanks again for your answer!

BR,

Mingming

View solution in original post

0 Kudos
7 Replies
JananiC_Intel
Moderator
1,358 Views

Hi,

Thanks for reaching out.

Are you trying it in OpenVINO?


0 Kudos
Mingming_X_Intel
Employee
1,344 Views

Hi,

Starting from OpenVINO 2020.1, the Inference Engine use nGraph API to replace NNBuilder API, which uses a new way to represent a model in run time underneath of the conventional CNNNetwork API. To align with the new definition of nGraph operations in OpenVINO, I am using nGraph API under OpenVINO 2020.3 environment.

I tried to use TopK to implement the Argmax for running deeplab v3 model which is needed by this native demo Image Segmentation C++ Demo. So how does this Demo support deeplab v3 model? Does thie Demo also use TopK to implement Argmax?  

BR, 

Mingming

0 Kudos
Mingming_X_Intel
Employee
1,336 Views

Hi,

And I also tried use v0::ArgMax as below.

auto argmaxNode = std::make_shared<op::v0::ArgMax>
    (inputNode,1,element::i32);

But I also failed and got exception error as below.

exception Error of validate layer: ArgMax_6567 with type: ArgMax. No such parameter name 'top_k' for layer ArgMax_6567

 BR, 

Mingming

0 Kudos
JananiC_Intel
Moderator
1,331 Views

Hi,

Thanks for the update.

We are moving this query to openvino forum for a faster response.


0 Kudos
Mingming_X_Intel
Employee
1,330 Views
0 Kudos
Munesh_Intel
Moderator
1,280 Views

Hi Ming Ming Xu,


Image Segmentation C++ Demo is validated, and I’ve also validated on my end as well, using semantic-segmentation-adas-0001.xml model, as shown in the following page.


https://docs.openvinotoolkit.org/2020.4/omz_demos_segmentation_demo_README.html#running


Regarding your other question, please note that for CPU, the support for TopK and ArgMax layers are implemented via Extensibility Mechanism.


More information is available at the following page:

https://docs.openvinotoolkit.org/2020.4/openvino_docs_IE_DG_supported_plugins_Supported_Devices.html#supported_layers


Lastly, for your query regarding DeeplabV3, we are currently investigating the compatibility of DeeplabV3 with this demo.


Regards,

Munesh


0 Kudos
Mingming_X_Intel
Employee
1,267 Views

Hi, Munesh,

Thanks for your great help. I just solved this problem already. I share the method with you as below.

 

auto A = make_shared<op::Parameter>(element::f32, shape);
const auto k = op::Constant::create(element::i32, Shape{}, {2});
auto B = make_shared<op::v1::TopK>(A, k, 1, "max", "value", element::i32);
auto fun = make_shared<Function>(OutputVector{B->output(0), B->output(1)}, ParameterVector{A});

 

 If we want to implement ArgMax with TopK, We should use the codes above to add TopK node, and then the second output of TopK 

B->output(1)

will show the result of ArgMax. But if I used the 

B->output(1)

to make function as below

auto fun = make_shared<Function>(OutputVector{B->output(0)}, ParameterVector{A})

will failed. That's the root cause why I failed.

And deeplabv3 model for segmentation demo has been validated successfully.

Thanks again for your answer!

BR,

Mingming

0 Kudos
Reply