tensorflow / tflite-support

TFLite Support is a toolkit that helps users to develop ML and deploy TFLite models onto mobile / ioT devices.
Apache License 2.0
378 stars 127 forks source link

ImportError from image_utils #952

Open alxhoff opened 1 year ago

alxhoff commented 1 year ago

Hi,

I hope I am correct here, a docker I have been using without problems for the past months started throwing an error today. The only difference I have noted recently on the docker I am using as my base image (tensorflow/tensorflow:latest-gpu) is that they have moved from python 3.10 to 3.11, so I have manually set python to Python 3.10.12 but the problem persists.

The error output is as follows

    sys.exit(main())
  File "/home/sources/TensorDSE/resources/model_summaries/CreateModelSummary.py", line 38, in main
    SummarizeGraph(args.model, args.outputdir, args.outputname)
  File "/home/sources/TensorDSE/resources/model_summaries/summarize.py", line 2, in SummarizeGraph
    from mltk.core import summarize_model
  File "/usr/local/lib/python3.10/dist-packages/mltk/core/__init__.py", line 7, in <module>
    from .tflite_model import *
  File "/usr/local/lib/python3.10/dist-packages/mltk/core/tflite_model/__init__.py", line 2, in <module>
    from .tflite_model import (
  File "/usr/local/lib/python3.10/dist-packages/mltk/core/tflite_model/tflite_model.py", line 13, in <module>
    from . import tflite_schema as _tflite_schema_fb
  File "/usr/local/lib/python3.10/dist-packages/mltk/core/tflite_model/tflite_schema.py", line 27, in <module>
    from tflite_support.schema_py_generated import *
  File "/usr/local/lib/python3.10/dist-packages/tflite_support/__init__.py", line 53, in <module>
    from tflite_support import task
  File "/usr/local/lib/python3.10/dist-packages/tflite_support/task/__init__.py", line 32, in <module>
    from . import vision
  File "/usr/local/lib/python3.10/dist-packages/tflite_support/task/vision/__init__.py", line 20, in <module>
    from tensorflow_lite_support.python.task.vision import image_classifier
  File "/usr/local/lib/python3.10/dist-packages/tensorflow_lite_support/python/task/vision/image_classifier.py", line 23, in <module>
    from tensorflow_lite_support.python.task.vision.core import tensor_image
  File "/usr/local/lib/python3.10/dist-packages/tensorflow_lite_support/python/task/vision/core/tensor_image.py", line 19, in <module>
    from tensorflow_lite_support.python.task.vision.core.pybinds import image_utils
ImportError: generic_type: cannot initialize type "StatusCode": an object with that name is already defined

To recreate the error minimally the docker image can be pulled and run using this Dockerfile.

wget https://github.com/alxhoff/TensorDSE/raw/master/resources/model_summaries/Dockerfile
docker build -t tensorflow/tensorflow:latest-gpu .
docker run -it tensorflow/tensorflow:latest-gpu /bin/bash 

and the minimal example should be there as test_summarize_model.py and should throw the error.

The code below is what is contained in test_summarize_model.py

from mltk.core import summarize_model
import wget

model_name = wget.download("https://github.com/alxhoff/TensorDSE/raw/master/resources/models/example_models/MNIST_full_quanitization.tflite")

summary = summarize_model(model_name, tflite=True)

print(summary)

If this is remotely the correct place to bring up an error like this please let me know what other information could be useful and a big thanks to anyone that takes the time to help.

Cheers,

Alex

alxhoff commented 1 year ago

I believe the problem is using a Tensorflow version > 2.13

nathan-stewart commented 10 months ago

Other discussion on this issue: https://github.com/ultralytics/ultralytics/issues/5161#issuecomment-1810548383

glenn-jocher commented 8 months ago

@alxhoff did you find any solution to this problem? I've been able to reproduce this bug by simply attempting to import the package in Google Colab, nothing more.

Screenshot 2024-02-19 at 16 52 04
alxhoff commented 8 months ago

Hi @glenn-jocher,

sadly not, had to stop using that set up.