hhk7734 / tensorflow-yolov4

YOLOv4 Implemented in Tensorflow 2.
MIT License
136 stars 75 forks source link

when using tensorflow not tflite runtime the load delegate method is not found to use coral #48

Closed fogelton closed 3 years ago

fogelton commented 3 years ago

in tflite/init bool variable can be added

tflitePresent=True
try:
    import tflite_runtime.interpreter as tflite
except ModuleNotFoundError:
    tflitePresent=False
    import tensorflow.lite as tflite

and later

        if tflitePresent:
            self.interpreter = tflite.Interpreter(
                model_path=tflite_path,
                experimental_delegates=[
                    tflite.load_delegate("libedgetpu.so.1")
                ],
            )
        else:
            self.interpreter = tflite.Interpreter(
                model_path=tflite_path,
                experimental_delegates=[
                    tflite.experimental.load_delegate("libedgetpu.so.1")
                ],
            )

to prevent the error, but maybe there is more elegant way :)

hhk7734 commented 3 years ago

On coral dev board?

fogelton commented 3 years ago

pc + usb coral

hhk7734 commented 3 years ago
try:
    import tflite_runtime.interpreter as tflite
    from tflite_runtime.interpreter import load_delegate
except ModuleNotFoundError:
    import tensorflow.lite as tflite
    from tensorflow.lite.experimental import load_delegate
        if self.tpu:
            self.interpreter = tflite.Interpreter(
                model_path=tflite_path,
                experimental_delegates=[load_delegate("libedgetpu.so.1")],
            )
        else:
            self.interpreter = tflite.Interpreter(model_path=tflite_path)

How about this? If you can test, please test and make pull request :)

fogelton commented 3 years ago

I just updated the package to the latest version and I get an import error for the load_delegate I do not know why.. i have tensorflow2.4 python3.8 when I execute python3 and only the given commands, the results:

import tensorflow.lite as tflite 2021-01-05 16:27:54.947757: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory 2021-01-05 16:27:54.947782: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. from tensorflow.lite.experimental import load_delegate Traceback (most recent call last): File "", line 1, in ImportError: cannot import name 'load_delegate' from 'tensorflow.lite.experimental'

when I execute the commands in python with tflite_runtime installed

import tflite_runtime.interpreter as tflite from tflite_runtime.interpreter import load_delegate

the load_delegate is imported successfully, this is very weird and above my knowledge

hhk7734 commented 3 years ago

I'm sorry. There seemed to be no problem, so I committed without testing. :(

Could you test the code below?

try:
    import tflite_runtime.interpreter as tflite
    from tflite_runtime.interpreter import load_delegate
except ModuleNotFoundError:
    import tensorflow.lite as tflite

    load_delegate = tflite.experimental.load_delegate
fogelton commented 3 years ago

it works, thanks