File size: 13,395 Bytes
747451d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# <a>Object detection STM32 model zoo</a>

Before you start using this project, it's important to understand the supported dataset names and formats. Please note that for all the training, evaluation and quantization services, it is expected to have a dataset in TFS Tensorflow format. For the object detection use case, the `get_dataset` API call takes care of the conversion of your dataset automatically depending on the `dataset_name` and `format` attributes.

The `dataset` section and its attributes are shown in the YAML code below.

```yaml
dataset:
  format: pascal_voc
  dataset_name: pascal_voc                                    # Dataset name. Defaults to "<unnamed>".
  class_names: [ aeroplane,bicycle,bird,boat,bottle,bus,car,cat,chair,cow,diningtable,dog,horse,motorbike,person,pottedplant,sheep,sofa,train,tvmonitor ] # Names of the classes in the dataset.
  data_dir: ./datasets/pascal_voc/tmp/                       # Path to the tmp directory before the split.
  train_images_path: /local/datasets/VOC0712/JPEGImages/     # Path to the root directory of the img before split.
  train_xml_dir: /local/datasets/VOC0712/Annotations         # Path to the root directory of the xml annotations
  training_path: <training-set-root-directory>               # Path to the root directory of the training set.
  validation_path: <validation-set-root-directory>           # Path to the root directory of the validation set.
  validation_split: 0.2                                      # Training/validation sets split ratio.
  test_path: <test-set-root-directory>                       # Path to the root directory of the test set.
  quantization_path: <quantization-set-root-directory>       # Path to the root directory of the quantization set.
  quantization_split:                                        # Quantization split ratio.
  seed: 123                                                  # Random generator seed used when splitting a dataset.
```

The `dataset_name` attribute is required and serves to specify the dataset you are using. This can be a well-known dataset like coco, pascal_voc, or a custom_dataset if you have your own data and it follows the logic below:

| Dataset Name     | Allowed Formats          | Description                                                                                  |
|------------------|-------------------------|----------------------------------------------------------------------------------------------|
| `coco`           | `coco`, `tfs`           | Native COCO format or TFS TensorFlow format                                                     |
| `pascal_voc`     | `pascal_voc`, `tfs`     | Native Pascal VOC format or TFS TensorFlow format                                               |
| `darknet_yolo`   | `darknet_yolo`, `tfs`   | Native Darknet YOLO format or TFS TensorFlow format                                             |
| `custom_dataset` | `tfs`                   | Only TFS TensorFlow format; in case the dataset is already converted before evaluation                          |

Depending on the `dataset_name`, the dataset loader will check the `format` to determine if it is necessary to convert the dataset to the final **TFS TensorFlow format**. These two parameters are mandatory if the operation mode is **training**, **evaluation** and **quantization**.

The `format` attributes defines the annotation format of your dataset. This must match the format of your dataset annotations. 
It serves to check whether your dataset is in its original format or in TFS TensorFlow format. 
This determines whether it is needed to convert the dataset to the required TFS format or not. It accepts the following values: 

  * `tfs`: If the dataset is a TensorFlow Object Detection API format.
  * `coco`: If the dataset is in COCO dataset format (JSON annotations).
  * `pascal_voc`: If the dataset is in Pascal VOC XML annotation format.
  * `darknet_yolo`: If the dataset is in YOLO Darknet text file annotations.

Depending on the `format` value, some additional attributes should be defined in the dataset section:
- If the `format` is set to **coco**, the following attributes should be set:
  * The `data_dir`: Required, refers to the temporary path where the TFS files will be generated.
  * The `train_images_path`: Required, refers to the path of the training subset directory where the images are located.
  * The `train_annotations_path`: Required, refers to the path of the training subset json file of the annotations.
  * The `val_images_path`: Optional, refers to the path of the validation subset directory where the images are located.
  * The `val_annotations_path`: Optional, refers to the path of the training subset json file of the annotations.

- If the `format` is set to **pascal_voc**, the following attributes should be set:
  * The `data_dir`: Required, refers to the temporary path where the TFS files will be generated.
  * The `train_images_path`: Required, refers to the path of the training subset directory where the images are located.
  * The `train_xml_dir`: Required, refers to the path of the training subset directory containing the xml files of the annotations.
  * The `val_images_path`: Optional, refers to the path of the validation subset directory where the images are located.
  * The `val_xml_dir`: Optional, refers to the path of the training subset directory containing the xml files of the annotations.

- If the `format` is set to **darknet_yolo**, the following attributes should be set:
  * The `data_dir`: Required, refers to the path of the directory containing the txt files of the annotations along with the images.


The state machine below describes the process of dataset loading for object detection use case.


```
                                                   dataset_name
                                                         |
                                                         |
        +----------------------------------+--------------------------+-------------------------------+
        |                                  |                          |                               |
        |                                  |                          |                               |
      coco                           pascal_voc              darknet_yolo                "custom_dataset"
        |                                  |                          |                               |
        |                                  |                          |                               |
  +-----+------------+           +-----+-----------+          +-------+-------+               +-------+-------+ 
  |                  |           |                 |          |               |               |               |
supported        unsupported    supported    unsupported   supported     unsupported      supported      unsupported        
 format:           format        format         format      format:        format           format         format
      |                             |                           |                             |
  +---+-----+                   +---+---+                  +----+-----+                       |
  |         |                   |       |                  |          |                       |
 coco      tfs             pascal_voc  tfs            darknet_yolo   tfs                     tfs
  |         |                   |       |                  |          |                (Custom dataset
  |         |                   |       |                  |          |                 should be used
  |         |                   |       |                  |          |                if the conversion
  |   dataset.format=tfs        |  dataset.format=tfs      |    dataset.format=tfs     has already been
  |   (already TFS)             |    (already TFS)         |      (already TFS)        done in a previous
  |         |                   |       |                  |          |                training or eval)
  |         |                   |       |                  |          |                       |
  |   load TFS directly         |   load TFS directly      |      load TFS directly      load TFS directly
  |                             |                          |                                  |
  |                             |                          |                                  |
dataset.format=coco     dataset.format=pascal_voc      dataset.format=darknet_yolo            |
(needs conversion)         (needs conversion)             (needs conversion)                  |
        |                         |                               |                           |
        v                         v                               v                           |
convert coco to tfs      convert pascal_voc to tfs     convert darknet yolo to tfs            |
        |                         |                               |                           |
        +-------------------------+-------------------------------+---------------------------+
                                                |
                                        Dataset in TFS format
                                            (used for)
                          +---------------------+-----------------------+
                          |                     |                       |
                      training             evaluation             quantization

```

## Dataset Configuration

### Details of Required / Optional Attributes per `(dataset_name, format)`

---

### 1. `dataset_name = coco`

**Supported `format` values:**

- `tfs`
- `coco`

#### 1.a `format = tfs`

- Dataset is already in **TFS TensorFlow** format.
- Loader reads TFS files directly.

**Required attributes**

- `data_dir`  
  β†’ Temporary path where the TFS files are located.

---

#### 1.b `format = coco`

- Dataset is in **COCO JSON** annotation format and must be converted to TFS.

**Required attributes**

- `data_dir`  
  β†’ Temporary path where the TFS files will be generated.
- `train_images_path`  
  β†’ Path to training images directory.
- `train_annotations_path`  
  β†’ Path to training subset COCO JSON annotations file.

**Optional attributes**

- `val_images_path`  
  β†’ Path to validation images directory.
- `val_annotations_path`  
  β†’ Path to validation subset COCO JSON annotations file.

**Conversion flow**

1. Read images/annotations from `train_*` (and optionally `val_*`).
2. Generate TFS TensorFlow records into `data_dir`.
3. Load resulting TFS dataset for training / evaluation / quantization with the specified split ratios.

---

### 2. `dataset_name = pascal_voc`

**Supported `format` values:**

- `tfs`
- `pascal_voc`

#### 2.a `format = tfs`

- Dataset is already in **TFS TensorFlow** format.
- Loader reads TFS files directly.

**Required attributes**

- `data_dir`  
  β†’ Temporary path where the TFS files are located.

---

#### 2.b `format = pascal_voc`

- Dataset is in **Pascal VOC XML** annotation format and must be converted.

**Required attributes**

- `data_dir`  
  β†’ Temporary path where the TFS files will be generated.
- `train_images_path`  
  β†’ Path to training images directory.
- `train_xml_dir`  
  β†’ Path to directory containing training XML annotation files.

**Optional attributes**

- `val_images_path`  
  β†’ Path to validation images directory.
- `val_xml_dir`  
  β†’ Path to directory containing validation XML annotation files.

**Conversion flow**

1. Read images/annotations from `train_*` (and optionally `val_*`).
2. Generate TFS TensorFlow records into `data_dir`.
3. Load resulting TFS dataset for training / evaluation / quantization.

---

### 3. `dataset_name = darknet_yolo`

**Supported `format` values:**

- `tfs`
- `darknet_yolo`

#### 3.a `format = tfs`

- Dataset is already in **TFS TensorFlow** format.
- Loader reads TFS files directly.

**Required attributes**

- `data_dir`  
  β†’ Temporary path where the TFS files are located.

---

#### 3.b `format = darknet_yolo`

- Dataset is in **YOLO Darknet text** annotation format and must be converted.

**Required attributes**

- `data_dir`  
  β†’ Path to the directory containing:
  - the `.txt` annotation files
  - the corresponding images

> No separate train/val split paths are specified. By convention, `data_dir` contains both the `.txt` files and images to be converted.

**Conversion flow**

1. Parse YOLO `.txt` annotations and corresponding images in `data_dir`.
2. Generate TFS TensorFlow records.
3. Load resulting TFS dataset for training / evaluation / quantization.

---

### 4. `dataset_name = "custom_dataset"`

**Supported `format` values:**

- `tfs`

This case assumes:

- The user has already produced a **TFS TensorFlow dataset** externally or from a previous operation.
- The loader only reads the TFS dataset (no conversion is performed).

**Required / optional attributes**

- Depend on your custom TFS dataset layout (not defined here).
- At minimum, paths pointing to the TFS TFRecord files (train/val) must be provided according to the specific tool’s configuration schema.

---

### Operation Modes and Mandatory Parameters

For the following operation modes:

- `training`
- `evaluation`
- `quantization`

The following parameters are **mandatory**:

- `dataset_name`
- `format`