Search code examples
tflitequalcommsnpe

snpe-tflite-to-dlc in qualcomm neural processing sdk gives error while converting tflite to dlc


I am trying to convert a .tflite model to .dlc using snpe-tflite-to-dlc in wsl ubuntu 20.4 using tflite version 2.3.1, installed in python 3.8 virtual environment. I got an error as attached below:

2024-04-12 11:25:29,364 - 230 - ERROR - Encountered Error: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
Traceback (most recent call last):
  File "/mnt/c/Qualcomm/AIStack/SNPE/2.20.0.240223/bin/x86_64-linux-clang/snpe-tflite-to-dlc", line 51, in main
    converter = TFLiteConverterFrontend(args)
File"/mnt/c/Qualcomm/AIStack/SNPE/2.20.0.240223/lib/python/qti/aisw/converters/tflite/tflite_to_ir.py", line 23, in __init__
    super(TFLiteConverterFrontend, self).__init__(args,
  File "/mnt/c/Qualcomm/AIStack/SNPE/2.20.0.240223/lib/python/qti/aisw/converters/relay/relay_to_ir.py", line 324, in __init__
    self.importer.convert_to_relay(self.input_model_path,
  File "/mnt/c/Qualcomm/AIStack/SNPE/2.20.0.240223/lib/python/qti/aisw/converters/relay/importers/tflite_importer.py", line 115, in convert_to_relay
    self.mod, self.params = tflite_to_relay.from_tflite(tflite_model,
  File "/mnt/c/Qualcomm/AIStack/SNPE/2.20.0.240223/lib/python/qti/tvm/relay/frontend/tflite.py", line 4608, in from_tflite
    tensor = subgraph.Tensors(tensor_idx)
  File "/home/rosemol_30/PYTHON3.8_VENV_ROOT/lib/python3.8/site-packages/tflite/SubGraph.py", line 26, in Tensors
    x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

If you have any knowledge, please help me. Thanks in advance.

I tried with changing different tensorflow and tflite versions, but it does not work.


Solution

  • This error usually means you have incorrectly specified the input tensors and their dimensions in the command. For whichever model you're using, you need to make sure you specify each input tensor by name and dimension by referring to it's name exactly. You can use a tool like Netron or other model viewers to find the names of these inputs as well as their dimensions.

    Take for example the following Segment Anyting Model .tflite file, viewed in Netron:

    Netron view of 5-input model

    It has 5 inputs, each with a specified name and input dimensions of datatype float32. The appropriate command for converting this .tflite model would be:

    snpe-tflite-to-dlc \
            --input_network sam.tflite \
            --input_dim image_embeddings "1,256,64,64" \
            --input_dim point_coords "1,1,2" \
            --input_dim point_labels "1,1" \
            --input_dim mask_input "1,1,256,256" \
            --input_dim has_mask_input "1" \
            --output_path sam.dlc
    

    While I am unsure if the error you are getting can have other causes, but I would always receive an identical error as yourself when the input tensors were not correctly specified. For the specific model in the example, the conversion still fails due to an unsupported operator, but that is unrelated to this and I have converted many models successfully using commands like the above one in the past.

    You can read more about snpe-tflite-to-dlc snpe-tflite-to-dlc docs, where each argument is explained in detail.