Skip to content

Instantly share code, notes, and snippets.

@biranchi2018
Created December 2, 2018 12:30
Show Gist options
  • Save biranchi2018/9e92a576b77156dc44d08b63f67d3365 to your computer and use it in GitHub Desktop.
Save biranchi2018/9e92a576b77156dc44d08b63f67d3365 to your computer and use it in GitHub Desktop.
Tensorflow Object Detection API :
==================================
https://www.youtube.com/watch?v=COlbP62-B-U&index=1&list=PLQVvvaa0QuDcNK5GeCQnxYnSSaar2tpku
https://github.com/tensorflow/models/tree/master/research/object_detection
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md
Models:
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md
Configs:
https://github.com/tensorflow/models/tree/master/research/object_detection/samples/configs
pip install tensorflow
pip install protobuf
pip install pillow
pip install lxml
pip install jupyter
pip install matplotlib
Step 1:
========
Download tensorflow models and protobuf
https://github.com/tensorflow/models/tree/master/research/object_detection
https://github.com/tensorflow/models
https://github.com/protocolbuffers/protobuf/releases
https://github.com/tzutalin/labelImg
https://github.com/datitran/raccoon_dataset
Step 2:
========
brew install protobuf
# From tensorflow/models/research/
protoc/bin/protoc object_detection/protos/*.proto --python_out=.
Step 3:
========
Add PYTHONPATH in ~/.bash_profile
export PYTHONPATH=/usr/local/bin/python
Step 4:
========
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
Step 5:
========
cd object_detection
Step 6:
========
jupyter notebook
Step 7:
========
# From tensorflow/models/research/
sudo python setup.py install
Step 8 (generate_tfrecord.py) :
===============================
Edit generate_tfrecord.py file to add image paths:
python generate_tfrecord.py --csv_input=data/train_labels.csv --output_path=data/train.record --images_folder_name=train
python generate_tfrecord.py --csv_input=data/test_labels.csv --output_path=data/test.record --images_folder_name=test
flags.DEFINE_string('images_folder_name', '', 'Images folder name') #test or train
path = os.path.join(os.getcwd(), 'images', FLAGS.images_folder_name)
print("path name : ", path)
Step 9 (ssd_mobilenet_v1_pets.config):
=======================================
Configuration for the ssd_mobilenet_v1_pets.config:
num_classes: 1
fine_tune_checkpoint: "../ssd_mobilenet_v1_coco_2018_01_28/model.ckpt"
train_input_reader: {
tf_record_input_reader {
input_path: "../data/train.record"
}
label_map_path: "../data/object-detection.pbtxt"
}
eval_input_reader: {
tf_record_input_reader {
input_path: "../data/test.record"
}
label_map_path: "../data/object-detection.pbtxt"
shuffle: false
num_readers: 1
}
Step 10:
=========
a) Run xml_to_csv.py to generate csv records
b) Run generate_tfrecord.py (Add class label to int)
c) Configure the ssd_mobilenet_v1_pets.config file (Add num_classes)
d) Create object-detection.pbtxt (Containing the labels and serial numbers)
e) Move the object-detection.pbtxt into data folder
f) Move the ssd_mobilenet_v1_pets.config file into training folder
g) Copy our custom data, images, ssd_model and training folders into object_detection folder
Step 11:
========
# From tensorflow/models/research/object_detection/legacy/
python train.py --logtostderr --train_dir=../training/ --pipeline_config_path=../training/ssd_mobilenet_v1_pets.config
Step 12:
========
# From tensorflow/models/research/object_detection/
tensorboard --logdir=training/
Step 13:
========
# From tensorflow/models/research/object_detection/
python export_inference_graph.py \
--input_type image_tensor \
--pipeline_config_path training/ssd_mobilenet_v1_pets.config \
--trained_checkpoint_prefix training/model.ckpt-6875 \
--output_directory mac_n_cheese_graph
Step 14:
========
jupyter notebook
MODEL_NAME = ‘mac_n_cheese_graph’
# MODEL_FILE = MODEL_NAME + ‘.tar.gz’
# DOWNLOAD_BASE = ‘http://download.tensorflow.org/models/object_detection’
PATH_TO_LABELS = os.path.join(‘data’ , ‘object-detection.pbtxt’)
NUM_CLASSES = 1
Download Model
# Comment out all the code….
# Add few test images to the “test_images” folder
TEST_IMAGE_PATHS = [ os.path.join(PATH_TO_TEST_IMAGES_DIR, i) for i in os.listdir(PATH_TO_TEST_IMAGES_DIR)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment