Building a Battleships AI

Monte-Carlo Simulation & Probability

Using Monte-Carlo simulation to build an AI for battleships

Deep Dream is a ‘technology’ originally developed by Google, which provides a very interesting insight into how deep CNNs (Convolutional Neural Networks) operate. Normally, for example, a CNN might be used for image categorisation. It takes in image as an input, performs some very mysterious black box process in a series of layers, and outputs a category for the image, say Dog. We only have a vague high level understanding of just how the black box process works, which is that each layer builds up greater and greater levels of abstraction. For example the first layers will be looking at lines and curves, the next at combinations of lines and curves, the next is perhaps looking for an eye or a leg (a combination of combinations of lines and curves) and the next, final layer, is looking for combinations of eyes and legs which might make up a dog. All of this is learned through backpropogation, which is a mathematical process designed to optimise a neural network. It’s composed of essentially a lot of linear algebra and calculus. However the way it optimises at a low level is very subtle and tough to reason about.

So, how does Deep Dream provide us with insight into this black box process? Well, rather than training a network to classify images, we take a network that has already been trained on such a task. Then, rather than optimising it to classify images, we optimise some layer in the middle and reapply the gradients (calculus term for rate of change of part of the network with respect to what we are optimising) to the input image. So, say the layer we are looking at happened to be a layer that would light up when an eye is in the input image, now it will respond to things that resemble an eye as before, but it will also emphasise anything in the image that vaguely resembles an eye, making it look more like an eye. This results in incredibly trippy modifications to input images, hence the name ‘dream’. For example:

You can see the input on top and the output below, the Deep Dreamed image shows what looks like dogs that it has ‘detected’ or ‘perceived’ in the image which aren’t really there, which it has emphasised

Now, this looks fantastic, but again, how does this help us understand the inner-workings of a neural network? Well, we can now get a visual representation of roughly what each layer is looking for in an image, which helps us build up a picture of how the network goes from an input image to a classification. This helps us to think of the network as less of a black box and more of a highly abstract set of layers which each perform a specific function.

But we can also have some fun with Deep Dream, as it creates some beautiful images! So, what happens if we feed a Deep Dream system an image of random noise?

You can see the input on top and a series of 3 outputs below. It takes the noise and adds a variety of interesting structures onto it.

It ‘sees’ things that aren’t there. This is also interesting in relation to our own consciousness. With our own sense data, we are often very likely to perceive patterns that aren’t there, most commonly this happens with faces. But people who enter, for example, sensory deprivation tanks often report hallucinations. Given nothing to see, our eyes/brains desperately try to find something to process, and so we end up with hallucinations. Although not exactly analogous, the parallel between the structure of an artificial neural network and our brains makes this an interesting comparison. Essentially we see that in both humans and artificial neural networks, patterns are perceived that simply aren’t there.

Next, we can try feeding it random noise, zooming into the centre of the image, and feeding the image back through the system again. Repeating this over and over again gives us the featured gif for this page. However that was just a low quality snapshot, here is the full video of the Deep Dream zoom:

Video Player

00:00 00:54

You will notice that as the video progresses, more and more complex things are emphasised. At the start it emphasises only lines and small shapes, but eventually it emphasises eyes, animals, snakes, scales etc. This is because as the video progresses, we move deeper and deeper into the network, so it emphasises more and more abstract concepts instead of lines and shapes.

This was a very interesting experiment in how deep neural networks operate, and it also provides some interesting parallels into our own mind too. It has been a very good learning tool for me and has improved my intuition surrounding deep learning, I hope you have gained some insight into the nature of neural networks from it as well!

Projects

Scraping prnt.sc

Web Scraping & Machine learning

A scraper designed to crawl through the image sharing site prnt.sc, using a CNN to classify images and OCR to extract text.

Read Me

YouTube & MBTI

YouTube & MBTI

Producing, publishing and analysing YouTube & MBTI Datasets on Kaggle

Read Me

Building a Battleships AI

Monte-Carlo Simulation & Probability

Using Monte-Carlo simulation to build an AI for battleships

Read Me

Building a Battleships AI

Monte-Carlo Simulation & Probability

Using Monte-Carlo simulation to build an AI for battleships

Read Me