Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
graphs
models
BUILD
Dockerfile
README.md
WORKSPACE
demo_run_graph_main.cc
setup.sh
update_sources.sh

README.md

Coral Dev Board Setup (experimental)

Dislaimer: Running MediaPipe on Coral is experimental, and this process may not be exact and is subject to change. These instructions have only been tested on the coral dev board with OS version mendel day, and may vary for different devices and workstations.

This file describes how to prepare a Google Coral Dev Board and setup a linux Docker container for building MediaPipe applications that run on Edge TPU.

Before creating the Docker

  • (on host machine) run setup.sh from MediaPipe root directory

      sh mediapipe/examples/coral/setup.sh
    
  • Setup the coral device via here, and ensure the mdt command works

  • (on coral device) prepare MediaPipe

      cd ~
      sudo apt-get install git
      git clone https://github.com/google/mediapipe.git
      mkdir mediapipe/bazel-bin
    
  • (on coral device) install opencv 3.2

      sudo apt-get update && apt-get install -y libopencv-dev
    
  • (on coral device) find all opencv libs

      find /usr/lib/aarch64-linux-gnu/ -name 'libopencv*so'
    
  • (on host machine) copy core opencv libs from coral device to a local folder inside MediaPipe checkout:

      # in root level mediapipe folder #
      mdt pull /usr/lib/aarch64-linux-gnu/libopencv_core.so opencv32_arm64_libs
      mdt pull /usr/lib/aarch64-linux-gnu/libopencv_calib3d.so opencv32_arm64_libs
      mdt pull /usr/lib/aarch64-linux-gnu/libopencv_features2d.so opencv32_arm64_libs
      mdt pull /usr/lib/aarch64-linux-gnu/libopencv_highgui.so opencv32_arm64_libs
      mdt pull /usr/lib/aarch64-linux-gnu/libopencv_imgcodecs.so opencv32_arm64_libs
      mdt pull /usr/lib/aarch64-linux-gnu/libopencv_imgproc.so opencv32_arm64_libs
      mdt pull /usr/lib/aarch64-linux-gnu/libopencv_video.so opencv32_arm64_libs
      mdt pull /usr/lib/aarch64-linux-gnu/libopencv_videoio.so opencv32_arm64_libs
    
  • (on host machine) Create and start the docker environment

      # from mediapipe root level directory #
      docker build -t coral .
      docker run -it --name coral coral:latest
    

Inside the Docker environment

  • Update library paths in /mediapipe/third_party/opencv_linux.BUILD

    (replace 'x86_64-linux-gnu' with 'aarch64-linux-gnu')

      "lib/aarch64-linux-gnu/libopencv_core.so",
      "lib/aarch64-linux-gnu/libopencv_calib3d.so",
      "lib/aarch64-linux-gnu/libopencv_features2d.so",
      "lib/aarch64-linux-gnu/libopencv_highgui.so",
      "lib/aarch64-linux-gnu/libopencv_imgcodecs.so",
      "lib/aarch64-linux-gnu/libopencv_imgproc.so",
      "lib/aarch64-linux-gnu/libopencv_video.so",
      "lib/aarch64-linux-gnu/libopencv_videoio.so",
    
  • Attempt to build hello world (to download external deps)

      bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world:hello_world
    
  • Edit /mediapipe/bazel-mediapipe/external/com_github_glog_glog/src/signalhandler.cc

    on line 78, replace
    
      return (void*)context->PC_FROM_UCONTEXT;
    
    with
    
      return NULL;
    
  • Edit /edgetpu/libedgetpu/BUILD

    to add this build target
    
       cc_library(
         name = "lib",
         srcs = [
             "libedgetpu.so",
         ],
         visibility = ["//visibility:public"],
       )
    
  • Edit tflite_inference_calculator.cc BUILD rules:

      sed -i 's/\":tflite_inference_calculator_cc_proto\",/\":tflite_inference_calculator_cc_proto\",\n\t\"@edgetpu\/\/:header\",\n\t\"@libedgetpu\/\/:lib\",/g' mediapipe/calculators/tflite/BUILD
    
    The above command should add
    
      "@edgetpu//:header",
      "@libedgetpu//:lib",
    
    to the _deps_ of tflite_inference_calculator.cc
    

Now try cross-compiling for device

  • Object detection demo

      bazel build -c opt --crosstool_top=@crosstool//:toolchains --compiler=gcc --cpu=aarch64 --define MEDIAPIPE_DISABLE_GPU=1 --copt -DMEDIAPIPE_EDGE_TPU --copt=-flax-vector-conversions mediapipe/examples/coral:object_detection_cpu
    

Copy object_detection_cpu binary to the MediaPipe checkout on the coral device

    # outside docker env, open new terminal on host machine #
    docker ps
    docker cp <container-id>:/mediapipe/bazel-bin/mediapipe/examples/coral/object_detection_cpu /tmp/.
    mdt push /tmp/object_detection_cpu /home/mendel/mediapipe/bazel-bin/.
  • Face detection demo

      bazel build -c opt --crosstool_top=@crosstool//:toolchains --compiler=gcc --cpu=aarch64 --define MEDIAPIPE_DISABLE_GPU=1 --copt -DMEDIAPIPE_EDGE_TPU --copt=-flax-vector-conversions mediapipe/examples/coral:face_detection_cpu
    

Copy face_detection_cpu binary to the MediaPipe checkout on the coral device

    # outside docker env, open new terminal on host machine #
    docker ps
    docker cp <container-id>:/mediapipe/bazel-bin/mediapipe/examples/coral/face_detection_cpu /tmp/.
    mdt push /tmp/face_detection_cpu /home/mendel/mediapipe/bazel-bin/.

On the coral device (with display)

 # Object detection
 cd ~/mediapipe
 chmod +x bazel-bin/object_detection_cpu
 export GLOG_logtostderr=1
 bazel-bin/object_detection_cpu --calculator_graph_config_file=mediapipe/examples/coral/graphs/object_detection_desktop_live.pbtxt

 # Face detection
 cd ~/mediapipe
 chmod +x bazel-bin/face_detection_cpu
 export GLOG_logtostderr=1
 bazel-bin/face_detection_cpu --calculator_graph_config_file=mediapipe/examples/coral/graphs/face_detection_desktop_live.pbtxt
You can’t perform that action at this time.