Tag Archives: onnx

[Solved] size_from_dim: Assertion `dim >= 0 && (size_t)dim < sizes_.size()` failed.

Problems encountered

/home/optimizer-master/third_party/onnx_common/tensor.h:117: size_from_dim: Assertion dim >= 0 && (size_t)dim < sizes_.size() failed.

 

Problem description

When import onnx, I encountered the above problems

 

Solution:

If there is an op operation that cannot be exported during onnx export, this error will be reported
How to Solve:
find the operation that cannot be exported and add a judgment. If you export onnx, the op will not be used. An example is as follows

def forward(self, x):
    if torch.onnx.is_in_onnx_export():# if onnx
        return x * self.act(x)/6
    else: # normally
        return x * self.act(x + 3)/6

[Solved] mnn Import Error: initMNN: init numpy failed

import MNN Error:

initMNN: init numpy failed

Solution:
pip uninstall numpy
pip install numpy

Error Messages:

D:\Anaconda3\lib\site-packages\numpy\_distributor_init.py:32: UserWarning: loaded more than 1 DLL from .libs:
D:\Anaconda3\lib\site-packages\numpy\.libs\libopenblas.WCDJNK7YVMPZQ2ME2ZZHJJRJ3JIKNDB7.gfortran-win_amd64.dll
D:\Anaconda3\lib\site-packages\numpy\.libs\libopenblas.XWYDX2IKJW2NMTWSFYNGFUWKQU3LYTCZ.gfortran-win_amd64.dll

 

mnn compile succefully:

Start to Convert Other Model Format To MNN Model...
[22:16:38] :30: ONNX Model ir version: 4
Start to Optimize the MNN Net...
inputTensors : [ images, ]
outputTensors: [ output, ]
Converted Success!

However, even so, MNN reasoning may report errors

Export failed:

Start to Convert Other Model Format To MNN Model...
[22:19:55] :30: ONNX Model ir version: 4
Start to Optimize the MNN Net...
inputTensors : [ images, ]
outputTensors: [ Transpose156, ]
Converted Success!

[Solved] TensorRT Error: Assertion Error in trtSmToCask: 0 (Unsupported SM.)

Error message:

E20211126 11:55:13.654 140412916315904 tensorrt.cpp:10] …/rtSafe/cuda/caskUtils.cpp (98) – Assertion Error in trtSmToCask: 0 (Unsupported SM.)

Reason: tensorrt version does not match CUDA or cudnn version. For example, the author’s tensorrt version is 7.2.1, while CUDA is the latest 11.5 version. CUDA version is too high to adapt:

Solution: reinstall CUDA or tensorrt
suggestion: reinstall CUDA because different versions of tensorrt have inconsistent codes. For example, tensorrt 7.2.1 and tensorrt 8.2.1 require that noexcept be added when rewriting virtual functions. If the amount of code is small, consider reinstalling tensorrt
attach the matching requirements of tensorrt, CUDA and cudnn versions: tensorrt release note

onnx.onnx_cpp2py_export.checker.ValidationError

onnx.onnx cpp2py export Yeah. checker.ValidationError

“25253rd;”381693rd;”

    import mxnet as mx
    import numpy as np
    from mxnet.contrib import onnx as onnx_mxnet
    import logging

    logging.basicConfig(level=logging.INFO)
    from onnx import checker
    import onnx

    syms = './mxnet/new_model-symbol.json'
    params = './mxnet/new_model-0000.params'

    input_shape = (1, 3, 112, 112)

    onnx_file = './mnist.onnx'

    # Invoke export model API. It returns path of the converted onnx model
    converted_model_path = onnx_mxnet.export_model(syms, params, [input_shape], np.float32, onnx_file)

    # Load onnx model
    model_proto = onnx.load_model(converted_model_path)

Online solution: pip install onnx==1.5.0
After the change, more errors are reported.
onnx.onnx_cpp2py_export.checker.ValidationError: Unrecognized attribute: spatial for operator BatchNormalization
==> Context: Bad node spec: input: “conv_1_conv2d” input: “conv_1_batchnorm_gamma” input: “conv_1_batchnorm_beta” input: “conv_1_batchnorm_moving_mean” input: “conv_1_batchnorm_moving_var” output: “conv_1_batchnorm” name: “conv_1_batchnorm” op_type: “BatchNormalization” attribute { name: “epsilon” f: 0.001 type: FLOAT } attribute { name: “momentum” f: 0.9 type: FLOAT } attribute { name: “spatial” i: 0 type: INT }