treehouses / builder

Treehouses Awesome 👓 Raspberry Pi Image Builder 🏗
http://download.treehouses.io
GNU Affero General Public License v3.0
47 stars 22 forks source link

Installation of Coral USB TPU in Raspian Buster - RPi4 #470

Open vers4ce opened 5 years ago

vers4ce commented 5 years ago
    4  cd ~/
    5  wget https://dl.google.com/coral/edgetpu_api/edgetpu_api_latest.tar.gz -O edgetpu_api.tar.gz --trust-server-names
    6  tar xzf edgetpu_api.tar.gz
    7  cd edgetpu_api
    8  sudo bash ./install.sh
    9  sudo nano ./install.sh
   10  cat /proc/device-tree/model
   11  sudo nano ./install.sh
   12  sudo bash ./install.sh
   13  cd /usr/local/lib/python3.5/dist-packages/edgetpu
   14  cd /usr/local/lib/python3.7/dist-packages/edgetpu
   15  ls ltr
   16  ls -ltr
   17  cd ./swig
   18  ls -ltr
   19  cd ~/Downloads/
   20  mkdir ~/Downloads
   21  cd ~/Downloads
   22  wget https://dl.google.com/coral/canned_models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite https://dl.google.com/coral/canned_models/inat_bird_labels.txt https://coral.withgoogle.com/static/docs/images/parrot.jpg
   23  cd /usr/local/lib/python3.5/dist-packages/edgetpu/demo
   24  cd /usr/local/lib/python3.7/dist-packages/edgetpu/demo
   25  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
   26  cd /usr/local/lib/python3.7/dist-packages/edgetpu
   27  ls -ltr
   28  cd ./swig
   29  ls -ltr
   30  sudo ln -s edgetpu_cpp_wrapper.cpython-3{5,7}m-arm-linux-gnueabihf.so
   31  ls -ltr
   32  cd /usr/local/lib/python3.7/dist-packages/edgetpu
   33  ls -ltr
   34  cd ./demo
   35  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
   36  cd /usr/local/lib/python3.7/dist-packages/edgetpu
   37  cd ./swig
   38  ls -ltr
   39  sudo ln -s _edgetpu_cpp_wrapper.cpython-3{5,7}m-arm-linux-gnueabihf.so
   40  ls -ltr
   41  sudo rm edgetpu_cpp_wrapper.cpython-37m-arm-linux-gnueabihf.so 
   42  ls -ltr
   43  cd /usr/local/lib/python3.7/dist-packages/edgetpu
   44  cd ./demo
   45  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
   46  history
vers4ce commented 5 years ago

the install script for raspberry pi 4:

#!/bin/bash
#
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
CLEAR="\033[0m"

CPU_ARCH=$(uname -m)
OS_VERSION=$(uname -v)

function info {
  echo -e "${GREEN}${1}${CLEAR}"
}

function warn {
  echo -e "${YELLOW}${1}${CLEAR}"
}

function error {
  echo -e "${RED}${1}${CLEAR}"
}

if [[ -f /etc/mendel_version ]]; then
  warn "Looks like you're using a Coral Dev Board. You should instead use Debian packages to manage Edge TPU software."
  exit 0
fi

if [[ "${CPU_ARCH}" == "x86_64" ]] && [[ "${OS_VERSION}" == *"Debian"* || "${OS_VERSION}" == *"Ubuntu"* ]]; then
  info "Recognized as Linux on x86_64."
  LIBEDGETPU_SUFFIX=x86_64
  HOST_GNU_TYPE=x86_64-linux-gnu
elif [[ "${CPU_ARCH}" == "armv7l" ]]; then
  MODEL=$(cat /proc/device-tree/model)
  if [[ "${MODEL}" == "Raspberry Pi 3 Model B Rev"* ]]; then
    info "Recognized as Raspberry Pi 3 B."
    LIBEDGETPU_SUFFIX=arm32
    HOST_GNU_TYPE=arm-linux-gnueabihf
  elif [[ "${MODEL}" == "Raspberry Pi 3 Model B Plus Rev"* ]]; then
    info "Recognized as Raspberry Pi 3 B+."
    LIBEDGETPU_SUFFIX=arm32
    HOST_GNU_TYPE=arm-linux-gnueabihf
  elif [[ "${MODEL}" == "Raspberry Pi 4 Model B Rev"* ]]; then
    info "Raspberry Pi 4 Model B."
    LIBEDGETPU_SUFFIX=arm32
    HOST_GNU_TYPE=arm-linux-gnueabihf
 fi
elif [[ "${CPU_ARCH}" == "aarch64" ]]; then
  info "Recognized as generic ARM64 platform."
  LIBEDGETPU_SUFFIX=arm64
  HOST_GNU_TYPE=aarch64-linux-gnu
fi

if [[ -z "${HOST_GNU_TYPE}" ]]; then
  error "Your platform is not supported."
  exit 1
fi

cat << EOM
Warning: During normal operation, the Edge TPU Accelerator may heat up, depending
on the computation workloads and operating frequency. Touching the metal part of the
device after it has been operating for an extended period of time may lead to discomfort
and/or skin burns. As such, when running at the default operating frequency, the device is
intended to safely operate at an ambient temperature of 35C or less. Or when running at
the maximum operating frequency, it should be operated at an ambient temperature of
25C or less.

Google does not accept any responsibility for any loss or damage if the device is operated
outside of the recommended ambient temperature range.
.............................................................
Would you like to enable the maximum operating frequency? Y/N
EOM

read USE_MAX_FREQ
case "${USE_MAX_FREQ}" in
  [yY])
    info "Using maximum operating frequency."
    LIBEDGETPU_SRC="${SCRIPT_DIR}/libedgetpu/libedgetpu_${LIBEDGETPU_SUFFIX}.so"
    ;;
  *)
    info "Using default operating frequency."
    LIBEDGETPU_SRC="${SCRIPT_DIR}/libedgetpu/libedgetpu_${LIBEDGETPU_SUFFIX}_throttled.so"
    ;;
esac

LIBEDGETPU_DST="/usr/lib/${HOST_GNU_TYPE}/libedgetpu.so.1.0"

# Install dependent libraries.
info "Installing library dependencies..."
sudo apt-get install -y \
  libusb-1.0-0 \
  python3-pip \
  python3-pil \
  python3-numpy \
  libc++1 \
  libc++abi1 \
  libunwind8 \
  libgcc1
info "Done."

# Device rule file.
UDEV_RULE_PATH="/etc/udev/rules.d/99-edgetpu-accelerator.rules"
info "Installing device rule file [${UDEV_RULE_PATH}]..."

if [[ -f "${UDEV_RULE_PATH}" ]]; then
  warn "File already exists. Replacing it..."
  sudo rm -f "${UDEV_RULE_PATH}"
fi

sudo cp -p "${SCRIPT_DIR}/99-edgetpu-accelerator.rules" "${UDEV_RULE_PATH}"
sudo udevadm control --reload-rules && udevadm trigger
info "Done."

# Runtime library.
info "Installing Edge TPU runtime library [${LIBEDGETPU_DST}]..."
if [[ -f "${LIBEDGETPU_DST}" ]]; then
  warn "File already exists. Replacing it..."
  sudo rm -f "${LIBEDGETPU_DST}"
fi

sudo cp -p "${LIBEDGETPU_SRC}" "${LIBEDGETPU_DST}"
sudo ldconfig
info "Done."

# Python API.
WHEEL=$(ls ${SCRIPT_DIR}/edgetpu-*-py3-none-any.whl 2>/dev/null)
if [[ $? == 0 ]]; then
  info "Installing Edge TPU Python API..."
  sudo python3 -m pip install --no-deps "${WHEEL}"
  info "Done."
fi