You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/training.rst
+78-47
Original file line number
Diff line number
Diff line change
@@ -48,12 +48,13 @@ Preparing the Workspace
48
48
└─ workspace/
49
49
└─ training_demo/
50
50
51
-
3. The ``training_demo`` folder shall be our `training folder`, which will contain all files related to our model training. It is advisable to create a separate training folder each time we wish to train a different model. The typical structure for training folders is shown below.
51
+
3. The ``training_demo`` folder shall be our `training folder`, which will contain all files related to our model training. It is advisable to create a separate training folder each time we wish to train on a different dataset. The typical structure for training folders is shown below.
52
52
53
53
.. code-block:: default
54
54
55
55
training_demo/
56
56
├─ annotations/
57
+
├─ exported-models/
57
58
├─ images/
58
59
│ ├─ test/
59
60
│ └─ train/
@@ -64,6 +65,7 @@ Preparing the Workspace
64
65
Here's an explanation for each of the folders/filer shown in the above tree:
65
66
66
67
- ``annotations``: This folder will be used to store all ``*.csv`` files and the respective TensorFlow ``*.record`` files, which contain the list of annotations for our dataset images.
68
+
- ``exported-models``: This folder will be used to store exported versions of our trained model(s).
67
69
- ``images``: This folder contains a copy of all the images in our dataset, as well as the respective ``*.xml`` files produced for each one, once ``labelImg`` is used to annotate objects.
68
70
69
71
* ``images/train``: This folder contains a copy of all images, and the respective ``*.xml`` files, which will be used to train our model.
@@ -79,15 +81,20 @@ If you do not understand most of the things mentioned above, no need to worry, a
79
81
Preparing the Dataset
80
82
---------------------
81
83
84
+
Annotate the Dataset
85
+
********************
86
+
82
87
.. _labelImg_install:
83
88
84
89
Install LabelImg
85
-
****************
90
+
~~~~~~~~~~~~~~~~
86
91
87
92
There exist several ways to install ``labelImg``. Below are 3 of the most common.
88
93
89
-
Get from PyPI (Recommended)
90
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
94
+
.. _labelImg_install_pip:
95
+
96
+
Using PIP (Recommended)
97
+
#######################
91
98
1. Open a new `Terminal` window and activate the `tensorflow_gpu` environment (if you have not done so already)
92
99
2. Run the following command to install ``labelImg``:
93
100
@@ -104,7 +111,7 @@ Get from PyPI (Recommended)
104
111
labelImg [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
105
112
106
113
Use precompiled binaries (Easy)
107
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114
+
###############################
108
115
Precompiled binaries for both Windows and Linux can be found `here <http://tzutalin.github.io/labelImg/>`__ .
109
116
110
117
Installation is the done in three simple steps:
@@ -137,7 +144,7 @@ Installation is the done in three simple steps:
137
144
labelImg [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
138
145
139
146
Build from source (Hard)
140
-
~~~~~~~~~~~~~~~~~~~~~~~~
147
+
########################
141
148
The steps for installing from source follow below.
142
149
143
150
**1. Download labelImg**
@@ -193,25 +200,27 @@ The steps for installing from source follow below.
193
200
# From within Tensorflow/addons/labelImg
194
201
python labelImg.py
195
202
# or
196
-
python labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
203
+
python labelImg.py [IMAGE_PATH] [PRE-DEFINED CLASS FILE]
197
204
198
-
Annotate Images
199
-
***************
200
205
201
-
To annotate images we will be using the `labelImg <https://github.com/tzutalin/labelImg>`_ package. If you haven't installed the package yet, then have a look at :ref:`labelImg_install`.
206
+
Annotate Images
207
+
~~~~~~~~~~~~~~~
202
208
203
209
- Once you have collected all the images to be used to test your model (ideally more than 100 per class), place them inside the folder ``training_demo/images``.
204
-
- Open a new `Anaconda/Command Prompt` window and ``cd`` into ``Tensorflow/addons/labelImg``.
205
-
- If (as suggested in :ref:`labelImg_install`) you created a separate Conda environment for ``labelImg`` then go ahead and activate it by running:
210
+
- Open a new `Terminal` window.
211
+
- Next go ahead and start ``labelImg``, pointing it to your ``training_demo/images`` folder.
212
+
213
+
- If you installed ``labelImg`` :ref:`labelImg_install_pip`:
- A File Explorer Dialog windows should open, which points to the ``training_demo/images`` folder.
@@ -232,16 +241,42 @@ I won't be covering a tutorial on how to use ``labelImg``, but you can have a lo
232
241
Partition the Dataset
233
242
*********************
234
243
235
-
Once you have finished annotating your image dataset, it is a general convention to use only part of it for training, and the rest is used for evaluation purposes (e.g. as discussed in :ref:`evaluation_sec`).
244
+
Once you have finished annotating your image dataset, it is a general convention to use only part
245
+
of it for training, and the rest is used for evaluation purposes (e.g. as discussed in
246
+
:ref:`evaluation_sec`).
236
247
237
-
Typically, the ratio is 90%/10%, i.e. 90% of the images are used for training and the rest 10% is maintained for testing, but you can chose whatever ratio suits your needs.
248
+
Typically, the ratio is 90%/10%, i.e. 90% of the images are used for training and the rest 10% is
249
+
maintained for testing, but you can chose whatever ratio suits your needs.
238
250
239
-
Once you have decided how you will be splitting your dataset, copy all training images, together with their corresponding ``*.xml`` files, and place them inside the ``training_demo/images/train`` folder. Similarly, copy all testing images, with their ``*.xml`` files, and paste them inside ``training_demo/images/test``.
251
+
Once you have decided how you will be splitting your dataset, copy all training images, together
252
+
with their corresponding ``*.xml`` files, and place them inside the ``training_demo/images/train``
253
+
folder. Similarly, copy all testing images, with their ``*.xml`` files, and paste them inside
254
+
``training_demo/images/test``.
240
255
241
-
For lazy people like myself, who cannot be bothered to do the above, I have put tugether a simple script that automates the above process:
256
+
For lazy people like myself, who cannot be bothered to do the above, I have put together a simple
257
+
script that automates the above process:
242
258
243
259
.. literalinclude:: scripts/partition_dataset.py
244
260
261
+
- Under the ``TensorFlow`` folder, create a new folder ``TensorFlow/scripts``, which we can use to store some useful scripts.
262
+
- To make things even tidier, let's create a new folder ``TensorFlow/scripts/preprocessing``, where we shall store scripts that we can use to preprocess our training inputs. Below is out ``TensorFlow`` directory tree structure, up to now:
263
+
264
+
.. code-block:: default
265
+
266
+
TensorFlow/
267
+
├─ addons/ (Optional)
268
+
│ └─ labelImg/
269
+
├─ models/
270
+
│ ├─ community/
271
+
│ ├─ official/
272
+
│ ├─ orbit/
273
+
│ ├─ research/
274
+
│ └─ ...
275
+
├─ scripts/
276
+
│ └─ preprocessing/
277
+
└─ workspace/
278
+
└─ training_demo/
279
+
245
280
- Click :download:`here <scripts/partition_dataset.py>` to download the above script and save it inside ``TensorFlow/scripts/preprocessing``.
246
281
- Then, ``cd`` into ``TensorFlow/scripts/preprocessing`` and run:
247
282
@@ -286,35 +321,13 @@ Create TensorFlow Records
286
321
Now that we have generated our annotations and split our dataset into the desired training and
287
322
testing subsets, it is time to convert our annotations into the so called ``TFRecord`` format.
288
323
289
-
Before we proceed to describe the above steps, let's create a directory where we can store some
290
-
scripts. Under the ``TensorFlow`` folder, create a new folder ``TensorFlow/scripts``, which we can
291
-
use to store some useful scripts. To make things even tidier, let's create a new folder
292
-
``TensorFlow/scripts/preprocessing``, where we shall store scripts that we can use to preprocess
293
-
our training inputs. Below is out ``TensorFlow`` directory tree structure, up to now:
294
-
295
-
.. code-block:: default
296
-
297
-
TensorFlow/
298
-
├─ addons/ (Optional)
299
-
│ └─ labelImg/
300
-
├─ models/
301
-
│ ├─ community/
302
-
│ ├─ official/
303
-
│ ├─ orbit/
304
-
│ ├─ research/
305
-
│ └─ ...
306
-
├─ scripts/
307
-
│ └─ preprocessing/
308
-
└─ workspace/
309
-
└─ training_demo/
310
-
311
324
312
325
Convert ``*.xml`` to ``*.record``
313
326
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
314
327
315
-
To do this we can write a simple script that iterates through all ``*.xml`` files in the ``training_demo/images/train`` and ``training_demo/images/test`` folders, and generates a ``*.record`` file for each of the two.
316
-
317
-
Here is an example script that allows us to do just that:
328
+
To do this we can write a simple script that iterates through all ``*.xml`` files in the
329
+
``training_demo/images/train`` and ``training_demo/images/test`` folders, and generates a
330
+
``*.record`` file for each of the two. Here is an example script that allows us to do just that:
318
331
319
332
.. literalinclude:: scripts/generate_tfrecord.py
320
333
@@ -401,6 +414,8 @@ model, you can download the model and after extracting its context the demo dire
401
414
| └─ pipeline.config
402
415
└─ ...
403
416
417
+
.. _training_pipeline_conf:
418
+
404
419
Configure the Training Pipeline
405
420
*******************************
406
421
Now that we have downloaded and extracted our pre-trained model, let's create a directory for our
@@ -530,7 +545,7 @@ The steps to run the evaluation are outlined below:
530
545
531
546
#. Secondly, we must modify the configuration pipeline (``*.config`` script).
532
547
533
-
- See lines 178 and 181 of the script in :ref:`config_training_pipeline_sec`.
548
+
- See lines 178-179 of the script in :ref:`training_pipeline_conf`.
534
549
535
550
#. The third step is to actually run the evaluation. To do so, open a new `Terminal`, ``cd`` inside the ``training_demo`` folder and run the following command:
536
551
@@ -611,8 +626,8 @@ following which you should be presented with a dashboard similar to the one show
611
626
612
627
613
628
614
-
Exporting a Trained Inference Graph
615
-
-----------------------------------
629
+
Exporting a Trained Model
630
+
-------------------------
616
631
617
632
Once your training job is complete, you need to extract the newly trained inference graph, which
618
633
will be later used to perform the object detection. This can be done as follows:
@@ -622,7 +637,23 @@ will be later used to perform the object detection. This can be done as follows:
0 commit comments