google-coral / edgetpu

Coral issue tracker (and legacy Edge TPU API source)
https://coral.ai
Apache License 2.0
426 stars 125 forks source link

Not compatible with tf-nightly #336

Closed Laxnring closed 3 years ago

Laxnring commented 3 years ago

Hi guys, I've been trying to use the pycoral library with the USB Accelerator, but, having had issues with the interpreter on the latest stable tensorflow version (2.4.1), I was forced to use the tf-nightly version. However I ran into the following error when importing both pycoral and tensorflow at the same time:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-05f0b9fbfbb6> in <module>
      5 from pycoral.adapters import segment
      6 
----> 7 import tensorflow as tf
      8 import numpy as np
      9 from tensorflow import keras

~\anaconda3\lib\site-packages\tensorflow\__init__.py in <module>
     53 from ._api.v2 import autograph
     54 from ._api.v2 import bitwise
---> 55 from ._api.v2 import compat
     56 from ._api.v2 import config
     57 from ._api.v2 import data

~\anaconda3\lib\site-packages\tensorflow\_api\v2\compat\__init__.py in <module>
     37 import sys as _sys
     38 
---> 39 from . import v1
     40 from . import v2
     41 from tensorflow.python.compat.compat import forward_compatibility_horizon

~\anaconda3\lib\site-packages\tensorflow\_api\v2\compat\v1\__init__.py in <module>
     32 from . import autograph
     33 from . import bitwise
---> 34 from . import compat
     35 from . import config
     36 from . import data

~\anaconda3\lib\site-packages\tensorflow\_api\v2\compat\v1\compat\__init__.py in <module>
     37 import sys as _sys
     38 
---> 39 from . import v1
     40 from . import v2
     41 from tensorflow.python.compat.compat import forward_compatibility_horizon

~\anaconda3\lib\site-packages\tensorflow\_api\v2\compat\v1\compat\v1\__init__.py in <module>
     49 from tensorflow._api.v2.compat.v1 import layers
     50 from tensorflow._api.v2.compat.v1 import linalg
---> 51 from tensorflow._api.v2.compat.v1 import lite
     52 from tensorflow._api.v2.compat.v1 import logging
     53 from tensorflow._api.v2.compat.v1 import lookup

~\anaconda3\lib\site-packages\tensorflow\_api\v2\compat\v1\lite\__init__.py in <module>
      9 
     10 from . import constants
---> 11 from . import experimental
     12 from tensorflow.lite.python.lite import Interpreter
     13 from tensorflow.lite.python.lite import OpHint

~\anaconda3\lib\site-packages\tensorflow\_api\v2\compat\v1\lite\experimental\__init__.py in <module>
      8 import sys as _sys
      9 
---> 10 from . import nn
     11 from tensorflow.lite.python.lite import convert_op_hints_to_stubs
     12 from tensorflow.lite.python.lite import get_potentially_supported_ops

~\anaconda3\lib\site-packages\tensorflow\_api\v2\compat\v1\lite\experimental\nn\__init__.py in <module>
      8 import sys as _sys
      9 
---> 10 from tensorflow.lite.python.lite import TFLiteLSTMCell
     11 from tensorflow.lite.python.lite import TfLiteRNNCell
     12 from tensorflow.lite.python.lite import dynamic_rnn

~\anaconda3\lib\site-packages\tensorflow\lite\python\lite.py in <module>
     49 from tensorflow.lite.python.convert import toco_convert_protos  # pylint: disable=unused-import
     50 from tensorflow.lite.python.convert_saved_model import freeze_saved_model as _freeze_saved_model
---> 51 from tensorflow.lite.python.interpreter import Interpreter  # pylint: disable=unused-import
     52 from tensorflow.lite.python.interpreter import load_delegate  # pylint: disable=unused-import
     53 from tensorflow.lite.python.op_hint import convert_op_hints_to_stubs  # pylint: disable=unused-import

~\anaconda3\lib\site-packages\tensorflow\lite\python\interpreter.py in <module>
     30     os.path.join('tflite_runtime', 'interpreter')):
     31   # This file is part of tensorflow package.
---> 32   from tensorflow.lite.python.interpreter_wrapper import _pywrap_tensorflow_interpreter_wrapper as _interpreter_wrapper
     33   from tensorflow.python.util.tf_export import tf_export as _tf_export
     34 else:

ImportError: generic_type: type "InterpreterWrapper" is already registered!

I've since been able to mitigate the problem by wrapping the tensorflow call of the tensorflow lite interpreter wrapper in a try...except... block. However this is hardly a good solution. Is there any way anyone could take a look at this?

Library versions ersions:

Namburger commented 3 years ago

@Laxnring what does you try catch block looks like? I believe this is an issue because both pycoral and tensorflow owns an instance of the tflite interpreter..

Laxnring commented 3 years ago

Yes, exactly, that seems to be the issue. Therefore, I put the try catch block around the call for interpreter wrapper by tensorflow lite.

manoj7410 commented 3 years ago

@Laxnring Were you able to resolve this issue ?

manoj7410 commented 3 years ago

Feel free to reopen this thread if the issue still persists.

Vindhya07 commented 3 years ago

I have tried the try/catch block approach and it didnt work :( Is this a new modification to the library, cuz it was working fine a month ago