This tutorial will show you how to get the popular pix2pix-tensorflow repository up and running on Spell. We'll take you through the pix2pix intro tutorial which shows you how to train a neural net to generate images of building facades based on a colorblock input image.
The first step is to clone the pix2pix repo onto your local workspace and
cd into the repository.
$ git clone https://github.com/affinelayer/pix2pix-tensorflow.git $ cd pix2pix-tensorflow
Download the CMP Facades Dataset onto Spell
The tutorial requires the CMP Facades dataset. Rather than downloading it onto our local computer and then upload to Spell, we'll download it directly onto Spell and mount it to our future runs.
Make a note of the
run id for the run downloading your dataset. The id for the below run is
$ spell run "python tools/download-dataset.py facades" Everything up-to-date 💫 Casting spell #2717… ✨ Stop viewing logs with ^C ✨ Machine_Requested… done ✨ Building… done ✨ Run is running downloading https://people.eecs.berkeley.edu/~tinghuiz/projects/pix2pix/datasets/facades.tar.gz extracting done ✨ Saving… done ✨ Pushing… done 🎉 Total run time: 45.302121s 🎉 Run 2717 complete
We can check our downloaded folder by running
spell ls and view the folders that were downloaded. Here, we see in our
runs/2717 folder a folder named
facades was downloaded.
$ spell ls runs/2717 - - facades
Train the pix2pix Model
Next, we'll train the model on the dataset we downloaded. To do so, we'll need to mount the dataset we downloaded in the previous step.
To mount the file, we'll use the
-m parameter in our
spell run command. This will mount all the files that were output by our run
2717 into a folder named
dataset in the root (top level) directory of our new run.
Then we just need to tell the pix2pix Python script where our
Finally, we'll also want to indicate what machine we want to run on. We'll use a K80, which is a pretty fast and affordable GPU option. We can tell Spell what machine to use using the
-t argument. To see a full list of machine types, check out our pricing page.
spell run -m runs/2717:dataset \ -t K80 \ "python pix2pix.py \ --mode train \ --output_dir \ facades_train \ --max_epochs 200 \ --input_dir dataset/facades/train \ --which_direction BtoA" ✨ Run created -- waiting for a K80 machine. ✨ Run is building . . . Dec 26 14:01:30: running: gen_loss_L1 0.18661024 Dec 26 14:01:33: running: recording summary Dec 26 14:01:33: running: progress epoch 200 step 399 image/sec 20.6 remaining 0m Dec 26 14:01:33: running: discrim_loss 0.6338811 Dec 26 14:01:33: running: gen_loss_GAN 3.132745 Dec 26 14:01:33: running: gen_loss_L1 0.18652529 Dec 26 14:01:33: running: saving model ✨ Run is saving Dec 26 14:01:39: saving: Retrieving modified or new files from the run Dec 26 14:01:46: saving: Saving 'facades_train' Dec 26 14:02:29: saving: Compressing saved files ✨ Run is pushing Dec 26 14:03:19: pushing: Saving build environment for future runs ✨ Total run time: 1h6m52.457456s ✨ Run 2720 complete
Once again, we can see the outputs of our run using the
spell ls command.
$ spell ls runs/2720 - - facades_train
Test the Model
Once our model has finished training (about 4 hours on a K80 and 1 hour on a V100), we can test the model.
We need to mount the output of our training run as well as our downloaded dataset into our new run. We'll mount the output of our training run (
2720) into our new run in a directory called
model. We'll use the same mount command from our previous run to mount our dataset.
Since this step doesn't require a powerful GPU, we can leave out the machine type argument and run our command on the default CPU.
$ spell run -m runs/2720:model \ -m runs/2717:dataset \ "python pix2pix.py \ --mode test \ --output_dir facades_test \ --input_dir dataset/facades/val \ --checkpoint model/facades_train" Everything up-to-date 💫 Casting spell #2723… ✨ Stop viewing logs with ^C ✨ Machine_Requested… done ✨ Building… done ✨ Mounting… done ✨ Run is running . . . evaluated image 98 evaluated image 99 evaluated image 100 wrote index at facades_test/index.html rate 0.6639545273780822 ✨ Saving… done ✨ Pushing… done 🎉 Total run time: 2m12.272398s 🎉 Run 2723 complete
View Output of Test Run
To view the output of our test run, we can copy the directory output by our run to our local computer using the
spell cp command.
$ spell cp runs/2723
The pix2pix script automatically creates an
html file so you can view the results of your test run on a local site.
$ open facades_test/index.html
Congratulations! You trained your neural net to generate new images of building facades based on a color block input image.