zhenhuaw-me / tflite2onnx

Convert TensorFlow Lite models (*.tflite) to ONNX.
https://zhenhuaw.me/tflite2onnx
Apache License 2.0
149 stars 26 forks source link

transfrom_axis = [input[p] for p in perm] IndexError: list index out of range #72

Open zhang0557kui opened 2 years ago

zhang0557kui commented 2 years ago

File "D:\anaconda3\lib\site-packages\tflite2onnx\layout.py", line 27, in transform output = transform(input, self.source, self.target) File "D:\anaconda3\lib\site-packages\tflite2onnx\layout.py", line 16, in transform transfrom_axis = [input[p] for p in perm] File "D:\anaconda3\lib\site-packages\tflite2onnx\layout.py", line 16, in transfrom_axis = [input[p] for p in perm] IndexError: list index out of range python-BaseException

zhenhuaw-me commented 2 years ago

Hi @zhang0557kui thank you for reporting this issue. Could you help to attach the model that triggers the error? It seems to me that the model raised our semantic assumption somehow.

zhang0557kui commented 2 years ago

Hi @zhang0557kui thank you for reporting this issue. Could you help to attach the model that triggers the error? It seems to me that the model raised our semantic assumption somehow.

https://github.com/google/mediapipe/blob/master/mediapipe/modules/palm_detection/palm_detection_full.tflite

Amadeus-AI commented 2 years ago

Same issue when trying to convert palm_detection_full.

Amadeus-AI commented 2 years ago

It maybe a PReLu related issue https://github.com/NVIDIA/TensorRT/issues/310

crazySyaoran commented 2 years ago

same issue when converting this model: https://github.com/google/mediapipe/tree/master/mediapipe/modules/face_landmark/face_landmark.tflite

I solved this probelm temporary by changing this two files in your lib code:

# tflite2onnx/tensor.py
...
    def transform(self):
        assert(self.status.parsed)
        assert(self.layout is not None)
        if self.isInitializer:
            data = self.data.reshape(self.shape)
            self.shape = self.layout.transform(self.shape)
            if(len(self.shape)<4):
                self.data = data.transpose([2,0,1])
            else:
                self.data = data.transpose(self.layout.perm)
        else:
            self.shape = self.layout.transform(self.shape)
...

and

# tflite2onnx/layout.py
...
def transform(input, ilayout: str, olayout: str):
    if (ilayout == olayout):
        return input

    perm = getPerm(ilayout, olayout)
    if(len(input) < 4):
        # print(input)
        transfrom_axis = [input[2], input[0], input[1]]
        # transfrom_axis =  [input[0], input[2], input[1]]
    else:
        transfrom_axis = [input[p] for p in perm]
    return transfrom_axis
...

By the way, I have another problem when converting another model: https://github.com/google/mediapipe/tree/master/mediapipe/modules/face_landmark/face_landmark_with_attention.tflite cuz there's some "CUSTOM" ops, such as No.192, No.193. Is there any solutions to convert this tflite model?

thx.

zhenhuaw-me commented 2 years ago

@crazySyaoran Glad to hear that you resolved this issue!

I was assuming the two inputs of PReLU have the same rank, but they should be broadcastable. I think we can share the Binary.fakeBroadcast() with PReLU. Do you have time to try if the fakeBroadcast works for PReLU?

For custom ops, unfortunality, tflite2onnx cannot convert such ops as of now. But it's encouraged to introduce a design for custome operators and bridge to ONNX. As first step, we can take the custom op as blackbox - we don't care what the semantic of it, but only track the tensors of it.