rockchip-linux / rknn-toolkit

BSD 3-Clause "New" or "Revised" License
802 stars 173 forks source link

E Calc node Loop : generic_loop_Loop__34 output shape fail #134

Closed AIGirl10 closed 2 years ago

AIGirl10 commented 2 years ago

We got this error while converting ssd_mobilenet_v1 model from ONNX to RKNN.

W Call onnx.optimizer.optimize fail, skip optimize
E Calc node Loop : generic_loop_Loop__34 output shape fail
W ----------------Warning(1)----------------
E Catch exception when loading onnx model: models/onnx/ssd_mobilenet_v1/latest_opset11.onnx!
E Traceback (most recent call last):
E   File "rknn/base/RKNNlib/onnx_ir/onnx_numpy_backend/shape_inference.py", line 60, in rknn.base.RKNNlib.onnx_ir.onnx_numpy_backend.shape_inference.infer_shape
E   File "rknn/base/RKNNlib/onnx_ir/onnx_numpy_backend/ops/loop.py", line 34, in   rknn.base.RKNNlib.onnx_ir.onnx_numpy_backend.ops.loop.Loop
E   File "rknn/base/RKNNlib/onnx_ir/onnx_numpy_backend/onnx_backend.py", line 135, in rknn.base.RKNNlib.onnx_ir.onnx_numpy_backend.onnx_backend.GraphRunner.run
E   File "rknn/base/RKNNlib/onnx_ir/onnx_numpy_backend/onnx_backend.py", line 128, in rknn.base.RKNNlib.onnx_ir.onnx_numpy_backend.onnx_backend.GraphRunner.run.pick_ref_tensor_value
E KeyError: '@parent_context'
E During handling of the above exception, another exception occurred:
E Traceback (most recent call last):
E   File "rknn/api/rknn_base.py", line 292, in rknn.api.rknn_base.RKNNBase.load_onnx
E   File "rknn/base/RKNNlib/RK_nn.py", line 141, in rknn.base.RKNNlib.RK_nn.RKnn.load_onnx
E   File "rknn/base/RKNNlib/app/importer/import_onnx.py", line 118, in rknn.base.RKNNlib.app.importer.import_onnx.Importonnx.run
E   File "rknn/base/RKNNlib/converter/convert_onnx.py", line 94, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx.__init__
E   File "rknn/base/RKNNlib/converter/convert_onnx.py", line 984, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx._shape_inference
E   File "rknn/base/RKNNlib/onnx_ir/onnx_numpy_backend/shape_inference.py", line 70, in rknn.base.RKNNlib.onnx_ir.onnx_numpy_backend.shape_inference.infer_shape
E   File "rknn/api/rknn_log.py", line 312, in rknn.api.rknn_log.RKNNLog.e
E ValueError: Calc node Loop : generic_loop_Loop__34 output shape fail
done
--> Build RKNN model...
Traceback (most recent call last):
  File "rknn_convert.py", line 89, in <module>
    convert_model(model_path, out_path, pre_compile)
  File "rknn_convert.py", line 72, in convert_model
    rknn.build(do_quantization=model['quantize'], dataset=dataset_path, pre_compile=pre_compile)
  File "/home/aigirl/.local/lib/python3.6/site-packages/rknn/api/rknn.py", line 241, in build
    inputs = self.rknn_base.net.get_input_layers()
AttributeError: 'NoneType' object has no attribute 'get_input_layers'

Steps we followed

  1. Created model_config.yml file here

    project-name: mobilenet-ssd
    models:
    mobilenet-ssd:
      platform: onnx
      model_file_path: frozen_inference_graph.onnx
      subgraphs:
          inputs:
            - image_tensor
    
          input-size-list:
            - 300,300,3
          outputs:
            - concat
            - concat_1
      quantize: true
      source: text
      dataset: ../../../../tensorflow/ssd_mobilenet_v1/dataset.txt
      configs:
        quantized_dtype: asymmetric_quantized-u8
        batch_size: 1
        mean_values: [[127.5, 127.5, 127.5]]
        std_values: [[127.5, 127.5, 127.5]]
        reorder_channel: 0 1 2
  2. Used conversion script to convert model and it gave this output.
    W Please confirm that your onnx opset_version <= 11 (current opset_verison = 12)!!!
    E Unknown shape of image_tensor:0, please specify input-size-list 
    • To get rid of warning we kept opset of onnx model to 11 and warning was gone.
    • To solve the error we fixed the input size in ONNX model to 300x300x3
  3. But now we are getting 3rd error, which is mentioned above
    E Calc node Loop : generic_loop_Loop__34 output shape fail

Can anyone please help with this ?

zen-xingle commented 2 years ago

If your model is trained with TensorFlow, please try to save the model as a frozen pb model and convert it to RKNN. This onnx error may be caused by the nonstandard convert rule and RKNN-Toolkit not recognizing it.

If your model is trained with PyTorch, please try to save the model as pt model(torch.jit.save) and convert it to RKNN.

If neither it's trained with PyTorch or TensorFlow, it's appreciated for you to upload the onnx model and our team will take a close look at this bug.

AIGirl10 commented 2 years ago

Thanks for reply. Model was trained in tensorflow, will try to convert to RKNN directly !