google-coral / edgetpu

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

Run inference on Vagrant VM #487

Closed IArchi closed 3 years ago

IArchi commented 3 years ago

I'm trying to run the image classifier as explained in the Get started documentation.

I've set up a Virtualbox VM using Vagrant:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

    # RAM, CPU and USB configuration
    config.vm.provider "virtualbox" do |v|
        v.memory = 4096
        v.cpus = 2
        v.customize ["modifyvm", :id, "--usb", "on"] # Enable USB
        v.customize ["modifyvm", :id, "--usbehci", "on"] # Enable USB 2.0
        v.customize ["modifyvm", :id, "--usbxhci", "on"] # Enable USB 3.0
        v.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'Coral USB Accelerator', '--vendorid', '0x1a6e', '--productid', '0x089a']
        v.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'Google Inc. Coral USB Accelerator', '--vendorid', '0x18d1', '--productid', '0x9302' ]
    end

    # Worker node config
    config.vm.define "worker-coral" do |worker|
        worker.vm.box = "hashicorp/bionic64"
        worker.vm.network "private_network", ip: "192.168.50.10"

        # Share USB devices with host
        worker.vm.synced_folder "/dev/bus/usb", "/dev/bus/usb", SharedFoldersEnableSymlinksCreate: true
    end
end

Then, I've followed every single line to install the library and run the example:

    echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
    sudo apt-get update
    sudo apt-get install libedgetpu1-std -y
    sudo apt-get install python3-pycoral -y
    mkdir coral && cd coral
    git clone https://github.com/google-coral/pycoral.git
    cd pycoral
    bash examples/install_requirements.sh classify_image.py
    python3 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

This produces the following error:

$ python3 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 "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 160, in load_delegate
    delegate = Delegate(library, options)
  File "/usr/lib/python3/dist-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 "examples/classify_image.py", line 121, in <module>
    main()
  File "examples/classify_image.py", line 71, in main
    interpreter = make_interpreter(*args.model.split('@'))
  File "/usr/lib/python3/dist-packages/pycoral/utils/edgetpu.py", line 87, in make_interpreter
    delegates = [load_edgetpu_delegate({'device': device} if device else {})]
  File "/usr/lib/python3/dist-packages/pycoral/utils/edgetpu.py", line 52, in load_edgetpu_delegate
    return tflite.load_delegate(_EDGETPU_SHARED_LIB, options or {})
  File "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 163, in load_delegate
    library, str(e)))
ValueError: Failed to load delegate from libedgetpu.so.1

Apparently, the Coral Edge TPU USB dongle is not correctly detected but is visible in lsusb:

$ lsusb
Bus 004 Device 003: ID 18d1:9302 Google Inc.
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Is there something to do to make it works with Vagrant ?

IArchi commented 3 years ago

Solution was to remove this useless line !

worker.vm.synced_folder "/dev/bus/usb", "/dev/bus/usb", SharedFoldersEnableSymlinksCreate: true

google-coral-bot[bot] commented 3 years ago

Are you satisfied with the resolution of your issue? Yes No