Skip to content

Commit 3508d77

Browse files
authored
Use last model layer for benchmarking (do not pick softmax layer, which may be located somewhere in the middle of the model (#147490) (#3966)
* Use last model layer for benchmarking (do not pick softmax layer, which may be located somewhere in the middle of the model (#147490) * The check is performed earlier in the flow, extend its text * swap lines
1 parent cec8d2b commit 3508d77

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

demos/common/cpp/models/src/classification_model.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void ClassificationModel::prepareInputsOutputs(std::shared_ptr<ov::Model>& model
8989
// --------------------------- Configure input & output -------------------------------------------------
9090
// --------------------------- Prepare input ------------------------------------------------------
9191
if (model->inputs().size() != 1) {
92-
throw std::logic_error("Classification model wrapper supports topologies with only 1 input");
92+
throw std::logic_error("Classification model wrapper supports topologies with only 1 input, but found: " + std::to_string(model->inputs().size()));
9393
}
9494
const auto& input = model->input();
9595
inputsNames.push_back(input.get_any_name());
@@ -158,19 +158,11 @@ void ClassificationModel::prepareInputsOutputs(std::shared_ptr<ov::Model>& model
158158
model = ppp.build();
159159

160160
// --------------------------- Adding softmax and topK output ---------------------------
161-
auto nodes = model->get_ops();
162-
auto softmaxNodeIt = std::find_if(std::begin(nodes), std::end(nodes), [](const std::shared_ptr<ov::Node>& op) {
163-
return std::string(op->get_type_name()) == "Softmax";
164-
});
165-
166-
std::shared_ptr<ov::Node> softmaxNode;
167-
if (softmaxNodeIt == nodes.end()) {
168-
auto logitsNode = model->get_output_op(0)->input(0).get_source_output().get_node();
169-
softmaxNode = std::make_shared<ov::op::v1::Softmax>(logitsNode->output(0), 1);
170-
} else {
171-
softmaxNode = *softmaxNodeIt;
172-
}
161+
auto logitsNode = model->get_output_op(0)->input(0).get_source_output().get_node();
162+
163+
std::shared_ptr<ov::Node> softmaxNode = std::make_shared<ov::op::v1::Softmax>(logitsNode->output(0), 1);
173164
const auto k = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, std::vector<size_t>{nTop});
165+
174166
std::shared_ptr<ov::Node> topkNode = std::make_shared<ov::op::v3::TopK>(softmaxNode,
175167
k,
176168
1,

0 commit comments

Comments
 (0)