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

[IE Samples] Improved processing outputs for model with more than one output #10737

Merged
merged 3 commits into from
Mar 3, 2022
Merged
Changes from 2 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
19 changes: 9 additions & 10 deletions samples/cpp/speech_sample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,10 @@ int main(int argc, char* argv[]) {
// -----------------------------------------------------------------------------------------------------
// --------------------------- Step 5. Do inference --------------------------------------------------------
std::vector<std::vector<uint8_t>> ptrUtterances;
std::vector<std::vector<uint8_t>> vectorPtrScores((outputs.size() == 0) ? 1 : outputs.size());
std::vector<uint16_t> numScoresPerOutput((outputs.size() == 0) ? 1 : outputs.size());
std::vector<std::vector<uint8_t>> vectorPtrScores((outputs.size() == 0) ? executableNet.outputs().size()
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it is not necessary to define the size of those vectors here it will reduce code size

: outputs.size());
std::vector<uint16_t> numScoresPerOutput((outputs.size() == 0) ? executableNet.outputs().size()
: outputs.size());
std::vector<std::vector<uint8_t>> vectorPtrReferenceScores(reference_name_files.size());
std::vector<ScoreErrorT> vectorFrameError(reference_name_files.size()),
vectorTotalError(reference_name_files.size());
Expand Down Expand Up @@ -474,8 +476,9 @@ int main(int argc, char* argv[]) {
inferRequest.inferRequest.wait();
if (inferRequest.frameIndex >= 0)
for (size_t next_output = 0; next_output < count_file; next_output++) {
std::string outputName = (outputs.size() == 0) ? executableNet.output(0).get_any_name()
: output_names[next_output];
std::string outputName = (outputs.size() == 0)
? executableNet.output(next_output).get_any_name()
: output_names[next_output];
auto dims = executableNet.output(outputName).get_shape();
numScoresPerOutput[next_output] = std::accumulate(std::begin(dims),
std::end(dims),
Expand All @@ -493,10 +496,6 @@ int main(int argc, char* argv[]) {

ov::Tensor outputBlob =
inferRequest.inferRequest.get_tensor(executableNet.output(outputName));
if (!outputs.empty()) {
outputBlob =
inferRequest.inferRequest.get_tensor(executableNet.output(outputName));
}
// locked memory holder should be alive all time while access to its buffer happens
auto byteSize = numScoresPerOutput[next_output] * sizeof(float);
std::memcpy(outputFrame, outputBlob.data<float>(), byteSize);
Expand Down Expand Up @@ -654,8 +653,8 @@ int main(int argc, char* argv[]) {
}
if (!FLAGS_r.empty()) {
// print statistical score error
std::string outputName =
(outputs.size() == 0) ? executableNet.output(0).get_any_name() : output_names[next_output];
std::string outputName = (outputs.size() == 0) ? executableNet.output(next_output).get_any_name()
Copy link
Contributor

Choose a reason for hiding this comment

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

we are setting this variable 2 times in the code...I would recommend moving this replacement when we are defining outputs vector, but let's do it next time

: output_names[next_output];
std::cout << "Output name: " << outputName << std::endl;
std::cout << "Number scores per frame: " << numScoresPerOutput[next_output] / batchSize << std::endl
<< std::endl;
Expand Down