In this project, the goal of the vehicle's perception system is to identify drivable space. To achieve this, the pixels of the road surface in images are labeled into two classes: road and non-road. The labeling is performed by using a Fully Convolutional Network (FCN), that is based on the solution described in the paper Fully Convolutional Networks for Semantic Segmentation.
The following figure shows architecture of the DNN for the fully convolutional network as shown in the original paper.

The FCN is based on encoder-decoder architecture. The encoder part of the FCN is based on a VGG-16 classification network architecture. We obtained a pre-trained version of this network with fully-connected layers replaced by 1x1 convolution as input to this project. The proper implemention of the decoder part of the FCN architecture is the main task of this project. In order to impelement the encoder the following layers are used as a source for skip connections:
layer 3layer 4layer 7
The encoder also implements several upsampling layers implemented through deconvolutional layers:
upsample_2Xupsample_4Xupsample_32X
In the project, the upsampling layers have been setup with a kernel initializer and a kernel L-2 regularizer. However, throughout work, I did not find L2-regularization useful, so it is not used in the loss function as suggested in the project review points. I also did not scale 1x1 convolutions coming from layer 3, 4, and 7 of the VGG encoder as was mentioned on the project review task list.
The actual selection of the hyperparameters was done manually by training a number of times and observing the the loss on the training set. The following tables shows the final parameters chosen for submission.
| Parameter | Value |
|---|---|
| Learning rate | 0.00001 |
| Number of epochs | 50 |
| Batch size | 8 |
| Kernal intialization standard deviation | 0.01 |
| L2-regularization of convolution kernels | 0.001 |
| "Keep probability" value | 0.5 |
The implemented fully convolutional network classifies the road surface well visually. The following imagery shows visualization of classified road surfaces from images of the test set of Kitti:
In order to have persistent results the trained model is always saved in runs/ directory.
In this project, you'll label the pixels of a road in images using a Fully Convolutional Network (FCN).
main.py will check to make sure you are using GPU - if you don't have a GPU on your system, you can use AWS or another cloud computing platform.
Make sure you have the following is installed:
You may also need Python Image Library (PIL) for SciPy's imresize function.
Download the Kitti Road dataset from here. Extract the dataset in the data folder. This will create the folder data_road with all the training a test images.
Implement the code in the main.py module indicated by the "TODO" comments.
The comments indicated with "OPTIONAL" tag are not required to complete.
Run the following command to run the project:
python main.py
Note: If running this in Jupyter Notebook system messages, such as those regarding test status, may appear in the terminal rather than the notebook.
Here are examples of a sufficient vs. insufficient output from a trained network:
| Sufficient Result | Insufficient Result |
|---|---|
![]() |
![]() |
- Ensure you've passed all the unit tests.
- Ensure you pass all points on the rubric.
- Submit the following in a zip file.
helper.pymain.pyproject_tests.py- Newest inference images from
runsfolder (all images from the most recent run)
- The link for the frozen
VGG16model is hardcoded intohelper.py. The model can be found here. - The model is not vanilla
VGG16, but a fully convolutional version, which already contains the 1x1 convolutions to replace the fully connected layers. Please see this post for more information. A summary of additional points, follow. - The original FCN-8s was trained in stages. The authors later uploaded a version that was trained all at once to their GitHub repo. The version in the GitHub repo has one important difference: The outputs of pooling layers 3 and 4 are scaled before they are fed into the 1x1 convolutions. As a result, some students have found that the model learns much better with the scaling layers included. The model may not converge substantially faster, but may reach a higher IoU and accuracy.
- When adding l2-regularization, setting a regularizer in the arguments of the
tf.layersis not enough. Regularization loss terms must be manually added to your loss function. otherwise regularization is not implemented.
In main.py, you'll notice that layers 3, 4 and 7 of VGG16 are utilized in creating skip layers for a fully convolutional network. The reasons for this are contained in the paper Fully Convolutional Networks for Semantic Segmentation.
In section 4.3, and further under header "Skip Architectures for Segmentation" and Figure 3, they note these provided for 8x, 16x and 32x upsampling, respectively. Using each of these in their FCN-8s was the most effective architecture they found.
Within main.py, there are a few optional sections you can also choose to implement, but are not required for the project.
- Train and perform inference on the Cityscapes Dataset. Note that the
project_tests.pyis not currently set up to also unit test for this alternate dataset, andhelper.pywill also need alterations, along with changingnum_classesandinput_shapeinmain.py. Cityscapes is a much more extensive dataset, with segmentation of 30 different classes (compared to road vs. not road on KITTI) on either 5,000 finely annotated images or 20,000 coarsely annotated images. - Add image augmentation. You can use some of the augmentation techniques you may have used on Traffic Sign Classification or Behavioral Cloning, or look into additional methods for more robust training!
- Apply the trained model to a video. This project only involves performing inference on a set of test images, but you can also try to utilize it on a full video.
If you are unfamiliar with GitHub , Udacity has a brief GitHub tutorial to get you started. Udacity also provides a more detailed free course on git and GitHub.
To learn about REAMDE files and Markdown, Udacity provides a free course on READMEs, as well.
GitHub also provides a tutorial about creating Markdown files.






