google-coral / edgetpu

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

Yolov8n inference is crashing with Deadline exceeded: USB transfer error 2 [LibUsbDataOutCallback] #773

Open yrik opened 1 year ago

yrik commented 1 year ago

Description

I've compiled a default Yolov8n model for edgetpu but it's crashing when I try inferencing.

I'm running it on raspberry 4 with coral tpu dongle

Issue Type

Bug

Operating System

Linux

Coral Device

USB Accelerator

Other Devices

Rapsberry Pi 4

Programming Language

Python 3.9

Relevant Log Output

yura@malyna:~/coral/pycoral$ python3.9 examples/classify_image.py --model ../../yolov8n_edgetpu_edgetpu.tflite --labels test_data/inat_bird_labels.txt --input test_data/parrot.jpg
/home/yura/coral/pycoral/examples/classify_image.py:79: DeprecationWarning: ANTIALIAS is deprecated and will be removed in Pillow 10 (2023-07-01). Use LANCZOS or Resampling.LANCZOS instead.
  image = Image.open(args.input).convert('RGB').resize(size, Image.ANTIALIAS)
----INFERENCE TIME----
Note: The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory.
F driver/usb/usb_driver.cc:857] transfer on tag 1 failed. Abort. Deadline exceeded: USB transfer error 2 [LibUsbDataOutCallback]
yrik commented 1 year ago

Archive.zip I've attached the .tflite and _edtetpu.tflite versions of the model.

Alan01252 commented 11 months ago

Did you have any luck with this @yrik I'm having the same thing. I've seen that some of this is related to power issues, but I have my coral plugged into a desktop with full USB-powered ports and am getting the same error

yrik commented 10 months ago

Did you have any luck with this @yrik I'm having the same thing. I've seen that some of this is related to power issues, but I have my coral plugged into a desktop with full USB-powered ports and am getting the same error

I've realized that coral tpu does not support bigger models, so if you have many classes or higher resolution, it will crash. For me, 2 classes with 640x640 were working fine but with 80 classes it was crashing.

ukicomputers commented 4 months ago

That same happens to me. By the way, @yrik, how you were trained model to work (code in Python, or using yolo-cli)? Help is appriciated. Thanks in advance.

ukicomputers commented 4 months ago

So while reading other issues, I also discovered that it's not problem with classes (as the @yrik said), but just one thing: the image size. As YOLOv8 is large model (even if used YOLOv8n), the computation power and loading is not enough to start the processing. This is just from reading other issues. The key for it to work is:

To convert model to edgetpu format and achieve proper results without crashing while inference with TPU, just run this command (uses YOLO-CLI and YOLOv8n pre-trained model):

yolo export model=yolov8n.pt format=edgetpu imgsz=192,192

I hope this helps for beginners.