← Back to AI Site

Tensorflow Notes

Tensorflow Title
The First Tensorflow Neural Network

The code used in this note is u2bTensorflowTutor.py
GitHub repository: https://github.com/linzexinmasterchief/TensorflowLearn

This code is currently able to train and save the tensorflow models. The critical variables to be saved are "x" and "sess". x indicates the input matrix ["none", 784] (the pictures are 28 x 28 pixels large, therefore 784 pixels are used. The idea of the input layer is that the pictures are "flattened" from a two dimension matrix to a one dimension matrix. Although this operation destroyed the 2D construct of the picture, it made the picture data easier for tensorflow network to process. By the way, the parameter "none" means "any number", which means the matrix could contain any amount of images).

I've made a lot of comments in the code in order for you to understand.

Using Tensorboard to Visualize the Model
Tensors Flowing Tensorflow Graphs

Put this in your code after the session sess is defined:

writer = tf.summary.FileWriter('./graphs', sess.graph)
writer.close()

Use this command in the terminal to start the tensorboard at 127.0.0.1:6006

tensorboard --logdir="./graphs"
The Use of CNN (Convolutional Neural Network)

The use of CNN provide artificial intelligences the ability to identify structured data matrix such as pictures. In the previous approaches, our AI could only first flatten the 2D picture into a 1D array, then find the patterns of 0 and 1s. However, that approach obviously destroyed some critical informations, for example: the relative postion of each object, the relationship between different parts of the picture... Therefore, we need a new model, which is CNN.

The theory of CNN itself is pretty simple and straight forward: it is like using a magnifier to scan a map, but in the opposite way. The program will first use the smallest square: 5x5 for example, small details like curves, vertical lines, and horizontal lines. The small square will move a little at a time (1 step could be 1px, 2px etc), the scanner square itself is also a matrix which contains the special pattern it want to detect, in each step, the matrix is the square will be doing a dot product with the square scanned by the square: this is called a convolution.

Visualize CNN

scs.ryerson.ca/~aharley/vis/conv/ visualized this process.

Kaggle Digit Recognization Project

The finished version of kaggle recognization project source code should be able to run on any machine with tensorflow installed, both cpu and gpu version should work as predicted.

The basic theory of the project is just as simple as a normal CNN we learned in ECA.

The kaggle page of this project just in case anyone is interested.

Kaggle Score