Skip to content
Branch: master
Find file History
pengchongjin and allenwang28 \nInternal refactor
PiperOrigin-RevId: 263877713
Latest commit f59154b Aug 16, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
README.md Add EfficientNet-EdgeTPU blog post link. Aug 6, 2019
__init__.py Add eval_ckpt tool for MixNet. Jul 23, 2019
efficientnet_edgetpu_builder.py \nInternal refactor Aug 19, 2019

README.md

EfficientNet-EdgeTPU

Blog post: https://ai.googleblog.com/2019/08/efficientnet-edgetpu-creating.html

EfficientNet-EdgeTPU are a family of image classification neural network models customized for deployment on Google Edge TPU. These networks are closely related to [EfficientNets] (https://arxiv.org/abs/1905.11946).

EfficientNet-EdgeTPU were developed using the AutoML MNAS framework by augmenting the neural network search space with building blocks tuned to execute efficiently on the EdgeTPU neural network accelerator architecture. The neural architecture search was incentivized to discover models that achieve low parameter footprint and low latency on EdgeTpu, while simultaneously achieving high classification accuracy. This neural architecture search produced a baseline model: edgetpunet-S, which is subsequently scaled up using EfficientNet's compound scaling method to produce the M and L models.

Using Pretrained EfficientNet-EdgeTPU Checkpoints

We have provided pretrained checkpoints and float/quantized TFLite models:

A quick way to use these checkpoints is to run:

$ export MODEL=efficientnet-edgetpu-S
$ wget https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/${MODEL}.tar.gz
$ tar zxf ${MODEL}.tar.gz
$ wget https://upload.wikimedia.org/wikipedia/commons/f/fe/Giant_Panda_in_Beijing_Zoo_1.JPG -O panda.jpg
$ wget https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/eval_data/labels_map.txt
$ python eval_ckpt_main.py --model_name=$MODEL --ckpt_dir=$MODEL --example_img=panda.jpg --labels_map_file=labels_map.txt --include_background_label

Note that these models were trained with label#0 marked as the background label for easier deployment. TFLite models can be evaluated using this tool.

Training EfficientNet-EdgeTPU on Cloud TPUs

Please refer to our tutorial: https://cloud.google.com/tpu/docs/tutorials/efficientnet

Post-training quantization

EdgeTPUs support inference using integer quantized models only. We found that using the Tensorflow Lite's post-training quantization tool works remarkably well for producing a EdgeTPU-compatible quantized model from a floating-point training checkpoint. For full integer quantization, the post-training quantization tool requires a representative dataset for calibrating the dynamic ranges of the activations.

We provide a tool that invokes the post-training quantization tool to produce quantized tensorflow-lite model:

$ export MODEL=efficientnet-edgetpu-S
$ wget https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/${MODEL}.tar.gz
$ tar zxf ${MODEL}.tar.gz
$ python export_model.py --model_name=$MODEL --ckpt_dir=$MODEL --data_dir=/path/to/representative_dataset/ --output_tflite=${MODEL}_quant.tflite

To produce a float model that bypasses the post-training quantization:

$ python export_model.py --model_name=$MODEL --ckpt_dir=$MODEL --output_tflite=${MODEL}_float.tflite --quantize=False

The table below compared the accuracy of float models (on CPU) and the quantized models on EdgeTPU:

Model Imagenet top-1 accuracy (float) Imagenet top-1 accuracy (quantized)
efficientnet-edgetpu-S 77.23% 77.0 %
efficientnet-edgetpu-M 78.69 78.6 %
efficientnet-edgetpu-L 80.62 80.2%

The export_model.py script can also be used to export a tensorflow saved_model from a training checkpoint:

$ python export_model.py --model_name=$MODEL --ckpt_dir=/path/to/model-ckpt/ --output_saved_model_dir=/path/to/output_saved_model/ --output_tflite=${MODEL}_float.tflite --quantize=False
You can’t perform that action at this time.