tflite2onnx icon indicating copy to clipboard operation
tflite2onnx copied to clipboard

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

Open zhang0557kui opened this issue 3 years ago • 6 comments

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

zhang0557kui avatar Nov 24 '21 08:11 zhang0557kui

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.

zhenhuaw-me avatar Dec 20 '21 07:12 zhenhuaw-me

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

zhang0557kui avatar Dec 30 '21 05:12 zhang0557kui

Same issue when trying to convert palm_detection_full.

Amadeus-AI avatar Jan 18 '22 02:01 Amadeus-AI

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

Amadeus-AI avatar Jan 19 '22 08:01 Amadeus-AI

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.

crazySyaoran avatar Jun 08 '22 09:06 crazySyaoran

@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.

zhenhuaw-me avatar Jun 15 '22 10:06 zhenhuaw-me