nncase icon indicating copy to clipboard operation
nncase copied to clipboard

Fatal: Data type of input "278" is not supported

Open prakharg24 opened this issue 5 years ago • 4 comments

I am trying to convert a model from pytorch to kmodel. I have been following the instructions from the Face Detection repo (https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB) and the demo in the nncase repo (https://github.com/kendryte/nncase/tree/master/examples/fast_facedetect). Replicating everything as is works fine.

The above model conversion flow is pytorch -> onnx -> onnx-simplified -> caffe -> kmodel. Clealry, there is an additional unnecessary step, converting model from onnx to caffe, not to mention that caffe to kmodel conversion supports far less number of layers than onnx to kmodel. So I tried to eliminate it.

First, I simply tried the conversion flow pytorch -> onnx -> kmodel. However, this does not work since there are batch normalization layers, 'shape' layers, etc. present in the model. Thus I needed to 'simplify' the onnx model using onnx simplifier (https://github.com/daquexian/onnx-simplifier).

Unfortunately, when I try to follow the conversion flow pytorch -> onnx -> onnx-simplified -> kmodel, I am facing a different kind of error. I get the error Fatal: Data type of input "278" is not supported . Here, the 278th layer is connected to a reshape, which is most probably the issue. I found this thread discussing the same : https://github.com/kendryte/nncase/issues/117

According to the above thread which I have linked here, the issue should be already solved. But even after using the latest nncase version and compiling the binary on my own, I am facing the exact same issue. I also tried the same with the latest release (v0.2.0 beta4), and some other intermediate version, but kept facing the exact same issue.

Assuming the issue I am facing is the same as the one described in the link above, probably the Int64 datatype was solved in some earlier branch, but has since resurfaced.

Bottom line : I want to remove going through the caffe route for model conversion, since I would like to add in more complex layers that are only supported during the onnx to kmodel conversion, but it seems that the reshape layer in my model is stopping me from doing so.

@cscribano I see that you were the one found the issue earlier. Do you have any insights on what issue I might be facing now, and if there is a more sure way of debuging? I am relatively new to the world of mobile computing and nncase. Thank You.

Please find the onnx model attached, which causes the error during onversion. Ultra-slim-320-simplified.zip

prakharg24 avatar Jan 06 '21 06:01 prakharg24

Hi @prakharg24 ,

I'm new to onnx and I am learning as well. So hope this makes sense.

I found out the reason why your onnx file is not working while the example in issue #117 is ok.

When I looked at your onnx file, I noticed "278" is declared as input and initializer. When declared as input,

const auto input_dt { get_datatype(input_info) };

will return a not supported type. As it looks for either float of uint8. Since "278" is INT64, it throws an error.

This is your onnx file...

  node {
    input: "269"
    input: "278"
    output: "279"
    op_type: "Reshape"
  }
  initializer {
    dims: 3
    data_type: 7
    name: "278"
    raw_data: "\001\000\000\000\000\000\000\000\377\377\377\377\377\377\377\377\002\000\000\000\000\000\000\000"
  }

  input {
    name: "278"
    type {
      tensor_type {
        elem_type: 7
        shape {
          dim {
            dim_value: 3
          }
        }
      }
    }
  }

I compared to the example found in issue #117 it is only delcared as initializer and not as input. I am not sure what causes the differences, it could be due to onnx-simplifier.

  node {
    input: "3"
    input: "4"
    output: "output_1"
    op_type: "Reshape"
  }
  initializer {
    dims: 3
    data_type: 7
    name: "4"
    raw_data: "\001\000\000\000\000\000\000\000\003\000\000\000\000\000\000\000\020\003\000\000\000\000\000\000"
  }


To create a workaround, I modified around line 121 of onnx_importer.cpp to the following


        const auto& type { input_info.type() };
        const auto& ValueInfoProto = static_cast<TensorProto_DataType>(type.tensor_type().elem_type());

        if (ValueInfoProto == TensorProto_DataType_INT64) {
            continue;
        }

        if (!input_dt)
            throw runtime_error("Debug 1 : Data type of input \"" + input_name + "\" is not supported");

xalogic-linus avatar Jan 06 '21 14:01 xalogic-linus

@xalogic-linus I met this problem too.

To create a workaround, I modified around line 121 of onnx_importer.cpp to the following

After modifying the code, the kmodel can be genrated. Is the generated kmodel output result affected? the kmodel result is same as orignal onnx model output?

Thank you.

xiaxinkai avatar May 23 '21 06:05 xiaxinkai

Please use the features/upgrade branch to try again. I can build the attached onnx model for k210 target successfully.

zhangyang2057 avatar Jun 29 '21 01:06 zhangyang2057

The 278 is a shape with 'int64' type, which is not supported before.
Now onnx_importer::get_datatype() can support int64 type. I can use the latest nncase to build the Ultra-slim-320-simplified.onnx successfully now. If you have any problem, please summit a new issue. Thanks.

zhangyang2057 avatar Jul 26 '21 09:07 zhangyang2057