Giter Club home page Giter Club logo

tf-detection-example's Introduction

tf-detection-example

A simple example to how to use Tensorflow detection API on a custom dataset

Detector in action

Detector in action (from https://youtu.be/eYUohOTqn7g)

Dataset

Download and install labelImg tool

  • Put your images in dataset/train/images folder
  • Create a dataset/train/annotations/ folder
  • Open Dir in labelImg tool to dataset/train/images folder
  • Change Save Dir in labelImg tool to dataset/train/annotations/ folder
  • Start boring annotation task ๐Ÿคทโ€โ™€๏ธ

For the laziest, you can also use an existing dataset. Use the script convert_dataset_format.py to convert from a YOLO dataset to a PASCAL VOC style dataset.

Install Tensorflow Object Detection

Download and install the tensorflow object detection preferably in a conda env

conda create --name tf_detection python=3.7 -y
conda activate tf_detection

Do not forget to add it to the PYTHONPATH

Set the TF_MODELS_PATH env var to the Tensorflow detection folder. If you cloned in your home directory export TF_MODELS_PATH=~/models or cd into the directory and do export TF_MODELS_PATH=$(pwd)

Generate tfr

Split test train

python split_train_test.py

Create the TFRecords

python create_pascal_tf_record.py --output_path=./train.record --data_dir=dataset/train
python create_pascal_tf_record.py --output_path=./test.record --data_dir=dataset/test

Download a pre-trained model

The model used in this example is the ssdlite_mobilenet_v2_coco_2018_05_09, you can change it with whatever you like

python download_model.py

If you changed the model, download also the adequate pipeline config here and edit the file by replacing all the PATH_TO_BE_CONFIGURED.

Training

Run this command to begin the training

python ${TF_MODELS_PATH}/research/object_detection/model_main.py \
   --pipeline_config_path=ssdlite_mobilenet_v2_coco_modified.config \
   --model_dir=./finetuned_model \
   --alsologtostderr \
   --num_train_steps=30000 \
   --num_eval_steps=100

You can follow the training using Tensorboard

tensorboard --logdir=finetuned_model

Export graph

After the training completion, export the graph for inference

INPUT_TYPE=image_tensor
PIPELINE_CONFIG_PATH=ssdlite_mobilenet_v2_coco_modified.config
TRAINED_CKPT_PREFIX=finetuned_model/model.ckpt-30000
EXPORT_DIR=finetuned_model/export_frozen
python ${TF_MODELS_PATH}/research/object_detection/export_inference_graph.py \
    --input_type=${INPUT_TYPE} \
    --pipeline_config_path=${PIPELINE_CONFIG_PATH} \
    --trained_checkpoint_prefix=${TRAINED_CKPT_PREFIX} \
    --output_directory=${EXPORT_DIR}

Inference

To run a inference in a image

python inference.py

inference

tf-detection-example's People

Contributors

coac avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.