junxnone / tio

Log
Other
10 stars 5 forks source link

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

Open junxnone opened 5 years ago

junxnone commented 5 years ago

Reference

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:

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 commented 5 years ago

202