Coral USB inference not working on Windows 10 (ValueError: Failed to load delegate from edgetpu.dll)

Update: It looks like the Error has ben fixed with the installer version from Octobre 24th 2022.

Following the install instructions for Windows on the Coral website, I got the following error:

Max@Rhea MINGW64 /c/Business-2022/pi3g e.K/Marketing/2022 Präsentation für Ric/Coral on Windows/coral/pycoral (master)
$ pyenv exec python examples/classify_image.py \
> --model test_data/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
> --labels test_data/inat_bird_labels.txt \
> --input test_data/parrot.jpg
Traceback (most recent call last):
  File "C:\Users\Max\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\tflite_runtime\interpreter.py", line 160, in load_delegate
    delegate = Delegate(library, options)
  File "C:\Users\Max\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\tflite_runtime\interpreter.py", line 119, in __init__
    raise ValueError(capture.message)
ValueError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Business-2022\pi3g e.K\Marketing\2022 Präsentation für Ric\Coral on Windows\coral\pycoral\examples\classify_image.py", line 121, in <module>
    main()
  File "C:\Business-2022\pi3g e.K\Marketing\2022 Präsentation für Ric\Coral on Windows\coral\pycoral\examples\classify_image.py", line 71, in main
    interpreter = make_interpreter(*args.model.split('@'))
  File "C:\Users\Max\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\pycoral\utils\edgetpu.py", line 87, in make_interpreter
    delegates = [load_edgetpu_delegate({'device': device} if device else {})]
  File "C:\Users\Max\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\pycoral\utils\edgetpu.py", line 52, in load_edgetpu_delegate
    return tflite.load_delegate(_EDGETPU_SHARED_LIB, options or {})
  File "C:\Users\Max\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\tflite_runtime\interpreter.py", line 162, in load_delegate
    raise ValueError('Failed to load delegate from {}\n{}'.format(
ValueError: Failed to load delegate from edgetpu.dll

The last line, “ValueError: Failed to load delegate from edgetpu.dll” usually means that no Coral USB device could be recognized. (If you unplug your Coral USB device, you should continue to see the same error).

I was able to track this down to a bug (I think!) in the install script for Windows.

The bug is present in the newest two releases of libedgetpu.

The install script, which the Coral team ships and which I executed is called install.bat

line 52 of this script (you can open it using a text editor, for example Notepad++) states:

start /wait msiexec /i "%ROOTDIR%\third_party\usbdk\UsbDk_*.msi" /quiet /qb! /norestart

This is supposed to install UsbDk. And it should look like this:

So – an external installer for UsbDk opens, and installs it. During the Windows Security screen (UAC, User Account Control, Screen) something about RedHat is mentioned.

I guess that this application never opens and installs on your computer, does it?

But it is required by the Coral USB application stack, this is a special software which allows applications to access custom USB devices.

Here I have good news and bad news for you.

Let’s start with the good news first: I managed to create a fix for that.

The fix for UsbDk not being installed / Failed to load delegate from edgetpu.dll

Update 5.11.2022:

Good news! We have released a patched Runtime Installer ZIP file, which solves two bugs and allows you to install the latest Coral runtime contained in 20220308.

This works with the newest runtime, as it also switches libusb-1.0.dll to a working version (taken from a previous package). We have tested this on Windows 8.1 and Windows 10. This patched package resolves the “Failed to delegate” error, and also the segmentation faults.

Report any issues in the comments below!

historic content explaining the background

Before you try the fix, please read the bad news too! (The fix works, but there is a different problem which probably only Google can solve! I recommend: Go to the third solution “The better news” for now!)

Just to be on the safe side, first run uninstall.bat

Overwrite this line (line 52) with two new lines as follows:

:: start /wait msiexec /i "%ROOTDIR%\third_party\usbdk\UsbDk_*.msi" /quiet /qb! /norestart
start /wait msiexec /i "%ROOTDIR%\third_party\usbdk\UsbDk_1.0.22_x64.msi" /quiet /qb! /norestart

The double colon will comment the original line (I prefer to leave original lines in the code for these fixes, so we can see what had been modified)

Now when you run install.bat by double-clicking it, it WILL install UsbDk.

UsbDk being installed

Note: while UsbDk is being installed, I can hear the well-known Windows USB unplug / replug sound!

Removing UsbDk

Note that the uninstall.bat has the same issue. Edit the line 51

:: start /wait msiexec /x "%ROOTDIR%\third_party\usbdk\UsbDk_*.msi" /quiet /qb! /norestart
start /wait msiexec /x "%ROOTDIR%\third_party\usbdk\UsbDk_1.0.22_x64.msi" /quiet /qb! /norestart

This will allow you to actually execute the UsbDk installer for running the uninstall.

You can alternatively also (probably without side effects) go to the directory third_party/usbdk inside the edgetpu Runtime folder, and right-click on UsbDk to uninstall it:

Again, during uninstallation the UsbDk installer should be seen and also the characteristic USB “unplug” sound which Windows makes should be heard!

The bad news: Segmentation fault

The error now changes to a Segmentation fault!

$ pyenv exec python examples/classify_image.py --model test_data/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite --labels test_data/inat_bird_labels.txt --input test_data/parrot.jpg
Segmentation fault

Note – I also hear a Windows USB unplug sound when this executes. This is to be expected – The Coral device is accessed in one mode first, as I understand to push inferencing information on it, and then it is supposed to be unplugged.

This segmentation fault is a step forward, even if it does not seem like that to you. Possibly some further debugging could solve this issue, or possibly the Google team can look into it.

I have added my insights to this GitHub thread, hopefully that might point Google developers into the right direction …

If you tried this and it works for you, please leave a comment below!

The better news: a working Coral Runtime version!

There is a version of the Coral Runtime which does not have this bug (UsbDk install bug as described above), and which also does not have the Segmentation fault.

The only downside is that this version only supports Version 13 of the runtime (so some features of version 14 will be missing).

https://coral.ai/software/#edgetpu-runtime

Use edgetpu_runtime_20210119 (Frogfish)

The installer will install UsbDk. Note, this is an older UsbDk release (version UsbDk_1.0.21_x64.msi) which is bundled with the 20210119 release, possibly this is part of the reasons why this works.

Using this you should be able to run the Coral USB parrot inferencing example on Windows 10:

$ pyenv exec python examples/classify_image.py --model test_data/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite --labels test_data/inat_bird_labels.txt --input test_data/parrot.jpg
C:\Business-2022\pi3g e.K\Marketing\2022 Präsentation für Ric\Coral on Windows\coral\pycoral\examples\classify_image.py:79: DeprecationWarning: ANTIALIAS is deprecated and will be removed in Pillow 10 (2023-07-01). Use 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.
12.5ms
2.8ms
2.8ms
2.7ms
2.7ms
-------RESULTS--------
Ara macao (Scarlet Macaw): 0.75781

I will probably add a writeup soon of how to install the Coral USB on Windows 10 step-by-step, or possibly create a video for our YouTube Channel.

Buying Coral USB accelerators

We are one of the Coral USB distributors. Please contact our sales team with volume inquiries of the Coral USB, or if you want to become a reseller.

If you want to purchase one for yourself, try one of our resellers, or you can buy a Coral USB accelerator from our own shop, buyzero.de

Coral USB Consulting

As you may have noticed in this blog post, we are able to support you with consulting for your Coral USB based project. If you would like to discuss the possibilities of Coral EdgeTPU acceleration for your platform, need someone to implement a solution for you, or need another form of consulting / commercial support, please reach out to our sales team.

Other errors

ImportError: DLL load failed while importing _pywrap_coral: The specified module could not be found.

This error tells you that the install.bat has not been run.

    raise ValueError('Failed to load delegate from {}\n{}'.format(
ValueError: Failed to load delegate from edgetpu.dll

After fixing the UsbDk problem, as described above, this error should mean that your Coral USB device is not plugged into your Windows 10 Computer.

Verify this using the Windows Device Manager. If it is plugged in, it should show up:

Also verify that the Coral USB accelerator shows up as working normally:

raise ValueError('Failed to load delegate from {}\n{}'.format(
ValueError: Failed to load delegate from edgetpu.dll

If you get this error AND the Coral USB Accelerator shows up as “Working properly” in device manager, then double-check whether the UsbDk software is installed, as I have described above. You should see an “UsbDk Runtime Libraries” entry in your Apps & features: