Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Training Oxford-IIIT Pets Dataset with tensorflow/models #253

Open
1 of 15 tasks
junxnone opened this issue Dec 24, 2018 · 1 comment
Open
1 of 15 tasks

Training Oxford-IIIT Pets Dataset with tensorflow/models #253

junxnone opened this issue Dec 24, 2018 · 1 comment
Labels

Comments

@junxnone
Copy link
Owner

junxnone commented Dec 24, 2018

Reference

Models

Set the fine_tune_checkpoint in config files.

fine_tune_checkpoint: "/path/to/your/models/model.ckpt"
  • faster_rcnn_inception_resnet_v2_atrous_pets.config
  • faster_rcnn_inception_v2_pets.config
  • faster_rcnn_resnet101_pets.config
  • faster_rcnn_resnet152_pets.config
  • faster_rcnn_resnet50_pets.config
  • mask_rcnn_resnet101_pets.config
  • rfcn_resnet101_pets.config
  • ssd_inception_v2_pets.config - ssd_inception_v2_coco_2018_01_28.tar.gz
  • ssd_inception_v3_pets.config
  • ssd_mobilenet_v1_0.75_depth_quantized_300x300_pets_sync.config
  • ssd_mobilenet_v1_focal_loss_pets.config
  • ssd_mobilenet_v1_pets.config - ssd_mobilenet_v1_coco_2018_01_28.tar.gz

Download

wget http://www.robots.ox.ac.uk/~vgg/data/pets/data/images.tar.gz
wget http://www.robots.ox.ac.uk/~vgg/data/pets/data/annotations.tar.gz
tar -xvf annotations.tar.gz
tar -xvf images.tar.gz

Convert the Pets dataset to tfrecord format

python object_detection/dataset_tools/create_pet_tf_record.py \
    --label_map_path=object_detection/data/pet_label_map.pbtxt \
    --data_dir=`pwd` \
    --output_dir=`pwd`
cp pet_faces_train.record-* object_detection/data/
cp pet_faces_val.record-* object_detection/data/
sed -i "s|PATH_TO_BE_CONFIGURED|"YOUR_OBJECT_DETECTION_PATH"/data|g" \
    object_detection/samples/configs/faster_rcnn_resnet101_pets.config

YOUR_OBJECT_DETECTION_PATH is the models/research/object_detection

Training

cd models/research
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
PIPELINE_CONFIG_PATH=/work/tf/models/research/object_detection/samples/configs/ssd_mobilenet_v1_pets.config
MODEL_DIR=./modeldir
NUM_TRAIN_STEPS=50000
SAMPLE_1_OF_N_EVAL_EXAMPLES=1
python object_detection/model_main.py \
    --pipeline_config_path=${PIPELINE_CONFIG_PATH} \
    --model_dir=${MODEL_DIR} \
    --num_train_steps=${NUM_TRAIN_STEPS} \
    --sample_1_of_n_eval_examples=$SAMPLE_1_OF_N_EVAL_EXAMPLES \
    --alsologtostderr

The trainig model will save in the modeldir ($MODEL_DIR) folder
The checkpoint will typically consist of three files:

  • model.ckpt-${CHECKPOINT_NUMBER}.data-00000-of-00001
  • model.ckpt-${CHECKPOINT_NUMBER}.index
  • model.ckpt-${CHECKPOINT_NUMBER}.meta

Export the Model

python object_detection/export_inference_graph.py \
        --input_type image_tensor \
        --pipeline_config_path object_detection/samples/configs/ssd_mobilenet_v1_pets.config \
        --trained_checkpoint_prefix model.ckpt-$1 \
        --output_directory exported_graphs

$1 is the CHECKPOINT_NUMBER.
The exported files will save into exported_graphs folder.

$ tree ../exported_graphs/
../exported_graphs/
├── checkpoint
├── frozen_inference_graph.pb
├── model.ckpt.data-00000-of-00001
├── model.ckpt.index
├── model.ckpt.meta
├── pipeline.config
└── saved_model
    ├── saved_model.pb
    └── variables

Test the model

refer to the object_detection_tutorial.ipynb to modify to read the local model.

@junxnone
Copy link
Owner Author

#202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant