Skip to content

Instantly share code, notes, and snippets.

@bakercp
Created June 14, 2018 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bakercp/ba1db00e25296357e5e3fef11ee147a0 to your computer and use it in GitHub Desktop.
Save bakercp/ba1db00e25296357e5e3fef11ee147a0 to your computer and use it in GitHub Desktop.
Getting Started w/ Pix2Pix

Getting Started with Pix2Pix

Prepare Your Development Environment

Download and Install Software

Docker

Docker is software that allows users to run Tensorflow and other complex software in pre-configured containers within your machine. It is somewhat like using a virtual machine (e.g. Paralells or VMWare on macOS) but purpose-built for the developer's application and lightweight. Ultimately the goals is to make it easier to use complex software packages on any machine without the headaches caused by version conflicts mis-configurations, etc.

Docker is a program that allows you to run guest containers on a host. The host machine is the actual hardware that is doing the work (e.g. a desktop, your laptop, or even a cloud server). These containers which are also referred to as Docker Images are often prepared by software developers and distributors with complex software. Instead of requiring the users to install all of the dependencies, the Docker Images "contain" all of the dependencies. Then when the user wants to run the distributor's complex software they can run it from within the pre-configured context of the Docker Image.

Installation

macOS

Follow these instructions.

Linux

For Linux machines with NVidia graphics cards, install Nvidia-Docker following these instructions.

Note: This is already installed on the machines in our classroom.

Your Data

  1. Create a directory for your project and your images. We'll call the first data set data_set_0.
$ mkdir -p MY_PROJECT/datasets/data_set_0/
  1. Place your A/B images in the MY_PROJECT/datasets/data_set_0/ folder.

Pix2Pix

Download a copy of pix2pix into the location of your choice.

$ cd MY_PROJECT/
$ git clone https://github.com/memo/pix2pix-tensorflow.git

Pix2Pix will now be in the MY_PROJECT/pix2pix-tensorflow directory.

Start Docker Image

macOS

To start the docker image:

$ cd MY_PROJECT/
$ docker run -it -p 0.0.0.0:6006:6006 -v $(pwd):/MY_PROJECT tensorflow/tensorflow:1.3.0 /bin/bash

Linux

$ cd MY_PROJECT/
$ nvidia-docker run -p 0.0.0.0:6006:6006 -it -v $(pwd):/MY_PROJECT tensorflow/tensorflow:1.3.0-gpu /bin/bash

You should now see a command line that looks something like (though the numbers will be different):

root@6e69f7496aba:/notebooks#

This command prompt is now connected to the guest container's file system. Any command you run here will be executed within the context of the guest container and it will have access to any software installed in the guest container (i.e. the tensorflow software in this case).

Note that we use nvidia-docker on Linux. Note that we also use the tensorflow/tensorflow:1.3.0-gpu container, whereas for macOS we did not use the -gpu variant because most macOS machines don't support NVidia GPUs.

By default docker limits the communication between host and guest systems. Thus ports, filesystems and other resources are isolated unless explicitly connected using the -p, '-v' and other parameters.

Thus, this configuration will map your current MY_PROJECT/ directory on the host filesystem (assuming the present working directory pwd is MY_PROJECT/) to the absolute path of /MY_PROJECT/ docker guest filesystem. filesystem. Note also that port mapping from the guest container's port 6006 to the host machine's port 6006. This port opening will allow us to view the tensorboard webpage and keep up on our progress.

Start Pix2Pix and Tensorboard.

While working in your Docker Image you will only have access to the MY_PROJECT/ directory and its subdirectories.

Once inside inside the guest system, run:

$ cd /MY_PROJECT/

This directory and all of its sub-directories are shared between the host and guest systems according to the mapping used when starting docker or nvidia-docker.

Now start tensorboard:

$ mkdir -p /MY_PROJECT/results/AtoB/data_set_0
$ tensorboard --port=6006 --logdir=/MY_PROJECT/results/AtoB/data_set_0 &

(Press return a few times to bring back the command prompt).

Now start pix2pix:

$ cd /MY_PROJECT/pix2pix-tensorflow/
$ python pix2pix.py --mode train \
         --input_dir /MY_PROJECT/datasets/ \
         --dataset data_set_0 \
         --output_dir /MY_PROJECT/results/AtoB \
         --which_direction AtoB

Note that if you want to use a different dataset name or go from BtoA, you will need to modify the steps to make both the tensorboard startup command and the pix2pix startup commands point to the correct directories.

Once you are finished training, press ctrl+C and type exit to exit the guest.

Now back on a browser in your host machine you can keep up with the progress at http://127.0.0.1:6006.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment