google-coral / edgetpu-platforms

EdgeTPU support for other platforms, specifically Raspberry Pi Zero
Apache License 2.0
81 stars 11 forks source link

USB Coral with pass-through into Ubuntu 19.04 in VirtualBox: Basic example fails with "Failed to allocate tensors" #4

Closed ChristophDerndorfer closed 5 years ago

ChristophDerndorfer commented 5 years ago

I tried running the basic example with the USB Coral that's connected to an Ubuntu 19.04 guest in a VirtualBox on a Windows 10 host via USB passthrough.

sudo lsusb shows that the dongle is connected successfully: Bus 002 Device 004: ID 18d1;9302 Google Inc

However, when I run the example command (python3 classify_image.py \ --model ~/Downloads/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \ --label ~/Downloads/inat_bird_labels.txt \ --image ~/Downloads/parrot.jpg) I only get:

Traceback (most recent call last): File "classify_image.py", line 67, in main() File "classify_image.py", line 58, in main engine = ClassificationEngine(args.model) ... Runtime error: Failed to allocate tensors.

A subsequent sudo lsusb doesn't show the USB Coral device anymore.

During the installation I also ran into the issue mentioned here and subsequently also executed the command that's supposed to enable the dirty work-around: cd /usr/local/lib/python3.7/dist-packages/edgetpu/swig/ && sudo ln -s _edgetpu_cpp_wrapper.cpython-3{6,7}m-x86_64-linux-gnu.so

Looking at other issues I also tried sudo usermod -aG plugdev [my username] and reboots (mentioned in #1 ) but to no avail.

IoTman commented 5 years ago

Try connecting the Coral USB device to your PC via a USB hub, I've had similar issues with other USB3 devices that works with some USB hubs, and not others. USB3 devices start up in USB2 mode, then a driver is loaded and the device reboots into USB3 mode. My failing devices/hub would cause similar symptoms, ie devices would disappear from the lsusb, and need repowered to reset. This was just plain Ubuntu, without your extra VM fun.

ChristophDerndorfer commented 5 years ago

Thanks for the recommendation. I had no luck with an unpowered (and fairly old) USB hub so I ordered a new powered one and will then report back.

ChristophDerndorfer commented 5 years ago

Unfortunately using the new powered USB hub didn't change anything. It also doesn't matter whether I connect the USB hub via my USB 2.0 or USB 3.0 ports (using a Lenovo T430) and use VirtualBox's USB 2.0 or USB 3.0 controller. I'll try to continue the investigation on the weekend.

ChristophDerndorfer commented 5 years ago

These instructions by @koji finally provided me with a solution:

Aside of adding the "Global Unichip Corp [0100]" device to VirtualBox's USB devices you also need to add a second filter for an arbitrarily called USB device with Vendor ID: 18d1 and Product ID: 9302:

image

Then the basic example suddenly worked like a charm:

image

hb020 commented 5 years ago

For the record: VMWare has the same problem. You need to pass through the "Google USB Device". If you see "Global Unichip Corp" in lsusb in the VM, or in the VMWare USB console, then it will not work. A reboot of the VM (not of the host) may be needed to see that device.

Screenshot 2019-06-15 at 17 55 49

lsusb inside the VM should show something like this: Bus 004 Device 002: ID 18d1:9302 Google Inc.

hb020 commented 5 years ago

After some digging, this is what I found with VMWare Fusion (and I guess VirtualBox is something like this):

It just needs an init from a first run and a forced logical disconnect from the original device. Instead of disconnect, a VM reboot sometimes also works, but it's not always successful. Any physical power down of the device will force you to go through the process again.

It might be possible to automate this.

F.I.:

Initially, both the VM and the host (MBP in my case), show the USB device as:

Product ID: 0x089a Vendor ID: 0x1a6e (Global Unichip Corp.)

After the "init + re-attach", both show the USB device as:

Product ID: 0x9302 Vendor ID: 0x18d1 (Google Inc.)

I have reached out to Google for guidance on making this easier.