ARM-software / armnn

Arm NN ML Software. The code here is a read-only mirror of https://review.mlplatform.org/admin/repos/ml/armnn
https://developer.arm.com/products/processors/machine-learning/arm-nn
MIT License
1.14k stars 307 forks source link

Invalid action on a tensor shape that has unknown number of dimensions #671

Closed BrainSurgeAI closed 1 year ago

BrainSurgeAI commented 1 year ago

Hi, I use armnn[22_05] to create a network from binary file rvm_mobilenetv3_fp32.onnx occurs an error:

#include "armnn/INetwork.hpp"

#include "armnn/IRuntime.hpp"
#include <armnn/Utils.hpp>
#include <armnn/Logging.hpp>
#include <armnn/Descriptors.hpp>
#include <armnnOnnxParser/IOnnxParser.hpp>
#include <iostream>

int main(int argc, char **argv)
{
    using namespace armnn;
    using IParser = armnnOnnxParser::IOnnxParser;
    using BindingPointInfo = armnn::BindingPointInfo;

    armnn::TensorShape srcShape({1, 3, 1280, 720});
    armnn::TensorShape r1iShape({1, 1, 1, 1});
    armnn::TensorShape r2iShape({1, 1, 1, 1});
    armnn::TensorShape r3iShape({1, 1, 1, 1});
    armnn::TensorShape r4iShape({1, 1, 1, 1});
    armnn::TensorShape dsrShape({1}); 

    std::map<std::string, armnn::TensorShape> inputShapes {
        {"src", srcShape},
        {"r1i", r1iShape},
        {"r2i", r2iShape},
        {"r3i", r3iShape},
        {"r4i", r4iShape},
        {"downsample_ratio", dsrShape}};

    auto parser(IParser::Create());

    auto network = parser->CreateNetworkFromBinaryFile(argv[1], inputShapes);
  ...

Invalid action on a tensor shape that has unknown number of dimensions. at function CheckUnspecifiedNumDimensions

How can I fix it?

catcor01 commented 1 year ago

Hello @Chernobyl81,

I used this to get a visual on your model. It seems that the shape of the following are incorrect compared to the 'srcShape'.

armnn::TensorShape r1iShape({1, 1, 1, 1});
armnn::TensorShape r2iShape({1, 1, 1, 1});
armnn::TensorShape r3iShape({1, 1, 1, 1});
armnn::TensorShape r4iShape({1, 1, 1, 1});

Below is a picture of the input size the model requires:

Screenshot from 2022-07-18 10-58-03

I suggest the above TensorShapes should be {1, 1, 1280, 720} to conform with 'srcShape'. Also, I would think that seeing 'downsample_ratio' is an input this will also need to be included when calling CreateNetworkFromBinaryFile(). I hope this solved your problem.

Kind Regards, Cathal.

BrainSurgeAI commented 1 year ago

@catcor01 Thanks for help. But it does not work too.

xiaotongnii commented 1 year ago

@Chernobyl81 Can you show log more details?

BrainSurgeAI commented 1 year ago

Hi, @Shelton-N, I wrote this program just for test onnx model loading.

#include "armnn/INetwork.hpp"

#include "armnn/IRuntime.hpp"
#include <armnn/Utils.hpp>
#include <armnn/Logging.hpp>
#include <armnn/Descriptors.hpp>
#include <armnnOnnxParser/IOnnxParser.hpp>
#include <iostream>

int main(int argc, char **argv)
{
    using namespace armnn;
    using IParser = armnnOnnxParser::IOnnxParser;
    using BindingPointInfo = armnn::BindingPointInfo;

    armnn::TensorShape srcShape({1, 3, 1280, 720});
    armnn::TensorShape r1iShape({1, 1, 1, 1});
    armnn::TensorShape r2iShape({1, 1, 1, 1});
    armnn::TensorShape r3iShape({1, 1, 1, 1});
    armnn::TensorShape r4iShape({1, 1, 1, 1});
    armnn::TensorShape dsrShape({1}); 

    std::map<std::string, armnn::TensorShape> inputTensors{
        {"src", srcShape}, 
        {"r1i", r1iShape},
        {"r2i", r2iShape},
        {"r3i", r3iShape},
        {"r4i", r4iShape},
        {"downsample_ratio", dsrShape}
    };

    auto parser(IParser::Create());
    auto network = parser->CreateNetworkFromBinaryFile(argv[1]);

    IRuntime::CreationOptions options; 
    armnn::IRuntimePtr run(armnn::IRuntime::Create(options));
    armnn::IOptimizedNetworkPtr optNet = Optimize(*network, {"CpuRef"}, run->GetDeviceSpec());

    if (!optNet)
    {
        std::cerr << "Error: Failed to optimise the input network" << std::endl;
        return 1;
    }

    return 0;
}

And get an error: 企业微信截图_16582070351729

xiaotongnii commented 1 year ago

@Chernobyl81 form log, erro happend when parser onnx model; parser onnx model op tensorshape

void TensorShape::CheckSpecifiedNumDimensions() const
{
    if (Dimensionality::Specified == m_Dimensionality)
    {
        std::stringstream errorMessage;
        errorMessage << "Invalid action on a tensor shape that has known number of dimensions.";
        throw InvalidArgumentException(errorMessage.str(), CHECK_LOCATION());
    }
}

from rvm_mobilenetv3_fp32.onnx INPUT ,it seems that is dynamic shape model。 And now ArmNN22.05 may not support dynamic shape for ONNX.

Notes: your log show that you maybe use not a 22.05 version.

@catcor01 Right?

BrainSurgeAI commented 1 year ago

@Shelton-N @catcor01 thank you a lot!

xiaotongnii commented 1 year ago

@catcor01 Is there plan to support dynamic shape for ONNX parser in the futrue?