Saturday, April 1, 2017

Self-driving Car ND A2, traffic sign classifier

Recap: https://jychstar.blogspot.com/2017/02/scnd-11-finding-lane.html : course overview, environment setup and codes for project 1.

6 Intro to tensorflow

Obviously, deep learning ND does a much better job than its counterparts in Self-driving car ND. Because of its blending feature, self-driving car is slow to change.
At the end of this lesson comes a mini-project: TensorFlow-Lab. It is actually an improved version of https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/udacity/1_notmnist.ipynb
Something new is how to use yml to set up the environment.
$ conda env create -f CarND-Term1-Starter-Kit/environment.yml
$ conda env create -f CarND-TensorFlow-Lab/environment.yml
$ conda install --name CarND-TensorFlow-Lab -c conda-forge tensorflow
Alternatively, docker is a one-stop shopping tool.
docker version
docker run -d -p 80:80 --name webserver nginx
// go to http://localhost/

save TensorFlow Model

# training phase
file_name = 'model.ckpt'
saver = tf.train.Saver() # create an empty saver
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    # train steps
    saver.save(sess,file_name)  # save to local
    print('Trained Model Saved.')

# loading variables
# Remove the previous weights and bias
tf.reset_default_graph()
saver = tf.train.Saver()  # create an empty saver
with tf.Session() as sess:
    # no need to initialize
    saver.restore(sess,file_name) # restore from local
    print('Trained Model Loaded.')
    # use trained model
note that TensorFlow save the parameters node by node sequentially by default. If you change the node sequence, you get errors. To avoid this, use name=to name each node accordingly.

8 CNN

The famous LeNet comes as a practice at the end of the course. It’s 2 cnn layers + 3 dense layers.

9 Project 2: Traffic Sign Classifier

LeNet Architecture
AWS GPU instances (“udacity-carnd” AMI bd61c9dd, g2.2xlarge, seucrity group, proceed without a key pair).
ssh carnd@{public IP}, password: carnd
git clone https://github.com/udacity/CarND-LeNet-Lab.git
cd CarND-LeNet-Lab
source activate carnd-term1
jupyter notebook LeNet-Lab-Solution.ipynb
In this case, local cpu takes less than 10 minutes, still acceptable.

project

Train a model to classify traffic signs from the German Traffic Sign Dataset. This is a pickled dataset in which the images are resized to 32x32.
The project is not difficult. Some preprocessing to turn color image to grayscale and normalize the value, classifier used the pre-written LeNet, grab some images from web, resize and feed into the model. Detailed implementation.
Some suggestions from reviewer:
  1. use TensorFlow to convert RGB images to grayscale
  2. visualizing this architecture using TensorBoard
  3. Instead of a fixed number of epochs, one alternative is implementing early termination
  4. use the image augmentation technique to rebalance the number of examples for each class.Check out this article
  5. use plt.bar(x,y) to visualize softmax probability distribution.

2 comments:

Note: Only a member of this blog may post a comment.