11# Motivation
22
3+ ## Mapillary dataset
4+
35In this project we use a set of images provided
46by [ Mapillary] ( https://www.mapillary.com/ ) , in order to investigate on the
57presence of some typical street-scene objects (vehicles, roads,
6- pedestrians...). Mapillary released this dataset recently , it
7- is [ still available on its website] ( https://www.mapillary.com/dataset/vistas )
8+ pedestrians...). Mapillary released this dataset on July 2017 , it
9+ is [ available on its website] ( https://www.mapillary.com/dataset/vistas )
810and may be downloaded freely for a research purpose.
911
1012As inputs, Mapillary provides a bunch of street scene images of various sizes
@@ -19,6 +21,18 @@ There are 18000 images in the training set, 2000 images in the validation set,
1921and 5000 images in the testing set. The testing set is proposed only for a
2022model test purpose, it does not contain filtered versions of images.
2123
24+ ## Shape dataset
25+
26+ To complete the project, and make the test easier, a randomly-generated shape model is also
27+ available. In this dataset, some simple coloured geometric shapes are inserted into each picture,
28+ on a total random mode. There can be one rectangle, one circle and/or one triangle per image, or
29+ neither of them. Their location into each image is randomly generated (they just can't be too close
30+ to image borders). The shape and background colors are randomly generated as well.
31+
32+ The picture below shows an example of image generated in this way:
33+
34+ ![ Example of shape image] ( ./images/shape_00000.png )
35+
2236# Dependencies
2337
2438This project needs to load the following Python dependencies:
@@ -31,48 +45,63 @@ This project needs to load the following Python dependencies:
3145+ PIL
3246+ tensorflow
3347
34- As a remark, the code has been run with Python3 (version 3.5).
48+ These dependencies are stored in ` requirements.txt ` located at the project root. As a remark, the
49+ code has been run with Python3 (version 3.5).
3550
3651# Content
3752
38- Contain some Python materials designed to illustrate the Tensorflow library
39- (snippets and notebooks)
53+ The project contains some Python materials designed to illustrate the Tensorflow library (snippets
54+ and notebooks)
4055
41- + [ sources] ( ./sources ) contains Python modules that train a convolutional
42- neural network based on the Mapillary street image dataset
43- + [ images] ( ./images ) contains some example images to illustrate the Mapillary
44- dataset as well as some preprocessing analysis results
56+ + [ article] ( ./article ) contains the original text of articles that have been published
57+ on [ Oslandia blog] ( http://oslandia.com/en/blog/ ) on this topic
58+ + [ images] ( ./images ) contains some example images to illustrate the Mapillary dataset as well as
59+ some preprocessing analysis results
60+ + [ notebooks] ( ./notebooks ) contains some Jupyter notebooks that aim at describing data or basic
61+ neural network construction
62+ + [ sources] ( ./sources ) contains Python modules that train a convolutional neural network based on
63+ the Mapillary street image dataset
4564
4665Additionally, running the code may generate extra repositories:
4766
4867+ [ checkpoints] ( ./checkpoints ) refers to trained model back-ups, they are
4968 organized with respect to models
5069+ [ graphs] ( ./graphs ) is organized like ` checkpoints ` repository, it contains
5170 ` Tensorflow ` graphs corresponding to each neural network
71+ + [ chronos] ( ./chronos ) allows to store some training execution times, if wanted
72+
73+ These repository are located at the data repository root.
5274
5375# Running the code
5476
5577This project supposes that you have downloaded the Mapillary image dataset. The
5678following program calls are supposed to be made from the ` source ` repository.
5779
80+ ## Printing Mapillary glossary
81+
5882First of all, the Mapillary glossary can be printed for information purpose
5983with the following command:
6084
6185```
62- python3 train.py -g -d mapillary -dp ../ data
86+ python3 train.py -g -d mapillary -s 256 - dp ./any- data-path
6387```
6488
65- The ` -g ` argument makes the program recover the data glossary that corresponds
66- to the dataset indicated by ` -d ` command (the program expects ` mapillary ` or
67- ` shape ` ). By default, the program will look for the glossary in ` ../data `
68- repository (* i.e.* it hypothesizes that the data repository is at the project
69- root, or that a symbolic link points to it). This behavior may be changed
70- through ` -dp ` argument.
89+ The ` -g ` argument makes the program recover the data glossary that corresponds to the dataset
90+ indicated by ` -d ` command (the program expects ` mapillary ` or ` shapes ` ). By default, the program
91+ will look for the glossary in ` ../data ` repository (* i.e.* it hypothesizes that the data repository
92+ is at the project root, or that a symbolic link points to it). This behavior may be changed through
93+ ` -dp ` argument. By default, the image characteristics are computed starting from resized images of
94+ 512 * 512 pixels, that can be modified with the ` -s ` argument.
95+
96+ As an easter-egg feature, label popularity (proportion of images where the label appears in the
97+ dataset) is also printed for each label.
98+
99+ ## Model training
71100
72101Then the model training itself may be undertaken:
73102
74103```
75- python3 train.py -d mapillary - dp ../data -n mapcnn -s 512 -e 5
104+ python3 train.py -dp ../data -d mapillary -n mapcnn -s 512 -e 5
76105```
77106
78107In this example, 512* 512 images will be exploited (either after a
@@ -84,21 +113,58 @@ indicated by the `-e` argument. One epoch refers to the scan of every training
84113image.
85114
86115Some other arguments may be parametrized for running this program:
87- + ` -h ` : show the help message
116+ + ` -a ` : aggregate labels ( * e.g. * ` car ` , ` truck ` or ` caravan ` ... into a ` vehicle ` labels)
88117+ ` -b ` : indicate the batch size (number of images per training batch, 20 by
89118 default)
90- + ` -dn ` : dataset name (` training ` , ` validation ` or ` testing ` ), useful for image
91- storage on file system
119+ + ` -c ` : indicates if training time must be measured
92120+ ` -do ` : percentage of dropped out neurons during training process
121+ + ` -h ` : show the help message
122+ + ` -it ` : number of training images (default to 18000, according to the Mapillary dataset)
123+ + ` -iv ` : number of validation images (default to 200, regarding computing memory limitation, as
124+ validation is done at once)
93125+ ` -l ` : IDs of considered labels during training (between 1 and 65 if
94126 ` mapillary ` dataset is considered)
127+ + ` -ls ` : log periodicity during training (print dashboard on log each ` ss `
128+ steps)
129+ + ` -m ` : monitoring level on TensorBoard, either 0 (no monitoring), 1 (monitor main scalar tensor),
130+ 2 (monitor all scalar tensors), or 3 (full-monitoring, including histograms and images, mainly
131+ for a debugging purpose)
132+ + ` -ns ` : neural network size for feature detection problem, either ` small ` (default value), or
133+ ` medium ` , the former being composed of 3 convolution+pooling operation and 1 fully-connected
134+ layer, whilst the latter is composed of 6 convolution+pooling operation plus 2 fully-connected
135+ layers.
95136+ ` -r ` : decaying learning rate components; can be one floating number (constant
96137 learning rate) or three ones (starting learning rate, decay steps and decay
97138 rate) if learning rate has to decay during training process
98- + ` -ss ` : log periodicity during training (print dashboard on log each ` ss `
99- steps)
139+ + ` -ss ` : back-up periodicity during training (back-up the TensorFlow model into a ` checkpoints `
140+ sub-directory each ` ss ` steps)
100141+ ` -t ` : training limit, measured as a number of iteration; overload the epoch
101142 number if specified
143+ + ` -vs ` : validation periodicity during training (run the validation phase on the whole validation
144+ dataset each ` ss ` steps)
145+
146+ ## Model testing
147+
148+ Trained models may be tested after the training process. Once a model is trained, a checkpoint
149+ structure is recorded in ` <datapath>/<dataset>/checkpoints/<network-name> ` . It is the key for
150+ inference, as the model state after training is stored into it.
151+
152+ The model testing is done as follows:
153+
154+ ```
155+ python3 test.py -dp ../data -d mapillary -n mapcnn_256_small -i 1000 -b 100 -ls 100
156+ ```
157+
158+ + ` -b ` : testing image batch size (default to 20)
159+ + ` -d ` : dataset (either ` mapillary ` or ` shapes ` )
160+ + ` -dp ` : data path in which the data are stored onto the computer (the dataset content is located
161+ at ` <datapath>/<dataset> ` )
162+ + ` -i ` : number of testing images (default to 5000, according to the Mapillary dataset)
163+ + ` -ls ` : log periodicity during training (print dashboard on log each ` ss `
164+ steps)
165+ + ` -n ` : instance name, under the format ` <netname>_<imsize>_<netsize> ` , that allows to recover the
166+ model trained with the network name ` <netname> ` , image size of ` <imsize>*<imsize> ` pixels and a
167+ neural network of size ` <netsize> ` (either ` small ` or ` medium ` ).
102168
103169# TensorBoard
104170
@@ -108,17 +174,23 @@ corresponding [Github project](https://github.com/tensorflow/tensorboard) or
108174the
109175[ TensorFlow documentation] ( https://www.tensorflow.org/get_started/summaries_and_tensorboard ) .
110176
111- The network graph is created under ` <datapath>/graph/<network-name> ` (* e.g.*
112- ` ../data/mapcnn ` ).
177+ The network graph is created under ` <datapath>/<dataset>/ graph/<network-name> ` (* e.g.*
178+ ` ../data/mapillary/graph/ mapcnn ` ).
113179
114180To check the training process, a simple command must be done on your command prompt:
115181
116182```
117- tensorboard --logdir <datapath>/graph/<network-name> --port 6006
183+ tensorboard --port 6006 --logdir= <datapath>/<dataset>/ graph/<network-name>
118184```
119185
120- Be careful, if the path given to ` --logdir ` argument do not correspond to those
121- created within the training, the Tensorboard dashboard won't show anything.
186+ Be careful, if the path given to ` --logdir ` argument do not correspond to those created within the
187+ training, the Tensorboard dashboard won't show anything. As a remark, several run can be showed at
188+ the same time; in such a case, ` --logdir ` argument is composed of several path separated by commas,
189+ and graph instances may be named as follows:
190+
191+ ```
192+ tensorboard --port 6006 --logdir=n1:<datapath>/<dataset>/graph/<network-name-1>,n2:<datapath>/<dataset>/graph/<network-name-2>
193+ ```
122194
123195An example of visualization for scalar variables (* e.g.* loss, learning rate,
124196true positives...) is provided in the following figure:
@@ -127,4 +199,4 @@ true positives...) is provided in the following figure:
127199
128200___
129201
130- Oslandia, December 2017
202+ Oslandia, March 2018
0 commit comments