In this notebook, we’ll recreate a style transfer method that is outlined in the paper, Image Style Transfer Using Convolutional Neural Networks, by Gatys in PyTorch.
In this paper, style transfer uses the features found in the 19-layer VGG Network, which is comprised of a series of convolutional and pooling layers, and a few fully-connected layers. In the image below, the convolutional layers are named by stack and their order in the stack. Conv_1_1 is the first convolutional layer that an image is passed through, in the first stack. Conv_2_1 is the first convolutional layer in the second stack. The deepest convolutional layer in the network is conv_5_4.
Per the Anaconda docs:
Conda is an open source package management system and environment management system for installing multiple versions of software packages and their dependencies and switching easily between them. It works on Linux, OS X and Windows, and was created for Python programs but can package and distribute any software.
Using Anaconda consists of the following:
- Install
miniconda
on your computer, by selecting the latest Python version for your operating system. If you already haveconda
orminiconda
installed, you should be able to skip this step and move on to step 2. - Create and activate * a new
conda
environment.
* Each time you wish to work on any exercises, activate your conda
environment!
Download the latest version of miniconda
that matches your system.
Linux | Mac | Windows | |
---|---|---|---|
64-bit | 64-bit (bash installer) | 64-bit (bash installer) | 64-bit (exe installer) |
32-bit | 32-bit (bash installer) | 32-bit (exe installer) |
Install miniconda on your machine. Detailed instructions:
- Linux: http://conda.pydata.org/docs/install/quick.html#linux-miniconda-install
- Mac: http://conda.pydata.org/docs/install/quick.html#os-x-miniconda-install
- Windows: http://conda.pydata.org/docs/install/quick.html#windows-miniconda-install
For Windows users, these following commands need to be executed from the Anaconda prompt as opposed to a Windows terminal window. For Mac, a normal terminal window will work.
- Clone the repository, and navigate to the downloaded folder. This may take a minute or two to clone due to the included image data.
git clone https://github.com/wolfapple/style-transfer.git
cd style-transfer
- Create (and activate) a new environment, named
style-transfer
. Running this command will create a newconda
environment that is provisioned with all libraries you need to be successful in this program.
- Linux or Mac:
conda env create -f environment.yaml
source activate style-transfer
- Windows:
conda env create -f environment.yaml
activate style-transfer
At this point your command line should look something like: (style-transfer) <User>:style-transfer <user>$
. The (style-transfer)
indicates that your environment has been activated, and you can proceed with further package installations.
- Verify that the environment was created in your environments:
conda info --envs
- Cleanup downloaded libraries (remove tarballs, zip files, etc):
conda clean -tp
- That's it!
Now most of the libraries are available to you. Very occasionally, you will see a repository with an addition requirements file, which exists should you want to use TensorFlow and Keras, for example. In this case, you're encouraged to install another library to your existing environment, or create a new environment for a specific project.
To exit the environment when you have completed your work session, simply close the terminal window.
To uninstall the environment:
conda env remove -n style-transfer