This repository is an end-to-end example for training a binarized object detector on the PASCAL VOC dataset, exporting it for inference, and using the exported model in a demo application.
It is forked from https://github.com/pythonlessons/TensorFlow-2.x-YOLOv3, which had the most comprehensive training pipeline based on TensorFlow 2 that I can find for training a YOLO detector.
Libraries used:
- Larq 0.11.2
- TensorFlow 2.3.2 (Unexpected behaviour may show up if using TensorFlow 2.4, see this issue)
- OpenCV 4
Platform tested on:
- NVIDIA Jetson Nano 2GB
The example model is based off YOLOv2, with QuickNet as the backbone, and a head that is based off the transition blocks in QuickNet. Here are the statistics for this model:
- mAP@0.5 for VOC2007 Test Set: 0.37
- Average Inference Time (Tested using the LCE benchmarking tool on a Jetson Nano): 26.5 ms
cd demo_applicationpython demo_lce.py
For a quick demo, just skip to the deployment step with the provided
model.tflite and labelmap.tflite in demo_application/
- Run
dataset_preparation/dataset_preparation.sh/dataset_preparation/dataset_preparation_no_download.shif already downloaded dataset - Run
python dataset_preparation/migrate_data.py - Run
python dataset_preparation/flatten_voc.py - Run
mkdir voc_data - Run
mv VOCdevkit/train voc_data && mv VOCdevkit/test voc_data - Run
python dataset_preparation/remove_train_test_duplicates.py - (Optional) If you want to make sure the datset prepared is valid, run
python dataset_preparation/check_voc_dataset_sanity.py - Run
python tools/XML_to_YOLOv3.py
(Cleanup in case of messups)
- Run
rm -rf VOCdevkit/ && rm -rf VOC2007Trainval/ && rm -rf voc_data - Repeat the process with
dataset_preparation_no_download.shin step 1 instead.
- Run
python train.py
- Change
YOLO_CUSTOM_WEIGHTSinconfigs.pyto the checkpoint for the trained model, e.g.checkpoints/quickyolov2_custom - Run
python evaluate_mAP.py
- If haven't, change
YOLO_CUSTOM_WEIGHTSinconfigs.pyto the checkpoint for the trained model, e.g.checkpoints/quickyolov2_custom - Run
python export_larq_model.py
- Install OpenCV4 (run
demo_application/install_lce.shfrom current directory) - Install Larq Compute Engine (run
install_lce.shfrom current directory) - Move
demo_application/detection.ccto${larq-compute-engine}/examples - Move
demo_application/Makefileto${larq-compute-engine}/larq_compute_engine/tflite/build_make/Makefile - Build using
larq_compute_engine/tflite/build_make/build_lce.sh --native - Move the exported model, and
voc_names.txttogen/linux_aarch64, renaming them tomodel.tfliteandlabelmap.txtrespectively.
- A lot of the training code was forked from
https://github.com/pythonlessons/TensorFlow-2.x-YOLOv3 - Demo application took reference from
https://github.com/finnickniu/tensorflow_object_detection_tflite/blob/master/demo.cpp
- Clean up the code base in this repo
- Incorporate spatial pyramids
- Make example application buildable using Bazel
- Add multiprocessing for camera I/O in demo application
MIT
