• Stars
    star
    275
  • Rank 149,796 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

BodyPix model demo application for Google Coral

Coral BodyPix

BodyPix is an open-source machine learning model which allows for person and body-part segmentation. This has previously been released as a Tensorflow.Js project.

This repo contains a set of pre-trained BodyPix Models (with both MobileNet v1 and ResNet50 backbones) that are quantized and optimized for the Coral Edge TPU. Example code is provided to enable inferencing on generic platforms as well as an optimized version for the Coral Dev Board.

Body-Part Segmentation Anonymous Population Flow

The above images show two possible applications of BodyPix. The left shows body-part segmentation (on an example video) with bounding boxes and PoseNet-style skeletons. The right shows anonymous population flow. Both are running on the Coral Dev Board; see below for information on enabling these modes on the Dev Board or on a generic platform.

What is Person/Body-Part Segmentation?

Image segmentation refers to grouping pixels of an image into semantic areas, typically to locate objects and boundaries. For example, the Coral DeepLab model (available on the Coral Models Page) segments based on 20 objects. In this example, as with all segmentation examples, pixels are classified as one of those objects or background.

BodyPix extends this concept and segments for people as well as twenty-four body parts (such as "right hand" or "torso front"). More information can be found on the Tensorflow.Js page. This model and post-processing (contained as a custom OP in the Edge TPU TFLite Interpreter) has been optimized for the Edge TPU.

Examples in this repo

NOTE: BodyPix relies on the latest version of the Coral API and for the Dev Board the latest Mendel system image.

To install all the requirements, simply run

sh install_requirements.sh

bodypix.py

A generic BodyPix example intended to be run on multiple platforms, which has not been optimized. Note that this is not recommended for the Coral Dev Board, where the performance is poor compared to the bodypix_gl_imx example. This example allows segmentation of a person, segmentation of body parts, as well as an anonymizer option which lets you remove the person from the camera image.

Run the base demo (using the MobileNet v1 backbone with 640x480 input) like this:

python3 bodypix.py

To segment body parts (grouped as regions as opposed to displaying all 24) instead of the entire person, pass the --bodyparts flag:

python3 bodypix.py --bodyparts

In this repo we have included 11 BodyPix model files using different backbone networks and supporting different input resolutions. There are significant trade-offs in these versions, MobileNet will be faster than ResNet but less accurate; larger resolutions are slower but allow a wider field of view (allowing further-away people to be processed correctly).

This can be changed with the --model flag. Both EdgeTPU and CPU models can be found in the models folder.

You can change the camera resolution by using the --width and --height parameter. Note that in general the camera resolution should equal or exceed the input resolution of the network to get the full advantage of the higher resolution inference:

python3 bodypix.py --width 480 --height 360  # fast but low res
python3 bodypix.py --width 640 --height 480  # default
python3 bodypix.py --width 1280 --height 720 # slower but high res

If the camera and monitor are both facing you, consider adding the --mirror flag:

python3 bodypix.py --mirror

If your input camera supports encoded frames (h264 or JPEG) you can provide the corresponding flags to increase performance. Note these modes are mutually exclusive:

python3 bodypix.py --h264
python3 bodypix.py --jpeg

You can enable Anonymizer mode (which anonymizes the person, similar to in the Coral PoseNet Project. As opposed to the PoseNet example, instead of indicating the pose skeleton the entire outline of the person is indicated.

python3 bodypix.py --anonymize

bodypix_gl_imx.py

This example is optimized specifically for the iMX8MQ GPU and VPU found on the Coral Dev Board. It is intended to allow real time processing and rendering on the platform (able to achieve 30 FPS even at 1280x720 resolution). The flags for input (models, camera configuration) are the same but we enable toggling between display modes with key presses instead of a flag:

python3 bodypix_gl_imx.py

The following key presses can be used to toggle various modes:

Toggle PoseNet-style Skeletons: 's'
Toggle Bounding Boxes: 'b'
Toggle Anonymizer: 'a'
Toggle Aggregated Heatmap Generation: 'h'
Toggle Body Part Segmentation: 'p'
Reset: 'r'

More Repositories

1

project-posenet

Human Pose Detection on EdgeTPU
Python
550
star
2

edgetpu

Coral issue tracker (and legacy Edge TPU API source)
C++
422
star
3

examples-camera

Small code snippets that show how to stream camera images to a Coral device.
Python
360
star
4

pycoral

Python API for ML inferencing and transfer-learning on Coral devices
Python
355
star
5

libedgetpu

Source code for the userspace level runtime driver for Coral.ai devices.
C++
183
star
6

tflite

Examples using TensorFlow Lite API to run inference on Coral devices
Python
182
star
7

tutorials

Colab/Jupyter tutorials about training TensorFlow models for Edge TPU, and other tutorials
Jupyter Notebook
179
star
8

project-keyword-spotter

Audio Keyphrase Detector
Python
139
star
9

example-object-tracker

Python
110
star
10

coralmicro

Source code for Coral Dev Board Micro
C++
105
star
11

edgetpu-platforms

EdgeTPU support for other platforms, specifically Raspberry Pi Zero
Shell
79
star
12

libcoral

C++ API for ML inferencing and transfer-learning on Coral devices
C++
78
star
13

project-teachable-sorter

Python
51
star
14

test_data

Trained and compiled TF Lite models, and other testing data for Coral devices
Starlark
47
star
15

project-birdfeeder

Python
41
star
16

webcoral

JavaScript
34
star
17

project-banana-robo

Python
30
star
18

electricals

Electrical designs for coral.ai projects
HTML
27
star
19

project-teachable

Example Project: Teachable Machine
Python
26
star
20

crosstool

Starlark
19
star
21

project-cloud-monitor

Python
15
star
22

example-multiple-edgetpus

C++
14
star
23

demo-manufacturing

C++
13
star
24

aiy-maker-kit

Simple Python API for ML inferencing with TF Lite and Coral Edge TPU
Python
10
star
25

imprinting-training

Imprinting training scripts of tensorflow.
Python
9
star
26

aiy-maker-kit-tools

Build scripts to create RPI OS system image for AIY Maker Kit
Python
7
star
27

py-repo

Python
5
star
28

mechanicals

Reference mechanical designs for coral.ai projects
5
star
29

demo-multi-video-stream

Demo showcasing processing multiple videostreams in parallel on system with 8 EdgeTPUs
C++
4
star
30

coralmicro-out-of-tree-sample

C++
3
star
31

coralmicro-rt1176-sdk

C
2
star
32

coralmicro-littlefs-fuse

C
1
star