0

I have an acoustic model that successfully converted from ONNX to OpenVino. However, in OpenVino this model outputs tensor that consists of zeroes from some position.

#include <iostream>
#include <fstream>
#include <iterator>
#include <inference_engine.hpp>

typedef struct {
    float* data;
    size_t size;
    size_t timeLen;
} Fbank;

using namespace InferenceEngine;
using std::cout;
using std::endl;

void print_arr(std::string text, const float* arr, int l, int r) {
    cout << text << endl;
    for (int i = l; i < r; i++) {
        cout << arr[i] << " ";
    }
    cout << endl;
}

void doInference(ExecutableNetwork& executable_network, const std::string& input_name, const std::string& output_name, Fbank* fbank) {

    InferRequest infer_request = executable_network.CreateInferRequest();

    InferenceEngine::TensorDesc tDesc(InferenceEngine::Precision::FP32,
        {fbank->size, fbank->timeLen}, InferenceEngine::Layout::HW);
    Blob::Ptr blob = InferenceEngine::make_shared_blob<float>(tDesc, fbank->data);

    infer_request.SetBlob(input_name, blob);

    infer_request.Infer();
    Blob::Ptr output_blob = infer_request.GetBlob(output_name);

    auto dims = output_blob->getTensorDesc().getDims();

    size_t batchSize = dims[0];
    size_t T = dims[1];
    size_t D = dims[2];

    MemoryBlob::CPtr moutput = as<MemoryBlob>(output_blob);
    if (!moutput) {
        return;
    }

    auto moutputHolder = moutput->rmap();
    const float *pred = moutputHolder.as<const float*>();

    print_arr("AM output:", pred, D*29, D*31);
}


int main() {
    Fbank* fbank = new Fbank;
    fbank->size = 64;
    fbank->timeLen = 2000;
    fbank->data = new float[64*2000];

    Core ie;
    CNNNetwork network = ie.ReadNetwork("quartznet_random.xml", "quartznet_random.bin");

    std::string input_name = network.getInputsInfo().begin()->first;
    std::string output_name = network.getOutputsInfo().begin()->first;

    network.getOutputsInfo().begin()->second->setPrecision(Precision::FP32);

    ExecutableNetwork executable_network = ie.LoadNetwork(network, "cpu");
    doInference(executable_network, input_name, output_name, fbank);
    return 0;
}

Outputs:

AM output:
0.138650 -5.833140 -8.023724 -7.637482 -8.001101 -9.033963 -8.029905 -8.132050 -9.186495 -8.537528 -8.788505 -9.240234 -8.547676 -8.673388 0.000000 0.000000 -0.000000 0.000000 -0.000000 0.000000 0.000000 -0.000000 -0.000000 0.000000 -0.000000 0.000000 0.000000 -0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -0.000000 0.000000 0.000000 -0.000000 0.000000 0.000000 -0.000000 -0.000000 -0.000000 -0.000000 -0.000000 0.000000 -0.000000 -0.000000 -0.000000 0.000000 -0.000000 -0.000000 -0.000000 0.000000 0.000000 -0.000000 -0.000000 0.000000 -0.000000 0.000000 -0.000000 -0.000000 -0.000000 0.000000 -0.000000 -0.000000 0.000000 -0.000000 0.000000

If I run ONNX model in Python using onnxruntime, the output will be correct. (Example).

Is it possible to fix it?

P.S. Command to convert the model from ONNX: python3 mo_onnx.py —input_model model.onnx —output="output" —input="fbanks[64 2000]"

0x1337
  • 1,074
  • 1
  • 14
  • 33

2 Answers2

1

Tested provided ONNX model in OpenVINO for Linux, couple of findings while testing OpenVINO 2020.1 and new 2020.2 version (released today 4/14/2020, release notes).

Using same command to convert from ONNX. Although its unclear what would be the expected output (probability between 0.0 and 1.0?), OpenVINO 2020.2 seems to affect the output results.

  1. On 2020.1, observed similar results to yours (one can assume this is the OpenVINO version you used).

AM output: -3.55062 -3.5114 -3.50925 -3.52013 -3.51791 -3.54656 -3.53908 -3.54239 -3.53626 -3.50982 -3.54193 -3.55593 -3.52877 -3.53786 -1.546e-07 -6.14673e-08 -8.56817e-08 -1.41561e-07 -6.14673e-08 -1.16415e-07 -9.30158e-08 -9.12696e-08 -1.29454e-07 -1.04774e-07 -6.14673e-08 -5.58794e-08 -1.71363e-07 -1.02445e-07 -5.7742e-08 -1.35042e-07 -9.26666e-08 -1.00583e-07 -1.04308e-07 -1.2666e-07 -1.39698e-07 -7.26432e-08 -9.68575e-08 -1.47149e-07 -9.40636e-08 -9.77889e-08 -9.49949e-08 -1.16415e-07 -9.54606e-08 -8.3819e-08 -1.28523e-07 -1.35973e-07 -7.66013e-08 -1.12224e-07 -1.546e-07 -6.14673e-08 -8.56817e-08 -1.41561e-07 -6.14673e-08 -1.16415e-07 -9.30158e-08 -9.12696e-08 -1.29454e-07 -1.04774e-07 -6.14673e-08 -5.58794e-08 -1.71363e-07 -1.02445e-07 -5.7742e-08 -1.35042e-07 -9.26666e-08 -1.00583e-07 -1.04308e-07 -1.2666e-07

  1. On OpenVINO 2020.2 had to change ExecutableNetwork executable_network = ie.LoadNetwork(network, "cpu"); to ExecutableNetwork executable_network = ie.LoadNetwork(network, "CPU"); as Inference Engine didnt't recognize lowercase CPU device, error was "terminate called after throwing an instance of 'InferenceEngine::details::InferenceEngineException' what(): Device with "cpu" name is not registered in the InferenceEngine Aborted (core dumped)"
  2. On OpenVINO 2020.2, the results differ and are not close to zero (although all seem negative).

AM output: -3.55062 -3.5114 -3.50925 -3.52013 -3.51791 -3.54656 -3.53908 -3.54239 -3.53626 -3.50982 -3.54193 -3.55593 -3.52877 -3.53786 -3.52153 -3.52563 -3.51142 -3.54885 -3.52137 -3.54384 -3.53411 -3.55188 -3.5477 -3.52514 -3.51171 -3.5022 -3.5138 -3.50823 -3.50125 -3.51817 -3.53914 -3.50173 -3.50603 -3.51917 -3.55062 -3.5114 -3.50925 -3.52013 -3.51791 -3.54656 -3.53908 -3.54239 -3.53626 -3.50982 -3.54193 -3.55593 -3.52877 -3.53786 -3.52153 -3.52563 -3.51142 -3.54885 -3.52137 -3.54384 -3.53411 -3.55188 -3.5477 -3.52514 -3.51171 -3.5022 -3.5138 -3.50823 -3.50125 -3.51817 -3.53914 -3.50173 -3.50603 -3.51917

It's uncertain if the output results of OpenVINO 2020.2 are expected/correct. I am unable to test Python example with the ONNX model using onnxruntime, script expects /kek/fbank.out file. Clarify/share what output is expected, i.e. correct AM output.

avitial
  • 176
  • 6
1

The problem was due to numerical instability in our implementation of LogSoftmax. Without log of softmax all works fine.

0x1337
  • 1,074
  • 1
  • 14
  • 33