-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running Detect on Edge TPU gives error "ImportError: generic_type: type "InterpreterWrapper" is already registered!" #5709
Comments
@phodgers thanks for the bug report! I searched online but no answers: Does this happen with default tflite export also or only with --int8? |
This seems to happen only when the 'edgetpu' label is added in the file name, so when it is switching over for Edge TPU inferencing. If I run the same file with original name yolov5s-int8.tflite it inferences on the CPU.
|
@phodgers yes edgetpu filenames use a different route: Lines 335 to 348 in 8df64a9
|
I have confirmed this on both Windows and Raspberry Pi systems. It seems line 321 of yolov5/models/common.py
causes the issue, when there is both Tensorflow and Tensoflow Lite on the system. So perhaps this section of code needs refactored when dealing with TFLITE files. |
@phodgers I looked a little closer into this. I am able to reproduce an error on a fresh Colab notebook: Loading yolov5s-int8-edgetpu.tflite for TensorFlow Edge TPU inference...
Traceback (most recent call last):
File "detect.py", line 244, in <module>
main(opt)
File "detect.py", line 239, in main
run(**vars(opt))
File "/usr/local/lib/python3.7/dist-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "detect.py", line 79, in run
model = DetectMultiBackend(weights, device=device, dnn=dnn)
File "/content/yolov5/models/common.py", line 338, in __init__
import tflite_runtime.interpreter as tfli
ModuleNotFoundError: No module named 'tflite_runtime' But the user is expected to have installed TFLite Edge TPU dependencies indicated in the comments in this section before attempting inference, i.e. on L335 and L339: Lines 335 to 342 in f17c86b
|
@glenn-jocher Yes, your error indicates you also need to install TFLite. But when you install TFLite, you then get the error I posted at the top (when trying to use detect.py with edgetpu inference). I found that I could successfully run the detect.py for edgetpu by commenting out line 321, since for the detection, edgetpu only needs TFLite. So I think there needs to be some refactoring to use TF library for when exporting (used for .TFLITE export, according to requirements.txt) and TFLite library for detection, but not to try to refer to both in same script since it brings up that error about the InterpreterWrapper already being registered. |
@phodgers oh ok I understand now. So you're saying we need to scope the tensorflow import better. Please submit a PR with the improved import scoping you had in mind, thank you! Please see our ✅ Contributing Guide to get started. |
As per bug report ultralytics#5709 I think there should be only one attempt to assign interpreter, and it appears tflite is only ever needed for the case of edgetpu model.
* tensorflow or tflite exclusively as interpreter As per bug report #5709 I think there should be only one attempt to assign interpreter, and it appears tflite is only ever needed for the case of edgetpu model. * Scope imports * Nested definition line fix * Update common.py Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* tensorflow or tflite exclusively as interpreter As per bug report ultralytics#5709 I think there should be only one attempt to assign interpreter, and it appears tflite is only ever needed for the case of edgetpu model. * Scope imports * Nested definition line fix * Update common.py Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* tensorflow or tflite exclusively as interpreter As per bug report ultralytics/yolov5#5709 I think there should be only one attempt to assign interpreter, and it appears tflite is only ever needed for the case of edgetpu model. * Scope imports * Nested definition line fix * Update common.py Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* tensorflow or tflite exclusively as interpreter As per bug report ultralytics/yolov5#5709 I think there should be only one attempt to assign interpreter, and it appears tflite is only ever needed for the case of edgetpu model. * Scope imports * Nested definition line fix * Update common.py Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Search before asking
YOLOv5 Component
Detection
Bug
C:\Users\Philip\Downloads\yolov5>python detect.py --weights yolov5s-int8-edgetpu.tflite
detect: weights=['yolov5s-int8-edgetpu.tflite'], source=data\images, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs\detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False
YOLOv5 v6.0-96-g8df64a9 torch 1.10.0+cu113 CUDA:0 (NVIDIA GeForce GTX 950A, 2048MiB)
Loading yolov5s-int8-edgetpu.tflite for TensorFlow Edge TPU inference...
Traceback (most recent call last):
File "C:\Users\Philip\Downloads\yolov5\detect.py", line 244, in
main(opt)
File "C:\Users\Philip\Downloads\yolov5\detect.py", line 239, in main
run(**vars(opt))
File "C:\Users\Philip\AppData\Local\Programs\Python\Python39\lib\site-packages\torch\autograd\grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "C:\Users\Philip\Downloads\yolov5\detect.py", line 79, in run
model = DetectMultiBackend(weights, device=device, dnn=dnn)
File "C:\Users\Philip\Downloads\yolov5\models\common.py", line 338, in init
import tflite_runtime.interpreter as tfli
File "C:\Users\Philip\AppData\Local\Programs\Python\Python39\lib\site-packages\tflite_runtime\interpreter.py", line 41, in
from tflite_runtime import _pywrap_tensorflow_interpreter_wrapper as _interpreter_wrapper
ImportError: generic_type: type "InterpreterWrapper" is already registered!
Environment
YOLOv5 v6.0-96-g8df64a9
WIndows 10
Minimal Reproducible Example
Additional
No response
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: