Thursday, September 17, 2015

Theano + Lasagne on Azure Machine Learning

This is a note on how I set up Theano + Lasagne on Azure Machine Learning

1. Install Anaconda Python

2. From your windows command prompt:
mkdir "C:\temp\Script Bundle\Python27\site-packages"
cd C:\temp\Script Bundle
git clone git:// theano_src
git clone lasagne_src
set PYTHONUSERBASE=c:\temp\Script Bundle
cd C:\temp\Script Bundle\theano_src
pip install -e . --no-deps --user
cd C:\temp\Script Bundle\lasagne_src
pip install -e . --no-deps --user

3. Edit C:\temp\Script Bundle\theano_src\Theano.egg-info\requires.txt
Change the requirement line for six to read:

4. Zip up the contents of C:\temp\Script Bundle
Upload it to Azure ML as a new dataset

5. Create a new Azure ML Experiment
Include your uploaded zip dataset
Include a "Execute Python Script" module

6. In your "Execute Python Script" module, include the following as a header:
import os
import os.path
import pkg_resources
import sys
SCRIPT_DIR = os.path.join(os.getcwd(), 'Script Bundle')
SITE_DIR = os.path.join(SCRIPT_DIR, 'Python27', 'site-packages')
siteEnv = pkg_resources.Environment([SITE_DIR])
packages, pkgErrors = pkg_resources.working_set.find_plugins(siteEnv)
for pkg in packages:
    print "Loading", pkg
    pkg_resources.working_set.add(pkg) # add plugins+libs to sys.path
if pkgErrors:
    print "Couldn't load", pkgErrors # display errors
# Set Theano variable to disable warning messages
os.environ['THEANO_FLAGS'] = 'cxx='
os.environ['OMP_NUM_THREADS'] = '4'