DEV Community


Posted on • Updated on

Coral EdgeTPU USB Accelerator with VirtualBox

I got Coral USB stick last month. I've been playing that with Raspberry Pi3.
That is a very cool product because with Coral USB the performance is pretty good.

But, the thing is Raspberry Pi3B+ cannot use USB3.0 which means data transferring between Pi and Coral is limited.

So I really wanted to use Coral with USB3.0, however, unfortunately recently Parallel Desktop lite got a paid software and I didn't install it on Mac(not sure why).

In this post, I will explain how to set up VirtualBox env for Coral. I think it's been a while since the last time I used VirtualBox.

1 Get VirtualBox

You need to get the latest one since I tried to use 5.2.22(not the latest version) and spent so much time then it didn't work. Once I switched from 5.2.22 to 6.0.6. Everything works perfectly.

2 Get Ubuntu (LTS version)

I think you can use 16.04 or 18.04. I'm using 18.04 since I use that for my GPU machine for training models. Maybe you can use 19.04, but not sure.

3 Install Ubuntu on VirtualBox

This article is very useful if you don't have any experience with VirtualBox.

4 Add USB Device Filters

This is the most important part of this article.
When you do this, you have to turn off your virtual machine
Settings > Ports > USB

(the machine is running. sorry I'm lazy...)

If you power off your machine, you can select USB3.0. Then you need to add 2 USB Device Filters. Probably you just need to add one the following.

3-1. Click Add button
3-2. Select Global Unichip Corp [0100]
3-3. Add one more
3-4. Select one filter you added and edit filter settings
filter setting

Name: you can put anything you want
Vendor ID: 18d1
Product ID: 9302

5 Setup EdgeTPU

We are almost there. You can follow the link.

Seems Google update edgetpu, so we don't need to change the install shell script anymore, but I think edgetpu is optimized for python3.5.
So I set up a virtual environment for that. As you know there are some ways to set up virtual env. virtualenv, virtualenvwrapper, pyenv, pipenv and anaconda.
For this, I decided to use Anaconda since it just needs to type a couple of commands to set up the python3.5 environment.

Digital Ocean has a nice article on that.

After activating your virtual environment, probably you will need this.

$ pip install edgetpu-1.9.2-py3-none-any.whl
Enter fullscreen mode Exit fullscreen mode

6 Run demo

Just follow the official guide (easy easy easy)

$ cd /usr/local/lib/python3.6/dist-packages/edgetpu/demo

$ python3 \
--model ~/Downloads/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
--label ~/Downloads/inat_bird_labels.txt \
--image ~/Downloads/parrot.jpg

Ara macao (Scarlet Macaw)
Score :  0.761719
Enter fullscreen mode Exit fullscreen mode

Coral repos are on Github

Additional Information

I just noticed that this post only works for the first time since something will change the Coral Edge TPU USB's Vender ID and Product ID

The solution

  1. Remove the first settings

    Vendor ID: 18d1

    Product ID: 9302

  2. Add a new one

    Vendor ID: 1a6e

    Product ID: 089a

    Probably these will work, but make sure that your Terminal app shows them when you run lsusb on your Mac.

  3. Reboot VirtualBox

  4. Devices --> USB --> Google, Inc

Top comments (14)

ebendl profile image
Eben de Lange

hi Koji, thanks for writing this up.

I got it working thanks to your instructions. My biggest problem was that my old laptop, an Asus N53SV where I was planning on running this with from Windows 10 as host with Ubuntu 18.04 LTS in Virtualbox 6.1. This laptop uses a FrescoLogic FL1000 chip for USB 3.0 and it is absolutely incompatible with Linux and the Google TPU. I couldn't get it working in baremetal with Ubuntu, I couldn't get it working in VirtualBox.

VirtualBox sometimes gives a message saying that it failed to attach the device. In Linux itself I would get it in lsusb for brief second, only to disappear again.

Plugging the TPU into a USB2 port (Intel chipsets on this machine) works perfectly with your instructions, other than I didn't even need to change the USB filters afterwards.

0xkoji profile image

Now you can use Coral EdgeTPU USB Accelerator without VirtualBox.

alsuren profile image
David Laban

Thanks for writing this up.

I have tried to encode these setup instructions in a Vagrantfile here: (using Ubuntu bionic LTS, because it already has a supported version of python).

If you have a coral device and a Mac, please try out my branch and add your feedback to the PR.

0xkoji profile image

nice! i will try it on weekend.

hb020 profile image
hb020 • Edited

Thanks for the find. Now I got this working once on my MBP, but now I am no longer able to get it working. Tried SMC reset, rebooting the host and the VM, (latest)VirtualBox with the above tweak of the extra USB device, VMWare Fusion with and without the equivalent tweak in the vmx file, other USB ports and external powered ports. All no luck. I no longer get the "18d1:9302 Google Inc" device when I do "lsusb" in the VM, nor do I see it in the list of USB devices through MacOS's System Report (all I see is the composite device from Global Unichip).
Anyone having a Macbook Pro that has succeeded in keeping it working?
So in essence, the solution above is partial, those on Mac might hit extra hurdles.

0xkoji profile image

Hey @hb020

Thank you for telling me this.

I just checked what you said.
I think I know what the issue is.
Will add the solution for that issue soon.

hb020 profile image

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

  • plug in the Coral USB accelerator
  • start VMWare Fusion
  • start the (Ubuntu/Debian) VM
  • in the VM settings, attach the "Global Unichip device" to USB
  • run the engine (classify or detection)
  • it will fail with "RuntimeError: Failed to allocate tensors"
  • in the VM settings, remove the Global Unichip device from USB. DO NOT UNPLUG!
  • you will see it suddenly becomes "Google USB Device"
  • in the VM settings, attach the "Google USB Device" to USB
  • and all is well

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.


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.

Thread Thread
0xkoji profile image

okay cool, that is what i did exactly.
i think the issue is vbox since i haven't had any issues with raspberry pi and another device

oveddan profile image
Dan Oved

Koji, when I run the final command:
python3 \
--model ~/Downloads/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
--label ~/Downloads/inat_bird_labels.txt \
--image ~/Downloads/parrot.jpg

I get an error:

RuntimeError: Mmap of '/home/dan/Downloads/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite' failed

Any idea what happens

oveddan profile image
Dan Oved

Nevermind...the file wasn't properly downloaded

oveddan profile image
Dan Oved

And one more question:

In your usb setup you have 3 usb devices, but the guide only shows setting up 2. Where does the "coral" device come from?

0xkoji profile image

My bad, "coral" is dummy lol.
You just need 2. One is the modified version and the other is no-modified version.

You can come to the resident office during the lunchtime.

oveddan profile image
Dan Oved • Edited I get another error:

"RuntimeError: Failed to allocate tensors"

Have you seen this?

0xkoji profile image

Hey Dan,
Are you using the latest VirtualBox?