├── README.md └── install_environment.sh /README.md: -------------------------------------------------------------------------------- 1 | > Warning: The underlying `texture_nets` repository isn't working. The training process is broken until further notice. Sorry for the inconvenience. 2 | 3 | > Second Warning: Don't forget to terminate your EC2 instance after you're done. You still get billed for the instance when you don't use it. 4 | 5 | # DeepFilter Training 6 | 7 | ![DeepFilter Example](https://s3.amazonaws.com/algorithmia-assets/github_repo/deepfilter-training/gan_vogh_example2.png) 8 | 9 | [DeepFilter](https://algorithmia.com/algorithms/deeplearning/DeepFilter) is a fun way to convert photos or images into the style of a masterpiece painting, drawing, etc. For instance, you could apply the artistic style of Van Gogh’s Starry Night to an otherwise boring photo of the Grand Canal in Venice, Italy. 10 | 11 | This is a guide to help you get started in training your own DeepFilters. 12 | 13 | ![AMI Creating Image](https://s3.amazonaws.com/algorithmia-assets/github_repo/deepfilter-training/ami_creation.png) 14 | 15 | ## 1. Training DeepFilter 16 | 17 | 1. First of, you'll need a valid AWS account so you can start off by creating an EC2 `P2.xlarge` instance with one of our AMI images (one image per region). `P2.xlarge` instances only exist in 3 regions: US-East-1 (Northern Virginia) `ami-b19aafa6`, US-West-2 (Oregon) `ami-5c2e823c` and EU-West-1 (Ireland) `ami-36461b45`. 18 | 19 | 2. SSH into your newly created server using the command: `ssh -i path/to/key.pem ubuntu@` 20 | 21 | 3. Git clone this repository by using the following command: `git clone https://github.com/algorithmiaio/deepfilter-training.git` 22 | 23 | 4. Run the following command: `. deepfilter-training/install_environment.sh` to setup the environment for DeepFilter training. (installing may take up to an hour or two) 24 | 25 | 5. Download a style image using the following command: `wget `. 26 | 27 | 6. Rename the style image file via: `mv style.jpg`. 28 | 29 | 7. Start training via the command: `th train.lua -data dataset -style_image style.jpg -style_size 480 -image_size 480 -model johnson -batch_size 4 -learning_rate 1e-2 -style_weight 10 -style_layers relu1_2,relu2_2,relu3_2,relu4_2 -content_layers relu4_2 -gpu 1` 30 | 31 | ![Iteration Example](https://s3.amazonaws.com/algorithmia-assets/github_repo/deepfilter-training/iteration_example.png) 32 | 33 | Training will continue until it hits 50k iterations (takes up to 24 hrs). You'll find all of your model files under the folder `data/checkpoints`. 34 | 35 | **Note:** You may play with the training settings to get different results. For more information regarding parameter optimization, please refer to: 36 | 37 | * [DmitryUlyanov/texture_nets - Documentation](https://github.com/DmitryUlyanov/texture_nets/blob/master/README.md) 38 | * [DmitryUlyanov/texture_nets - Issues regarding parameters](https://github.com/DmitryUlyanov/texture_nets/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20parameter). 39 | 40 | ## 2. Testing DeepFilter 41 | 42 | 1. Login to your algorithmia account with your API key via: `algo auth` 43 | 44 | 2. Create a new collection in your account to store your model file via: `algo mkdir .my/DeepFilterTraining` 45 | 46 | 3. Copy your 50k model file to new collection: `algo cp data/checkpoints/model_50000.t7 data://.my/DeepFilterTraining/my_model.t7` 47 | 48 | 4. Test your new model: `algo run deeplearning/DeepFilter/0.6.x -d '{"images": ["data://deeplearning/example_data/elon_musk.jpg"],"savePaths": ["data://.my/DeepFilterTraining/stylized.jpg"],"filterName": "data://.my/DeepFilterTraining/my_model.t7"}'` 49 | 50 | 5. View your stylized image [here](https://algorithmia.com/v1/data//DeepFilterTraining/stylized.jpg): (`https://algorithmia.com/v1/data//DeepFilterTraining/stylized.jpg`) (You need to be logged in, and need to change `` with your login name.) 51 | 52 | # Credits 53 | 54 | This guide is based on code provided by: [DmitryUlyanov/texture_nets](https://github.com/DmitryUlyanov/texture_nets). 55 | -------------------------------------------------------------------------------- /install_environment.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | checkAptGet () { 3 | while sudo fuser /var/lib/dpkg/lock >/dev/null 2>&1; do 4 | echo -n "." 5 | sleep 1 6 | done 7 | echo "" 8 | } 9 | 10 | echo "Have you read and accepted the following TOS & EULA for the following:" 11 | echo " NVIDIA Driver TOS: http://www.nvidia.com/content/DriverDownload-March2009/licence.php?lang=us" 12 | echo " NVIDIA CUDA EULA: http://developer.download.nvidia.com/compute/cuda/7.5/Prod/docs/sidebar/EULA.pdf" 13 | echo " NVIDIA CUDNN License: https://developer.nvidia.com/rdp/assets/cudnn-65-eula-asset" 14 | echo " COCO2014 Image Dataset: http://mscoco.org/terms_of_use/" 15 | read -p "If you've read and accepted the TOS, EULA and licenses, please enter (Y|n): " -n 1 -r 16 | echo # (optional) move to a new line 17 | if [[ $REPLY =~ ^[Yy]$ ]] 18 | then 19 | # Wait for apt-get to get unlocked 20 | echo -n "Initializing installation script " 21 | 22 | checkAptGet && sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 150 23 | 24 | checkAptGet && curl -LO http://us.download.nvidia.com/XFree86/Linux-x86_64/361.28/NVIDIA-Linux-x86_64-361.28.run && chmod +x NVIDIA-Linux-x86_64-361.28.run && sudo ./NVIDIA-Linux-x86_64-361.28.run --silent 25 | 26 | sudo update-alternatives --set gcc /usr/bin/gcc-4.8 27 | 28 | checkAptGet && curl -LO https://s3.amazonaws.com/algorithmia-assets/github_repo/deepfilter-training/cuda_7.5.18_linux.run && chmod +x cuda_7.5.18_linux.run && sudo ./cuda_7.5.18_linux.run --silent --toolkit 29 | checkAptGet && curl -LO https://s3.amazonaws.com/algorithmia-assets/github_repo/deepfilter-training/cudnn-7.5-linux-x64-v5.1.tgz && tar -xf cudnn-7.5-linux-x64-v5.1.tgz && sudo mv cuda/include/* /usr/local/cuda/include && sudo mv cuda/lib64/* /usr/local/cuda/lib64 30 | 31 | nvidia-modprobe -c 0 && nvidia-modprobe -c 0 -u 32 | nvidia-smi 33 | 34 | sudo update-alternatives --set gcc /usr/bin/gcc-5 35 | 36 | git clone https://github.com/torch/distro.git ~/torch; 37 | checkAptGet && cd ~/torch; 38 | git checkout 3fd189488e22c2a2afd351d07e2a2080fa685b1b; 39 | git submodule update --init --recursive; 40 | bash install-deps; 41 | 42 | sudo update-alternatives --set gcc /usr/bin/gcc-4.8 43 | 44 | checkAptGet && echo -ne '\n' | ./install.sh 45 | 46 | cd ~ 47 | 48 | checkAptGet && . torch/install/bin/torch-activate 49 | 50 | # Fix for broken Torch rocks installation 51 | # Peg git-hash version numbers 52 | torch_commit="426e2989de5ef3e759b1e10efe94bd04c170efda" 53 | sys_commit="f073f057d3fd2148866eaa0444a62ababfdf935e" 54 | cutorch_commit="bcbb427c4d7322a4e88f867a19193940677dfabc" 55 | loadcaffe_commit="6b6c58831980db9a09af2fd26bbd82247f116575" 56 | nn_commit="9b2f1ef7c45204f5c278bbdc55e367fcdd29e70e" 57 | cunn_commit="8d35db45bbb2ad35d3a045d7ebe185b1f9efc505" 58 | optim_commit="89ef52a03b1c39c645d96023b8748ef84973d4f6" 59 | image_commit="674c8d184b35d3e46e6bea54465b6c7b390d076f" 60 | cudnn_commit="970d7249e5c680d20ecac98edebe1f507feeecac" 61 | 62 | # Change directory to home directory 63 | cd ~ 64 | 65 | # Install torch rock from source. Equilavent of: luarocks install torch (as of Dec 8th 2016) 66 | git clone https://github.com/torch/torch7.git /tmp/torch7 --recursive \ 67 | && cd /tmp/torch7 \ 68 | && git checkout "$torch_commit" \ 69 | && luarocks make rocks/torch-scm-1.rockspec \ 70 | && cd ~ \ 71 | && rm -rf /tmp/torch7 72 | 73 | # Install sys rock from source. Equilavent of: luarocks install sys (as of Dec 8th 2016) 74 | git clone https://github.com/torch/sys.git /tmp/sys --recursive \ 75 | && cd /tmp/sys \ 76 | && git checkout "$sys_commit" \ 77 | && luarocks make sys-1.1-0.rockspec \ 78 | && cd ~ \ 79 | && rm -rf /tmp/sys 80 | 81 | # Install cutorch rock from source. Equilavent of: luarocks install cutorch (as of Dec 8th 2016) 82 | git clone https://github.com/torch/cutorch.git /tmp/cutorch --recursive \ 83 | && cd /tmp/cutorch \ 84 | && git checkout "$cutorch_commit" \ 85 | && luarocks make rocks/cutorch-scm-1.rockspec \ 86 | && cd ~ \ 87 | && rm -rf /tmp/cutorch 88 | 89 | # Install loadcaffe rock from source. Equilavent of: luarocks install loadcaffe (as of Dec 8th 2016) 90 | git clone https://github.com/szagoruyko/loadcaffe.git /tmp/loadcaffe --recursive \ 91 | && cd /tmp/loadcaffe \ 92 | && git checkout "$loadcaffe_commit" \ 93 | && luarocks make loadcaffe-1.0-0.rockspec \ 94 | && cd ~ \ 95 | && rm -rf /tmp/loadcaffe 96 | 97 | # Install nn rock from source. Equilavent of: luarocks install nn (as of Dec 8th 2016) 98 | git clone https://github.com/torch/nn.git /tmp/nn --recursive \ 99 | && cd /tmp/nn \ 100 | && git checkout "$nn_commit" \ 101 | && luarocks make rocks/nn-scm-1.rockspec \ 102 | && cd ~ \ 103 | && rm -rf /tmp/nn 104 | 105 | # Install cunn rock from source. Equilavent of: luarocks install cunn (as of Dec 8th 2016) 106 | git clone https://github.com/torch/cunn.git /tmp/cunn --recursive \ 107 | && cd /tmp/cunn \ 108 | && git checkout "$cunn_commit" \ 109 | && luarocks make rocks/cunn-scm-1.rockspec \ 110 | && cd ~ \ 111 | && rm -rf /tmp/cunn 112 | 113 | # Install optim rock from source. Equilavent of: luarocks install optim (as of Dec 8th 2016) 114 | git clone https://github.com/torch/optim.git /tmp/optim --recursive \ 115 | && cd /tmp/optim \ 116 | && git checkout "$optim_commit" \ 117 | && luarocks make optim-1.0.5-0.rockspec \ 118 | && cd ~ \ 119 | && rm -rf /tmp/optim 120 | 121 | # Install image rock from source. Equilavent of: luarocks install image (as of Dec 8th 2016) 122 | git clone https://github.com/torch/image.git /tmp/image --recursive \ 123 | && cd /tmp/image \ 124 | && git checkout "$image_commit" \ 125 | && luarocks make image-1.1.alpha-0.rockspec \ 126 | && cd ~ \ 127 | && rm -rf /tmp/image 128 | 129 | # Install cudnn rock from source. Equilavent of: luarocks install cudnn (as of Dec 8th 2016) 130 | git clone https://github.com/soumith/cudnn.torch.git /tmp/cudnn.torch --recursive \ 131 | && cd /tmp/cudnn.torch \ 132 | && git checkout "$cudnn_commit" \ 133 | && luarocks make cudnn-scm-1.rockspec \ 134 | && cd ~ \ 135 | && rm -rf /tmp/cudnn.torch 136 | 137 | git clone https://github.com/DmitryUlyanov/texture_nets.git 138 | 139 | checkAptGet && sudo apt-get install -y --force-yes libprotobuf-dev protobuf-compiler 140 | 141 | luarocks install --local loadcaffe 142 | 143 | export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH" 144 | 145 | cd texture_nets 146 | 147 | # Checkout to older version since model has been slightly changed (Jan 9th 2018) 148 | git checkout e4fd939d220afab8da194fd8e318d477a0c55fce 149 | 150 | cd data/pretrained && bash download_models.sh && cd ../.. 151 | 152 | wget http://msvocds.blob.core.windows.net/coco2014/train2014.zip 153 | wget http://msvocds.blob.core.windows.net/coco2014/val2014.zip 154 | unzip train2014.zip 155 | unzip val2014.zip 156 | mkdir -p dataset/train 157 | mkdir -p dataset/val 158 | ln -s `pwd`/val2014 dataset/val/dummy 159 | ln -s `pwd`/train2014 dataset/train/dummy 160 | 161 | sudo update-alternatives --set gcc /usr/bin/gcc-5 162 | 163 | checkAptGet && curl -sSf https://raw.githubusercontent.com/algorithmiaio/algorithmia-cli/master/install.sh | sh 164 | 165 | # Add cuddn .so files to LD_LIBRARY_PATH 166 | export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH 167 | echo "export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH" >> ~/.bashrc 168 | fi 169 | --------------------------------------------------------------------------------