Object Detection datasets ¶
This guide describes how the TensorFlow object detection services read a dataset: the supported annotation formats, the
dataset
section attributes, and how the training, validation, test, quantization, and prediction sets are built. For the PyTorch pipeline, see the
PyTorch training guide: it reads COCO-format datasets, and Pascal VOC for SSD models only.
The annotations are parsed directly in their original format when the data loaders are created and kept in memory. No conversion step is needed and no intermediate file is written on disk.
1. Supported formats ¶
Set
dataset.format
to the annotation format of your dataset:
|
|
Annotations |
Layout |
|---|---|---|
|
|
One JSON file per split |
An image folder and an annotation JSON file per split, for example
|
|
|
One XML file per image |
The
|
|
|
One
|
|
General rules:
Images: for
darknet_yoloandvoc, images must be.jpgfiles. Forcoco, the images are looked up by thefile_nameof the JSON file in the image folder; images listed in the annotations but missing from the folder are skipped. Folders of images for quantization and prediction must contain.jpgfiles, directly in the folder (no sub-folders).Classes:
dataset.class_namesis required for training and evaluation. Forcocoandvoc, the classes are selected by name and ordered as inclass_names; annotations of other classes are ignored. Fordarknet_yolo, theclass_idof the label files is the index inclass_names.Images without objects: images without annotation are kept as background images. Set
exclude_unlabeled: Trueto remove them.Maximum number of boxes: at most
max_gtboxes (default20) are kept per image; the others are dropped.
2. The
dataset
section
¶
dataset:
format: darknet_yolo # coco, voc or darknet_yolo
dataset_name: darknet_yolo # Selects the dataset wrapper, see section 3
dataset_subsetname: person # Optional. With dataset_name, selects the pretrained weights
class_names: [person] # Names of the classes
exclude_unlabeled: True # Optional, default False
max_gt: 20 # Optional, default 20
train_images_path: <train-images-directory>
train_annotations_path: <train-annotations>
val_images_path: <validation-images-directory> # Optional
val_annotations_path: <validation-annotations> # Optional
# validation_split: 0.2 # Used when no validation set is given
test_images_path: <test-images-directory> # Optional for training, required for evaluation
test_annotations_path: <test-annotations>
quantization_path: <quantization-images-directory> # Optional
quantization_split: # Optional
prediction_path: <prediction-images-directory> # Required for prediction
seed: 123
|
Attribute |
Description |
|---|---|
|
|
Annotation format. Required for
|
|
|
Selects the dataset wrapper (see section 3). Required for
|
|
|
List of the class names. Required for
|
|
|
If
|
|
|
Maximum number of boxes kept per image. Default:
|
|
|
Fraction of the training set used for validation when no validation set is given. Must be between 0 and 1 (excluded). Default:
|
|
|
Folder of calibration images. No annotations are needed. |
|
|
Fraction of the calibration images to use, between 0 (excluded) and 1. If it is set to
|
|
|
Folder of the images to predict. |
|
|
Seed used to shuffle the data and to split the training set. Default:
|
3. Dataset wrappers ¶
The
dataset_name
value selects a registered dataset wrapper:
coco,
voc,
darknet_yolo,
custom_dataset, or
custom. Any other value raises an error when the data loaders are created.
All the wrappers behave the same way: the loader is chosen with
dataset.format, not with
dataset_name. A dataset named
coco
can therefore be in
darknet_yolo
format, as in the example configuration files. Use
custom_dataset
for your own data if you do not want to reuse the name of a public dataset.
dataset_name -> dataset wrapper (coco, voc, darknet_yolo, custom_dataset, custom)
|
dataset.format
+-----------------+-----------------+
coco voc darknet_yolo
parse the JSON parse the XML parse the .txt
annotations annotations labels
+-----------------+-----------------+
|
samples kept in memory, then split in
train / validation / test (training, evaluation)
quantization and prediction sets
4. Attributes per format ¶
The attributes below are for the
training
mode. For the
evaluation
mode alone, only the
test_*
attributes are used, and they are all required.
4.1
format:
coco
¶
|
Attribute |
Training |
Evaluation |
|---|---|---|
|
|
Required: folder of the training images |
|
|
|
Required: COCO JSON file of the training set |
|
|
|
Optional. Both are needed to use a validation set. |
|
|
|
Optional. Both are needed to use a test set. |
Required |
If
download_data:
True
is set, the loader ignores the
train_*
and
val_*
paths and expects the official COCO layout in
data_dir: the
train2017
and
val2017
image folders and
annotations/instances_train2017.json
and
annotations/instances_val2017.json. The files are not downloaded by the loader: download and extract the dataset beforehand. The
train_images_path
and
train_annotations_path
attributes must still be set.
4.2
format:
voc
¶
|
Attribute |
Training |
Evaluation |
|---|---|---|
|
|
Required:
|
|
|
|
Required: folder of the XML annotation files |
|
|
|
Required:
|
|
|
|
Optional. All three are needed to use a validation set. |
|
|
|
Optional. All three are needed to use a test set. |
Required |
The split files list one image name per line, without extension. The image
<name>.jpg
and the annotation
<name>.xml
are read from the images and annotations folders.
download_data
and
data_dir
are not used by the Pascal VOC loader.
4.3
format:
darknet_yolo
¶
|
Attribute |
Training |
Evaluation |
|---|---|---|
|
|
Required: folder of the
|
|
|
|
Required: folder of the
|
|
|
|
Optional. Both are needed to use a validation set. |
|
|
|
Optional. Both are needed to use a test set. |
Required |
For each image
<name>.jpg, the labels are read from
<name>.txt
in the annotations folder. An image without label file is a background image.
download_data:
True
is not supported for this format.
5. How the sets are built ¶
Validation set: if no validation set is given,
validation_splitof the training set is used for validation (80:20 by default). Use the samevalidation_splitvalue in the training and evaluation services.Test set: if no test set is given, the validation set is used as the test set. Using a separate test set gives a more reliable estimate of the accuracy.
Quantization set: the images of
quantization_pathare used. If it is empty, the images oftrain_images_pathare used. If neither is set, or ifquantization_splitis0, the model is quantized with random data: the accuracy is meaningless, but the footprints on target can be estimated.quantization_splitselects a fraction of the images.Preprocessing: the bounding boxes are updated together with the images when they are resized or augmented.
6. Required attributes per operation mode ¶
|
Operation mode |
Required |
|---|---|
|
|
|
|
|
|
|
|
Nothing:
|
|
|
|
|
|
|
|
|
Nothing |
|
|
|