How to continue training an object detection model using Tensorflow Object Detection API?
Asked Answered
E

2

7

I'm using Tensorflow Object Detection API to train an object detection model using transfer learning. Specifically, I'm using ssd_mobilenet_v1_fpn_coco from the model zoo, and using the sample pipeline provided, having of course replaced the placeholders with actual links to my training and eval tfrecords and labels.

I was able able to successfully train a model on my ~5000 images (and corresponding bounding boxes) using the above pipeline (I'm mainly using Google's ML Engine on TPU, if revelant).

Now, I prepared an additional ~2000 images, and would like continue training my model with those new images, without restarting from scratch (training the initial model took ~6h of TPU time). How can I do that?

Eufemiaeugen answered 1/11, 2018 at 15:25 Comment(0)
E
8

You have two options, in both you need to change the input_path of the train_input_reader of your new dataset:

  1. When specifying a checkpoint to fine-tune in the training configuration, specify the checkpoint of your trained model
train_config{
    fine_tune_checkpoint: <path_to_your_checkpoint>
    fine_tune_checkpoint_type: "detection"
    load_all_detection_checkpoint_vars: true
}
  1. Simply keep using the same configuration (except the train_input_reader) with the same model_dir of your previous model. That way, the API will create a graph and will check whether a checkpoint already exists in model_dir and fits the graph. If so - it will restore it and continue training it.

Edit: fine_tune_checkpoint_type was previously set as true by mistake, while it should be "detection" or "classification" in general, and "detection" in this specific case. Thanks Krish for noticing.

Electrodynamic answered 4/11, 2018 at 8:24 Comment(1)
Did you simply add more examples of classes already represented for did you introduce new classes? If new classes, what value did you use for num_classes: in the pipeline? Also, did you create a new classes.pbtxt file or simply append the new classes?Historical
C
1

I haven't retrained the object detection model on a new dataset, but it looks like increasing the number of training steps train_config.num_steps in the config file and also adding images in the tfrecord files should be enough for that.

Cyclograph answered 1/11, 2018 at 15:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.