Label file in tensorflow object detection training

Viewed 612

I want to create my own .tfrecord files using tensorflow object detection API and use them for training. The record will be a subset of original dataset so the model will detect only specific categories. The thing I dont understand and cant find any information about is, how are id`s assigned to labels in label_map.pbtxt during training.

What I do...

Step 1: assign label_id during creation of the tfrecord file, where I put my own ids:

'image/object/class/label': dataset_util.int64_list_feature(category_ids)
'image/object/class/text': dataset_util.bytes_list_feature(category_names)

Step 2: create labels file with e.g. two categories:

item { name: "apple"  id: 53  display_name: "apple" }
item { name: "broccoli"  id: 56  display_name: "broccoli" }

Step 3: Train the model

After training, there are some objects detected, but with N/A label. When I set the id`s starting from 1 then it shows correct labels.

My questions are:

  1. Why it did not map correctly to label with custom id?
  2. Can the second id have other value than 2? I'm sure I saw skipped ids in labels file for coco dataset.
  3. How to set the id to have custom value, if possible?

Thanks

1 Answers

I had the same problem with my label map. After Googling a bit, I found your question here and also this excerpt from the TensorFlow Object Detection repository:

Each dataset is required to have a label map associated with it. This label map defines a mapping from string class names to integer class Ids. The label map should be a StringIntLabelMap text protobuf. Sample label maps can be found in object_detection/data. Label maps should always start from id 1.

I also checked the source code for label_map_util.py and found this comment:

We only allow class into the list if its id-label_id_offset is between 0 (inclusive) and max_num_classes (exclusive). If there are several items mapping to the same id in the label map, we will only keep the first one in the categories list

So in your example, which only has two classes, valid ID's are 1 and 2. Any higher value will be ignored.

Related