Skip to content

Quickly and easily deploy TF2 Image Object Detection models from TensorFlow Hub trained on COCO 2017 dataset.

Notifications You must be signed in to change notification settings

thomasmatt88/tfhub-od-easy

Repository files navigation

tfhub-od-easy

license Python 3.6

TensorFlow Hub lets you search and discover hundreds of trained, ready-to-deploy machine learning models in one place. This repo offers a minimal codebase to deploy TF2 Image Object Detection models from TensorFlow Hub for image object detection, video object detection, webcam object detection, and evaluation on the MS COCO 2017 validation dataset (5000 images). Simply replace the --url argument in any of the demos below with the url of the model of interest from https://tfhub.dev/s?module-type=image-object-detection&tf-version=tf2.

Example urls:

Demos

Before attempting the commands below make sure that your system meets the requirements listed in https://www.tensorflow.org/install. Namely that Python version is between 3.5 - 3.8.

pip install --upgrade pip
pip install -r requirements.txt

Detect Image

# detect image with SSD Mobilenet v2 
python detect_image.py --url https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2 --image_input ./data/kite.jpg

# detect image with EfficientDet-d7
python detect_image.py --url https://tfhub.dev/tensorflow/efficientdet/d7/1 --image_input ./data/kite.jpg

Output

SSD Mobilenet v2

Detect Video

# detect video with SSD Mobilenet v2 
python detect_video.py --url https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2 --video ./data/video.mp4 --output ./detect-test.mp4

Detect Webcam

# detect webcam with SSD Mobilenet v2 
python detect_video.py --url https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2 --video 0

Evaluate on MS COCO 2017 Validation Dataset

./scripts/get_coco_dataset_2017.sh
python evaluate.py --url https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2
cd mAP/extra
python remove_space.py # enter 'y' for everything
cd ..
python main.py # expect mAP of 29.70% for https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2

Save Model

# save SSD Mobilenet v2 to saved_models
python save_model.py --url https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2

Note:

Detect Image From Saved Model

python detect_image.py --url ./saved_models/ssd_mobilenet_v2_2

TODO

  • TensorFlow Lite Support
  • Training/Fine-tuning support

Acknowledgements

This project was inspired by

About

Quickly and easily deploy TF2 Image Object Detection models from TensorFlow Hub trained on COCO 2017 dataset.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages