## Neural Networks - Our Journey in Making Computers Smart
Artificial Intelligence, Machine Learning, Deep Learning have been the biggest tech buzzwords for the past few years. With our computers getting faster and more efficient, it is only obvious that we would try to achieve the sci-fi dream of having a humanoid robot. While we are still quite a few years away from realizing that dream, Machine Learning has still achieved wonders today.
Such an exciting field piqued our interest and we began working on a project to achieve style transfer using Neural Networks.
## Kickstart the Learning!
The first step was very obvious for us - learn as much as you can.
And our mentors had abundant resources prepared for us. Primarily we followed the Deep Learning Specialization taught by the ML Messiah - Andrew NG.
Initially it was overwhelming, because we had to finish a major portion of the specialization to just understand and start working on our actual project + the time constraint.
The course however provided a smooth learning experience, the best part of the course was its the assignments!
Our initial goals was just to understand the different aspects of neural networks and learn to build them from scratch.
This is where the assignments 10x'ed our learning.
We struggled with our initial assignments and
remember this meme on neural networks?
We built one in our 1st week and it actually is gonna take over the world!
<div>
<img src="https://i.imgur.com/s77ngS5.png" width="300" height="300" >
<img src="https://i.imgur.com/4gN3jND.png" width="400" height="300" >
</div>
<br>
## Shapes (10,7) and (4,7) not aligned
*Forward prop is just Matrix multiplication.*
It shouldn't be that hard right?
When you start out writing you own neural nets, you'll most likely run into one of these ValueErrors -
<img src="https://i.imgur.com/hkP0FQC.png" height="300" >
its so common because, its hard to keep track of the dimensions of your weight matrix for each layer, and you cannot multiply incorrect dimensions.
though it took alot of time to backtrack and resolve these errors, it made every step much more clear.
## Hello World program of Neural Networks
When you start learning a programming language, the 1st thing you (must) do is print "Hello World!".
Similarly, when you start learning Neural Nets, the 1st network you write is the one to identify handwritten digits!
So after learning enough about neural networks we decided to write a hello world program but in neural nets language.
We made a generalized Neural net, where you can chose the size(no. of layers and the activations in each layer) and feed it any dataset!
For digit recognition we used the classical MNIST Handwritten digits.
MNIST is a dataset of 60,000 small square 28×28 pixel grayscale images of handwritten single digits between 0 and 9.
This particular excercise was a rather smooth sailing, all thanks to the wonderful assignments.
While training we did get annoyed by how long it took (~30 minutes). Little did we know, how much worse it would get from now on.
Upon training this model, we were able to achieve a train accuracy of 97% and a test accuracy of 95.5%.
We built this model just an excercise to see if we could build a Neural Network model from scratch using Numpy. It is however important to note the the general consensus right now is that the MNIST dataset is not a reliable way
to learn neural networks since it is very easy to train. Infact, a simple convolutional neural network can
achieve 99.7% accuracy. It also might paint an unrealistic picture of how simple the field of deep learning
can be.
## Put on the training wheels
Now that we knew we can build a Neural Network from scratch, we made the process much easier for ourselves using Tensorflow.
TensorFlow is a free and open-source software library for machine learning and artificial intelligence. It can be used across a range of tasks but has a particular focus on training and inference of deep neural networks.
We began by creating another MNIST model using Tensorflow.
The model which took hundreds of lines of code previously using Numpy, now took under 10 lines! It still feels like cheating. However, we couldn't have made our larger models from scratch since writing the code would have taken up too much time. So, Tensorflow was the way to go.
## Walking the Trodden Path
We were in need for an accurate model. We could have spent time tinkering with our own model but instead decided to work with some published models.
Some of the most notable architectures are:
1. LeNet
2. AlexNet
3. VGG Net
4. GoogLeNet
5. ResNEt
6. ZFNet
We mostly tried AlexNet and VGGNet since they fit our requirements.
Since AlexNet and VGGNet are very deep networks, we trained both of these models on the CIFAR-10 dataset to learn more about these architectures.
## Neural Style Transfer
Neural Style Transfer was always the goal of our project. However, this project was not as much about the goal as it was about the process.
Understanding Neural Style Transfer requires a deep understanding of how neural networks, escpecially how the detection works.
Experimenting with the input image shows that the outputs of certain layers changes depending upon what kind of feature is changed in the image.
The lower layer layers are the most affected by low level features such as lines and blobs. The higher layers are most affected by higher level features.
We can use this knowledge to implement Neural Style Transfer.
The style of any image is defined by the lower level features like lines, stroke, colors, etc. The content of any image is defined by the higher level features like face, body, etc.
We obviously require a trained neural network for this and we use VGG-19 for this purpose.
Using all we have learned uptill now, we used VGG-19 to extract style from style image and content content image and blend them together.
We start by passing both our input images seperately through the neural network. We can then find out the activations from the lower layer of the style image for our style and activations of the higher layer of the content image for our content.
We also pass a randomly generated image and compare the lower layer activations to the style activations and the higher layer activations to the content activations. We then change this image itself to reduce the loss function as much as possible.
In the end, we shall have an image that has the style of the style image and the content of the content image.
We implemented NST on tensorflow and keras.
## A step further
We completed our initial goal of implementing NST well before time. So, we started exploring ways to extend the scope of our project. We considered trying out other variations of neural style tansdfer itself. However, in the end we felt like learning about GANs(Generative Adversarial Networks) was the natural progression of our project.
Generative Adversarial Networks takes up a game-theoretic approach, unlike a conventional neural network.
The network learns to generate from a training distribution through a 2-player game. The two entities are
Generator and Discriminator. These two adversaries are in constant battle throughout the training process.
We have 2 Neural Networks in this case - A generator network and a discriminator network.
The Generator network creates an image and the discriminator network determined whether its a real image or a fake one genrated by the generator.
Whil training the generator gets better at making images that can fool the discriminator and the discriminator gets better at generating images that can accurately identify fake images. Thus, both the networks force each other to get better at their tasks.
## Faces never seen before
We first started by implementing GANs for face generation.
We neede a dataset of face images for which we used facemask_lite/withoutmask dataset which contained 9896 images.
GANs are very computationaly expensive. So, training this model on your laptops was nearly impossible as it would have taken weeks.
Luckily, we got access to our college's DGX server which accelerated our training time by a huge margin.
## CycleGANs
The final task we completed in our project was CycleGANs.
The Cycle Generative Adversarial Network, or CycleGAN, is an approach to training a deep convolutional neural network for image-to-image translation tasks. The Network learns mapping between input and output images using unpaired dataset.
This model architecture has 2 generator models. One generator generates output images and the other generator converts output image back to input image.
CycleGANs are essential for image to image translation when we dont have a paired image dataset.
We implemented CycleGAN for a horse to zebra style transfer.
This model converted any image of a horse to zebra.
This style transfer is relatively easy for the model to do since the shape of horses and zebras are similar. Only the stripes have to be added in.
We needed a dataset of images of zebras and horses. We used tensorflow dataset to import a dataset call cycle_gan/horse2zebra It has 2 classes of images - zebras and horses.