Content-Length: 284939 | pFad | http://github.com/opencv/opencv/pull/27063/files

E1 Updated TopK Handling in ONNX Importer by tony19053000 · Pull Request #27063 · opencv/opencv · GitHub
Skip to content

Updated TopK Handling in ONNX Importer #27063

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions modules/dnn/src/onnx/onnx_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3124,19 +3124,36 @@ void ONNXImporter::parseLayerNorm(LayerParams& layerParams, const opencv_onnx::N

void ONNXImporter::parseTopK(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto)
{
// K needs to be constant in case of being input (since opset 10)
if (node_proto.input_size() == 2) {
bool K_const = constBlobs.find(node_proto.input(1)) != constBlobs.end();
CV_CheckTrue(K_const, "OnnxImporter/TopK: K being non-constant is not supported");
int k = -1;
for (const auto& attr : node_proto.attribute())
{
if (attr.name() == "k")
{
k = attr.i();
break;
}
}

Mat input_K = getBlob(node_proto, 1);
int K = input_K.at<int>(0);
layerParams.set("k", K);
int K = -1;
if (node_proto.input_size() == 2) {
auto it = constBlobs.find(node_proto.input(1));
if (it != constBlobs.end()) {
Mat input_K = getBlob(node_proto, 1);
K = input_K.at<int>(0);
}
else {
CV_LOG_WARNING(NULL, "OnnxImporter/TopK: K is not constant, falling back to attribute value if available");
}
}

CV_CheckTrue(k != -1 || K != -1, "OnnxImporter/TopK: K parameter is required but missing");

layerParams.set("k", K != -1 ? K : k);
addLayer(layerParams, node_proto);
}



void ONNXImporter::parseSimpleLayers(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto)
{
bool is_all_input_const = true;
Expand Down
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/opencv/opencv/pull/27063/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy