Setting up the environment

When you have connected to the instance, you can install the updated Lasagne and nolearn packages.

First, clone the git repository for Lasagne, as was outlined earlier in this chapter:

git clone https://github.com/Lasagne/Lasagne.git

In order to build this library on this machine, we will need setuptools for Python 3, which we can install via apt-get, which is Ubuntu's method of installing applications and libraries; we also need the development library for NumPy. Run the following in the command line of the virtual machine:

sudo apt-get install python3-pip python3-numpy-dev

Next, we install Lasagne. First, we change to the source code directory and then run setup.py to build and install it:

cd Lasagne
sudo python3 setup.py install

Note

We have installed Lasagne and will install nolearn as system-wide packages for simplicity. For those wanting a more portable solution, I recommend using virtualenv to install these packages. It will allow you to use different python and library versions on the same computer, and make moving the code to a new computer much easier. For more information, see http://docs.python-guide.org/en/latest/dev/virtualenvs/.

After Lasagne is built, we can now install nolearn. Change to the home directory and follow the same procedure, except for the nolearn package:

cd ~/
git clone https://github.com/dnouri/nolearn.git
cd nolearn
sudo python3 setup.py install

Our system is nearly set up. We need to install scikit-learn and scikit-image, as well as matplotlib. We can do all of this using pip3. As a dependency on these, we need the scipy and matplotlib packages as well, which aren't currently installed on this machine. I recommend using scipy and matplotlib from apt-get rather than pip3, as it can be painful in some cases to install it using pip3:

sudo apt-get install python3-scipy python3-matplotlib
sudo pip3 install scikit-learn scikit-image

Next, we need to get our code onto the machine. There are many ways to get this file onto your computer, but one of the easiest is to just copy-and-paste the contents.

To start with, open the IPython Notebook we used before (on your computer, not on the Amazon Virtual Machine). On the Notebook itself is a menu. Click on File and then Download as. Select Python and save it to your computer. This procedure downloads the code in the IPython Notebook as a python script that you can run from the command line.

Open this file (on some systems, you may need to right-click and open with a text editor). Select all of the contents and copy them to your clipboard.

On the Amazon Virtual Machine, move to the home directory and open nano with a new filename:

cd ~/
nano chapter11script.py

The nano program will open, which is a command-line text editor.

With this program open, paste the contents of your clipboard into this file. On some systems, you may need to use a file option of the ssh program, rather than pressing Ctrl + V to paste.

In nano, press Ctrl + O to save the file on the disk and then Ctrl + X to exit the program.

You'll also need the font file. The easiest way to do this is to download it again from the original location. To do this, enter the following:

wget http://openfontlibrary.org/assets/downloads/bretan/680bc56bbeeca95353ede363a3744fdf/bretan.zip
sudo apt-get install unzip
unzip -p bretan.zip Coval.otf > Coval.otf

This will unzip only one Coval.otf file (there are lots of files in this zip folder that we don't need).

While still in the virtual machine, you can run the program with the following command:

python3 chapter11script.py

The program will run through as it would in the IPython Notebook and the results will print to the command line.

The results should be the same as before, but the actual training and testing of the neural network will be much faster. Note that it won't be that much faster in the other aspects of the program—we didn't write the CAPTCHA dataset creation to use a GPU, so we will not obtain a speedup there.

Note

You may wish to shut down the Amazon virtual machine to save some money; we will be using it at the end of this chapter to run our main experiment, but will be developing the code on your main computer first.

Setting up the environment
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset