3

I am trying to create a C++ standalone app based on ArmNN that operates on ONNX models. To start with I have downloaded a few standard models for testing, and while trying to load the model I see a crash saying "Tensor numDimensions must be greater than 0".

The strange thing is, the function that I am invoking to load the model takes just one parameter which is the model name. There is no place for me to specify the dimensions and whatnot. Probably I am doing something wrong here? Or this is not the way to load the model?

I have compiled armnn with support for ONNX as detailed down here. The build and include folders have been copied to a ARM linux machine where I am trying to run the code. I am using a Makefile to compile and run it.

The model I am currently using is download from here.

Initially I was on ArmNN master branch, and while searching for this error message I came across the ArmNN release notes where it was mentioned that the very same error has been fixed in release 19.05. So I switched to tag v19.05 and rebuild everything from scratch and tried to run the application again, but the same error kept popping up.

Here is the C++ code -

#include "armnn/ArmNN.hpp"
#include "armnn/Exceptions.hpp"
#include "armnn/Tensor.hpp"
#include "armnn/INetwork.hpp"
#include "armnnOnnxParser/IOnnxParser.hpp"


int main(int argc, char** argv)
{
    armnnOnnxParser::IOnnxParserPtr parser = armnnOnnxParser::IOnnxParser::Create();
    std::cout << "\nmodel load start";
    armnn::INetworkPtr network = parser->CreateNetworkFromBinaryFile("model.onnx");
    std::cout << "\nmodel load end";

    std::cout << "\nmain end";
    return 0;
}

The Makefile looks like this -

ARMNN_LIB = /home/root/Rahul/armnn_onnx/build
ARMNN_INC = /home/root/Rahul/armnn_onnx/include

all: onnx_test

onnx_test: onnx_test.cpp 
        g++ -O3 -std=c++14 -I$(ARMNN_INC) onnx_test.cpp -I.-I/usr/include -L/usr/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui  -o onnx_test -L$(ARMNN_LIB) -larmnn -lpthread -larmnnOnnxParser

clean:
        -rm -f onnx_test

test: onnx_test
        LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(ARMNN_LIB) ./onnx_test

Expected output - The code should load the model as expected and do a clean exit.

Actual error message -

terminate called after throwing an instance of 'armnn::InvalidArgumentException'
  what():  Tensor numDimensions must be greater than 0
model load startAborted (core dumped)

A gdb backtrace is provided below -

(gdb) r
Starting program: /home/root/Rahul/sample_onnx/onnx_test 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".

terminate called after throwing an instance of 'armnn::InvalidArgumentException'
  what():  Tensor numDimensions must be greater than 0
model load start
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at /usr/src/debug/glibc/2.26-r0/git/sysdeps/unix/sysv/linux/raise.c:51
51  }
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at /usr/src/debug/glibc/2.26-r0/git/sysdeps/unix/sysv/linux/raise.c:51
#1  0x0000ffffbe97ff00 in __GI_abort () at /usr/src/debug/glibc/2.26-r0/git/stdlib/abort.c:90
#2  0x0000ffffbec0c0f8 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/libstdc++.so.6
#3  0x0000ffffbec09afc in ?? () from /usr/lib/libstdc++.so.6
#4  0x0000ffffbec09b50 in std::terminate() () from /usr/lib/libstdc++.so.6
#5  0x0000ffffbec09e20 in __cxa_throw () from /usr/lib/libstdc++.so.6
#6  0x0000ffffbefdad84 in armnn::TensorShape::TensorShape(unsigned int, unsigned int const*) () from /home/root/Rahul/armnn_onnx/build/libarmnn.so
#7  0x0000ffffbed454d8 in armnnOnnxParser::(anonymous namespace)::ToTensorInfo(onnx::ValueInfoProto const&) [clone .constprop.493] () from /home/root/Rahul/armnn_onnx/build/libarmnnOnnxParser.so
#8  0x0000ffffbed46080 in armnnOnnxParser::OnnxParser::SetupInfo(google::protobuf::RepeatedPtrField<onnx::ValueInfoProto> const*) () from /home/root/Rahul/armnn_onnx/build/libarmnnOnnxParser.so
#9  0x0000ffffbed461ac in armnnOnnxParser::OnnxParser::LoadGraph() () from /home/root/Rahul/armnn_onnx/build/libarmnnOnnxParser.so
#10 0x0000ffffbed46760 in armnnOnnxParser::OnnxParser::CreateNetworkFromModel(onnx::ModelProto&) () from /home/root/Rahul/armnn_onnx/build/libarmnnOnnxParser.so
#11 0x0000ffffbed469b0 in armnnOnnxParser::OnnxParser::CreateNetworkFromBinaryFile(char const*) () from /home/root/Rahul/armnn_onnx/build/libarmnnOnnxParser.so
#12 0x0000000000400a48 in main ()
klutt
  • 30,332
  • 17
  • 55
  • 95
Rahul Chowdhury
  • 173
  • 2
  • 11

2 Answers2

0

It looks like a scalar in ONNX is represented as a tensor with no dimensions. So the problem here is that armnnOnnxParser is not correctly handling ONNX scalars. I would suggest raising an issue on the armnn Github.

0

I think you should try with at least one input layer and output layer.

// Helper function to make input tensors
armnn::InputTensors MakeInputTensors(const std::pair<armnn::LayerBindingId,
    armnn::TensorInfo>& input,
    const void* inputTensorData)
{
 return { { input.first, armnn::ConstTensor(input.second, inputTensorData) } };
}

For reference visit: https://developer.arm.com/solutions/machine-learning-on-arm/developer-material/how-to-guides/configuring-the-arm-nn-sdk-build-environment-for-onnx

Parag Jain
  • 612
  • 2
  • 14
  • 31