Skip to content

xadrianzetx/coral-deeplab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

coral-deeplab

Coral Edge TPU compilable version of DeepLab v3 and DeepLab v3 Plus implemented in tf.keras with Edge TPU pre-compiled models included.

Implementation follows original paper as close as possible, while still being compatible with Edge TPU. The only difference is that last upsampling layer has been removed from decoder due to performance reasons. Thanks to multi subgraph support in edgetpu_compiler, model runs almost all operations on TPU, where original model delegates entirety of decoder to run on CPU.

Instalation

pip install git+https://github.com/xadrianzetx/coral-deeplab.git

Usage

You can train from scratch...

import tensorflow as tf
import coral_deeplab as cdl

model = cdl.applications.CoralDeepLabV3()
isinstance(model, tf.keras.Model)
# True

...or just pull pre-compiled Edge TPU models straight to interpreter (can use --no-deps for lightweight install).

import coral_deeplab as cdl
import tflite_runtime.interpreter as tflite

interpreter = tflite.Interpreter(
    cdl.from_precompiled(cdl.pretrained.EdgeTPUModel.DEEPLAB_V3_DM1),
    experimental_delegates=[tflite.load_delegate("libedgetpu.so.1")]
)

Compiler

Use edgetpu_compiler version 14.1 or 15.0 to compile finetuned or trained from scratch models. Correct version can be obtained by running ./compiler/compiler.sh or here.

Latency

All models have been tested with 513x513 input on fresh install of Raspbian GNU/Linux 10 (buster).

Model Backbone Depth mul. ARM Cortex-A53 (RPi3B+) ARM Cortex-A72 (RPi4)
DeepLab v3 (google) MobileNet v2 1.0 ~368.6 ms/iter (~2.7 FPS) ~147.5 ms/iter (~6.8 FPS)
DeepLab v3 (this) MobileNet v2 1.0 ~143.0 ms/iter (~7.0 FPS) ~43.7 ms/iter (~22.9 FPS)
DeepLab v3 (this) MobileNet v2 0.5 ~129.4 ms/iter (~7.8 FPS) ~32.6 ms/iter (~30.6 FPS)

Results

From left: original image, DeepLab v3 (google), DeepLab v3 (this). All segmentation masks were produced with Edge TPU.

References