-
Notifications
You must be signed in to change notification settings - Fork 1
Training a Custom model with Detectron
Training a model with Detectron:
Let's start with some introductory links:
From: Detectron - FAQ (Frequent Asked Questions) FAQ)
Q: How do I use Detectron to train a model on a custom dataset?
A: If possible, we strongly recommend that you first convert the custom dataset annotation format to the COCO API json format. Then, add your dataset to the dataset catalog so that Detectron can use it for training and inference. If your dataset cannot be converted to the COCO API json format, then it's likely that more significant code modifications will be required. If the dataset you're adding is popular, please consider making the converted annotations publicly available; If code modifications are required, please consider submitting a pull request.
And Citing @Vladimir Ilin comment on the next issue: transform from pascal voc format to coco format for object detection only with custom data "Add info about your datasets (paths to directories and json files) to file dataset_catalog.py and then specify datasets names in the config file (.yml) in TRAIN.DATASETS and TEST.DATASETS. You can specify a value of TRAIN.SNAPSHOT_ITERS. It's a model checkpoint period and as said in core/config.py it depends on number of GPUs. I used only 1 GPU and also decreased the value to save a model more frequently. And when you will run inference (it may or not be automatically after training) it will take names of classes from dummy_datasets.py so I changed it to get my class names on images."
-
Dataset Conversions if needed: We need to convert the data set to COCO format. In our case, we had Pascal_Voc format, so we converted it to coco (check here and here ... We still need to check if they do bboxes only or also the masks).
-
Dataset needs to be separated into Train-Valid-Test for Annotations and images. We will need to create 3 folders with the images and three files with the annotations for each folder.
-
Change 2 files:
-
Create a configuration file:. Just copy one, change its name and modify it with your own necessities, call it for example: clear_image.yaml
-
Modify the dataset_catalog.py as well. Remember to save a backup dataset_catalog.py before editing
-
-
Run Detectron from the terminal:
COCO_dataset:
$ python2 tools/train_net.py --cfg configs/getting_started/tutorial_1gpu_e2e_faster_rcnn_R-50-FPN.yaml OUTPUT_DIR /tmp/detectron-output
Custom dataset:
$ python2 tools/train_net.py --cfg configs/clear_image.yaml OUTPUT_DIR /tmp/detectron-output