apache / tvm

Open deep learning compiler stack for cpu, gpu and specialized accelerators
https://tvm.apache.org/
Apache License 2.0
11.67k stars 3.45k forks source link

[Bug] [TFLite] AttributeError: 'ResizeBilinearOptions' object has no attribute 'HalfPixelCenters' #15066

Open ChaojifeixiaDazhuang opened 1 year ago

ChaojifeixiaDazhuang commented 1 year ago

When I load a TFlite model with relay.frontend.from_tflite API, I get an AttributeError, as show below:

Actual behavior

Traceback (most recent call last): File "tflite_main.py", line 59, in <module> mod, params = relay.frontend.from_tflite(tflite_model) File "/workspace/tvm/python/tvm/relay/frontend/tflite.py", line 4205, in from_tflite op_converter.convert_op_to_relay() File "/workspace/tvm/python/tvm/relay/frontend/tflite.py", line 276, in convert_op_to_relay ret = self.convert_map[op_code_str](op) File "/workspace/tvm/python/tvm/relay/frontend/tflite.py", line 748, in convert_resize_bilinear return self._convert_resize("linear", op) File "/workspace/tvm/python/tvm/relay/frontend/tflite.py", line 726, in _convert_resize half_pixel_centers = resize_options.HalfPixelCenters() AttributeError: 'ResizeBilinearOptions' object has no attribute 'HalfPixelCenters

Environment

Root Cause and Solution

  1. Because I followed the documentation guide and install the TFLite with version 2.1.0,so we can modify the documentation with a higher TFlite version(such as 2.10.0)
  2. We can modify this line https://github.com/apache/tvm/blob/f172f6c70d8e72556225877c7522ef13b7b250e2/python/tvm/relay/frontend/tflite.py#L726 with: try: half_pixel_centers = resize_options.HalfPixelCenters() except AttributeError: half_pixel_centers = False As for ResizeBilinear Op, this attribution default to be false:https://www.tensorflow.org/api_docs/cc/struct/tensorflow/ops/resize-bilinear/attrs#:~:text=TF_MUST_USE_RESULT%20Attrs-,Defaults%20to%20false.,-Public%20attributes

Guys, do you have any suggestions?

Triage

cc @leandron

bethalianovike commented 4 months ago

Hi @ChaojifeixiaDazhuang I also encounter this problem recently, do you have any solution right now?

alalalsam commented 3 months ago

seems to be related to PyTorch models: https://github.com/pytorch/pytorch/issues/48389 maybe something hacky happens when pytorch models are converted to tensorflow models, at least that's my case.

Nevermind, I just installed latest tensorflow (pip3 install --upgrade tensorflow) which didnt fix anything, but then installed new tflite and it randomly fixed itself (pip install --upgrade tflite)