Skip to main content

Setting up GANs on Azure

Published onFeb 04, 2019
Setting up GANs on Azure

saved in another draft, then restored 2/23

Getting tensorflow biggan up and running

Create a VM on Azure

Create an Azure virtual machine:

Ubuntu 16.04, allow SSH port 22, NC24, location: East US 2.

Do NOT use the Microsoft special AI package image that already has tensorflow, etc. installed — it can’t be customized as easily.

As of 6pm Dec 8, you can SSH into our nice, GPU-laden machine with

ssh-add <gengroup key>
ssh [email protected]

# If the IP has changed since your last login, add the key again first

Install CUDA + CUDNN + conda

Instructions drawn from this guide to installing CUDA and CUDNN. I didn’t follow it exactly, I skipped almost all of the “samples to verify the installation”. I only tested it once at the end for time-efficiency. I also skipped all the reboots, and it worked just fine.

First install CUDA

sudo apt-get install nvidia-384 nvidia-modprobe
chmod +x cuda_9.0.176_384.81_linux-run
echo $HOME
./cuda_9.0.176_384.81_linux-run --extract=$HOME
sudo ./

You’ll have to click through the license. Accept the defaults, particularly making a symlink.

sudo bash -c "echo /usr/local/cuda/lib64/ > /etc/"
sudo ldconfig

Then add cuda to your code path:

sudo vim /etc/environment

and append :/usr/local/cuda/bin to the end of your PATH.

Next install CUDNN

From dali, download the .deb files for CUDNN. We can get them from these dropbox links:

wget -O  libcudnn7_7.4.1.5-1+cuda9.0_amd64.deb
wget -O  libcudnn7-dev_7.4.1.5-1+cuda9.0_amd64.deb
wget -O  libcudnn7-doc_7.4.1.5-1+cuda9.0_amd64.deb

Confirm they are the right size:

> ls -s *.deb
123500 libcudnn7_7.4.1.5-1+cuda9.0_amd64.deb
114316 libcudnn7-dev_7.4.1.5-1+cuda9.0_amd64.deb
  4856 libcudnn7-doc_7.4.1.5-1+cuda9.0_amd64.deb 

Then install them:

sudo dpkg -i libcudnn7_7.4.1.5-1+cuda9.0_amd64.deb 
sudo dpkg -i libcudnn7-dev_7.4.1.5-1+cuda9.0_amd64.deb 
sudo dpkg -i libcudnn7-doc_7.4.1.5-1+cuda9.0_amd64.deb

I ran this last verification because it was really fast:

cp -r /usr/src/cudnn_samples_v7/ ~
cd ~/cudnn_samples_v7/mnistCUDNN
make clean && make

Check for test passed! at the end of the output.

Now add this (vim ~/.bashrc) to the bottom of your .bashrc:

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/extras/CUPTI/lib64"

and finally run

source ~/.bashrc

Then install miniconda3

Get the source and install, and confirm it’s in place:

source ~/.bashrc

which conda

Run biggan with iPython

Now we’re ready to install what we need to run biggan:

conda create -n biggan python=2.7
source activate biggan
pip install tensorflow-gpu==1.12.0
pip install numpy
pip install scipy
pip install pillow
pip install tensorflow-hub 
conda install jupyter

Run Jupyter and load an iPython notebook

First connect to the server from your local client to the server IP:

ssh -N -f -L localhost:8888:localhost:8888 [email protected]

Then, from the azure server, run jupyter like so:

jupyter notebook --no-browser

This will return a URL you can browse to, to view your home directory in jupyter. (Doublecheck that it has port 8888 in it. If someone else is already running jupyter remotely in this way, it may return another port, such as 8889. Likewise make sure the IP is right; you may have to update the first ssh command above accordingly.)

Finally, this iPython notebook will load biggan. If it isn’t already in your directory on the server, download it there:

Now run it by clicking on the file in the directory view. The html file below shows you how it should look. Walk through the notebook, running each block of code in turn.


Working with MET data

Once this gets larger: perhaps split out into its own pub? Or will everyone referencing the above also be doing this?

Get MET metadata + images

Met images:

Use the file MetArtworksAugmented.csv to identify images to use. (A version from Dec. 1 is part of the blob hosted on the Azure filestore.

  • Find ObjectIDs for items with Object Name in {Print, Drawing, Painting} (column G)

  • Find any Tags (column AS)

  • The Primary Image URL (column AT) is a URL to a full-sized image.

There is also a MET API we should experiment with. (need contact form Loic)

Wikiart images:

  • Scraper tool:

May not need to if it suffices to specialize bigGAN with Met images.

But could just choose specific genres (or category combinations)


Transfer MET data into tensorflow

Using Azure blobs w/ python:

How to mount blobfuse on linux:

Create config file fuse_connection.cfg.

(Not working yet: we may need account info from MS).

Resize images to 512x512:

Done with a small shell script. Some small files were corrupted (error messages when the API rate-limited the request). Some larger ones also, for unknown reasons: 12634, 333937, 365872, 361642, 371743, 371744.

Use MET data to interact with biggan?

Training a small neural net on MET data

Testing: running progan on the MET images.

No comments here
Why not start the discussion?