Lab 8: Convolutional Neural Networks
Due April 10 by midnight

convolutional neural network

Starting point code

Use Teammaker to form your team. You can log in to that site to indicate your partner preference. Once you and your partner have specified each other, a GitHub repository will be created for your team.

Introduction

In this lab you will be using Keras to explore convolutional neural networks. You will start by experimenting with an already constructed convNet to learn the MNIST dataset. Once you understand how to use Keras to construct, train, and test a convNet, you will create your own convNet to work with the game Hex that we explored in lab4.

Relative to all of the previous labs in this class, most of the design of the lab is left up to you. This is intended to prepare you for your upcoming AI project. You will likely be using some type of publicly available software, like Keras, to complete you project. You should get used to consulting the documentation when you have questions. I am also willing to help, of course.

Using Keras

Before using Keras, you need to activate a virtual environment that contains all of the software packages that you'll need:

source /usr/swat/bin/CS63env
To leave the virtual environment, just type:
deactivate

When running Keras, it will first try to discover whether the computer you are running on contains a GPU device. The machines in the Clothier lab do not have GPUs. So when running Keras in Clothier you should preface the invocation of python like this:

CUDA_VISIBLE_DEVICES="" python3 filename
Keras will run more quickly on computers that do have GPUs. Here is a dashboard of the CS machines with the best GPUs. When doing longer experiments you can ssh into one of these machines to get quicker results.

MNIST

Open up the file mnist_conv_net.py and read through the code. Using a Keras network will typically require the steps listed below. Try to identify how each of these steps is being handled for learning the MNIST dataset.

  1. Prepare the data
    This may include loading, reshaping, normalizing, and dividing the data into separate training and testing sets.
  2. Construct the model
    We will be using Sequential() models. Add the layers in order from input to output.
  3. Compile the model
    Specify the optimizer, loss, and metric that will be used.
  4. Train the model
    Determine the number of epochs to complete.
  5. Test the model
    After training is complete, analyze the results.

Typically the network's performance will not be as successful as you expected. To improve the performance you will need to iterate over these steps multiple times. In some cases, you may need to pre-process the data in some way to simplify the problem. Or you may need to tweak the model architecture, by adding more layers, or changing the parameters within existing layers. If your inputs are in the range [-1,1] rather than [0, 1], you may need to use a different activation function, like tanh. You might get better results with a different optimizer or loss function. If loss is still dropping, you may just need to train the model for more epochs.

Try to improve the performance on the MNIST data set.

Applying Neural Networks to Hex

The file hex_data.npz contains data from a very good hex player, developed using Monte Carlo Tree Search, that contains information for over 47,000 unique game states. The program hex_conv_net.py reads in this compressed data file and creates the following arrays of data:

The program gives you a starting point for setting up the data and a Keras neural network. You get to decide how to design and train your neural network (subject to using at least one convolutional layer), and you even get to decide what function you are trying to learn. You should use a board state as your input data (transformations of board states are allowed), but you have several options for what to predict:

Before you begin constructing your Hex neural network, please discuss your plan with me. Think carefully about how you will split the data, and how you will represent the output.

Writeup

In the file writeup.tex, you should describe the problem you have solved, the neural network you built and the experiments you ran. As you work, you should keep track of what network architectures and parameters you have tried and how well they have worked at various learning problems.

You can edit the writeup.tex file with any text editor. There's lots of great help available online for latex; just google "latex topic" to find lots of tutorials. To compile your latex document into a pdf, run the following command:

pdflatex writeup.tex
You can then open the pdf from the command line with the command evince. Feel free to use services like sharelatex to edit your latex file.

Submitting

You should use git to add, commit, and push any files that you modify.