├── .gitattributes ├── Dockerfile ├── Dockerfile_torch-caffe ├── Dockerfile_torch-caffe-jupyter ├── GCE_setup.sh ├── README.md ├── test1.png └── volta-files ├── Neural-Tools ├── linear-color-transfer.py └── lum-transfer.py ├── models ├── VGG_ILSVRC_19_layers.caffemodel ├── VGG_ILSVRC_19_layers_deploy.prototxt ├── VGG_ILSVRC_19_layers_deploy_fullconv.prototxt ├── channel_pruning.caffemodel ├── channel_pruning.prototxt ├── nin_imagenet_conv.caffemodel ├── nyud-fcn32s-color-heavy-trainval.prototxt ├── nyud-fcn32s-color-heavy.caffemodel ├── train_val.prototxt └── vgg_normalised.caffemodel ├── neural_style_dir_rng_fix.lua ├── test_files ├── content.jpg └── style │ ├── 1.jpg │ └── 2.jpg ├── volta-cpu.sh ├── volta-mod.ipynb └── volta-x1.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | *.caffemodel filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nimaid/volta-deep-style:torch-caffe-jupyter 2 | 3 | RUN apt-get update 4 | RUN apt-get install -y --no-install-recommends curl 5 | 6 | COPY ./volta-files /volta 7 | WORKDIR /volta 8 | 9 | CMD export SHELL=/bin/bash && jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser --allow-root 10 | 11 | -------------------------------------------------------------------------------- /Dockerfile_torch-caffe: -------------------------------------------------------------------------------- 1 | FROM ufoym/deepo:torch 2 | 3 | RUN APT_INSTALL="apt-get install -y --no-install-recommends" && \ 4 | PIP_INSTALL="python -m pip --no-cache-dir install --upgrade" && \ 5 | GIT_CLONE="git clone --depth 10" && \ 6 | 7 | rm -rf /var/lib/apt/lists/* \ 8 | /etc/apt/sources.list.d/cuda.list \ 9 | /etc/apt/sources.list.d/nvidia-ml.list && \ 10 | 11 | apt-get update && \ 12 | 13 | # ================================================================== 14 | # python 15 | # ------------------------------------------------------------------ 16 | 17 | DEBIAN_FRONTEND=noninteractive $APT_INSTALL \ 18 | software-properties-common \ 19 | && \ 20 | add-apt-repository ppa:deadsnakes/ppa && \ 21 | apt-get update && \ 22 | DEBIAN_FRONTEND=noninteractive $APT_INSTALL \ 23 | python3.6 \ 24 | python3.6-dev \ 25 | python3-distutils-extra \ 26 | && \ 27 | wget -O ~/get-pip.py \ 28 | https://bootstrap.pypa.io/get-pip.py && \ 29 | python3.6 ~/get-pip.py && \ 30 | ln -s /usr/bin/python3.6 /usr/local/bin/python3 && \ 31 | ln -s /usr/bin/python3.6 /usr/local/bin/python && \ 32 | $PIP_INSTALL \ 33 | setuptools \ 34 | && \ 35 | $PIP_INSTALL \ 36 | numpy \ 37 | scipy \ 38 | pandas \ 39 | cloudpickle \ 40 | scikit-learn \ 41 | matplotlib \ 42 | Cython \ 43 | && \ 44 | 45 | # ================================================================== 46 | # boost 47 | # ------------------------------------------------------------------ 48 | 49 | wget -O ~/boost.tar.gz https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.gz && \ 50 | tar -zxf ~/boost.tar.gz -C ~ && \ 51 | cd ~/boost_* && \ 52 | ./bootstrap.sh --with-python=python3.6 && \ 53 | ./b2 install --prefix=/usr/local && \ 54 | 55 | # ================================================================== 56 | # opencv 57 | # ------------------------------------------------------------------ 58 | 59 | DEBIAN_FRONTEND=noninteractive $APT_INSTALL \ 60 | libatlas-base-dev \ 61 | libgflags-dev \ 62 | libgoogle-glog-dev \ 63 | libhdf5-serial-dev \ 64 | libleveldb-dev \ 65 | liblmdb-dev \ 66 | libprotobuf-dev \ 67 | libsnappy-dev \ 68 | protobuf-compiler \ 69 | && \ 70 | 71 | $GIT_CLONE --branch 4.0.1 https://github.com/opencv/opencv ~/opencv && \ 72 | mkdir -p ~/opencv/build && cd ~/opencv/build && \ 73 | cmake -D CMAKE_BUILD_TYPE=RELEASE \ 74 | -D CMAKE_INSTALL_PREFIX=/usr/local \ 75 | -D WITH_IPP=OFF \ 76 | -D WITH_CUDA=OFF \ 77 | -D WITH_OPENCL=OFF \ 78 | -D BUILD_TESTS=OFF \ 79 | -D BUILD_PERF_TESTS=OFF \ 80 | .. && \ 81 | make -j"$(nproc)" install && \ 82 | ln -s /usr/local/include/opencv4/opencv2 /usr/local/include/opencv2 && \ 83 | 84 | # ================================================================== 85 | # caffe 86 | # ------------------------------------------------------------------ 87 | 88 | $GIT_CLONE https://github.com/BVLC/caffe ~/caffe && \ 89 | sed -i 's/CV_LOAD_IMAGE_COLOR/cv::IMREAD_COLOR/g' ~/caffe/src/caffe/layers/window_data_layer.cpp && \ 90 | sed -i 's/CV_LOAD_IMAGE_COLOR/cv::IMREAD_COLOR/g' ~/caffe/src/caffe/util/io.cpp && \ 91 | sed -i 's/CV_LOAD_IMAGE_GRAYSCALE/cv::IMREAD_GRAYSCALE/g' ~/caffe/src/caffe/util/io.cpp && \ 92 | cp ~/caffe/Makefile.config.example ~/caffe/Makefile.config && \ 93 | sed -i 's/# USE_CUDNN/USE_CUDNN/g' ~/caffe/Makefile.config && \ 94 | sed -i 's/# PYTHON_LIBRARIES/PYTHON_LIBRARIES/g' ~/caffe/Makefile.config && \ 95 | sed -i 's/# WITH_PYTHON_LAYER/WITH_PYTHON_LAYER/g' ~/caffe/Makefile.config && \ 96 | sed -i 's/# OPENCV_VERSION/OPENCV_VERSION/g' ~/caffe/Makefile.config && \ 97 | sed -i 's/# USE_NCCL/USE_NCCL/g' ~/caffe/Makefile.config && \ 98 | sed -i 's/-gencode arch=compute_20,code=sm_20//g' ~/caffe/Makefile.config && \ 99 | sed -i 's/-gencode arch=compute_20,code=sm_21//g' ~/caffe/Makefile.config && \ 100 | sed -i 's/2\.7/3\.6/g' ~/caffe/Makefile.config && \ 101 | sed -i 's/3\.5/3\.6/g' ~/caffe/Makefile.config && \ 102 | sed -i 's/\/usr\/lib\/python/\/usr\/local\/lib\/python/g' ~/caffe/Makefile.config && \ 103 | sed -i 's/\/usr\/local\/include/\/usr\/local\/include \/usr\/include\/hdf5\/serial/g' ~/caffe/Makefile.config && \ 104 | sed -i 's/hdf5/hdf5_serial/g' ~/caffe/Makefile && \ 105 | sed -i 's/# Debugging/COMMON_FLAGS += -std=c++11\n# Debugging/g' ~/caffe/Makefile && \ 106 | cd ~/caffe && \ 107 | make -j"$(nproc)" -Wno-deprecated-gpu-targets distribute && \ 108 | 109 | # fix ValueError caused by python-dateutil 1.x 110 | sed -i 's/,<2//g' ~/caffe/python/requirements.txt && \ 111 | 112 | $PIP_INSTALL \ 113 | -r ~/caffe/python/requirements.txt && \ 114 | 115 | cd ~/caffe/distribute/bin && \ 116 | for file in *.bin; do mv "$file" "${file%%.bin}"; done && \ 117 | cd ~/caffe/distribute && \ 118 | cp -r bin include lib proto /usr/local/ && \ 119 | cp -r python/caffe /usr/local/lib/python3.6/dist-packages/ && \ 120 | 121 | # ================================================================== 122 | # config & cleanup 123 | # ------------------------------------------------------------------ 124 | 125 | ldconfig && \ 126 | apt-get clean && \ 127 | apt-get autoremove && \ 128 | rm -rf /var/lib/apt/lists/* /tmp/* ~/* 129 | 130 | RUN luarocks install loadcaffe 131 | -------------------------------------------------------------------------------- /Dockerfile_torch-caffe-jupyter: -------------------------------------------------------------------------------- 1 | FROM nimaid/volta-deep-style:torch-caffe 2 | 3 | RUN APT_INSTALL="apt-get install -y --no-install-recommends" && \ 4 | PIP_INSTALL="python -m pip --no-cache-dir install --upgrade" && \ 5 | GIT_CLONE="git clone --depth 10" && \ 6 | 7 | rm -rf /var/lib/apt/lists/* \ 8 | /etc/apt/sources.list.d/cuda.list \ 9 | /etc/apt/sources.list.d/nvidia-ml.list && \ 10 | 11 | apt-get update && \ 12 | 13 | # ================================================================== 14 | # jupyter 15 | # ------------------------------------------------------------------ 16 | 17 | $PIP_INSTALL jupyter && \ 18 | 19 | # Install deps for Neural-Tools 20 | 21 | $PIP_INSTALL numpy && \ 22 | $PIP_INSTALL scipy && \ 23 | 24 | # Install IPython File Upload Widget 25 | $PIP_INSTALL fileupload && \ 26 | jupyter nbextension install --py fileupload && \ 27 | jupyter nbextension enable --py fileupload 28 | 29 | 30 | #install file upload widget? 31 | 32 | EXPOSE 8888 -------------------------------------------------------------------------------- /GCE_setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # I started with a pre-made deep learning image because I was having issues getting nvidia-docker to talk with the drivers on Ubuntu 16.04 3 | # "Intel® optimized Deep Learning Image: Base m21 (with Intel® MKL and CUDA 10.0)" 4 | 5 | #curl -O -s https://gist.githubusercontent.com/durgeshm/b149e7baec4d4508eb4b2914d63018c7/raw/798aadbb54b451abcaba9bfeb833327fa4b3d53b/deps_nvidia_docker.sh -- may automate from 16.04 --> nvidia-docker 6 | 7 | # Install docker 8 | wget -O - -q 'https://gist.githubusercontent.com/allenday/c875eaf21a2b416f6478c0a48e428f6a/raw/f7feca1acc1a992afa84f347394fd7e4bfac2599/install-docker-ce.sh' | sudo bash 9 | 10 | # Install nvidia-docker 11 | wget https://github.com/NVIDIA/nvidia-docker/releases/download/v1.0.1/nvidia-docker_1.0.1-1_amd64.deb 12 | sudo dpkg -i nvidia-docker*.deb 13 | 14 | # Get docker image 15 | sudo docker pull nimaid/volta-deep-style:test1 16 | 17 | # Reboot and you're ready to go! 18 | sudo reboot 19 | 20 | # Run with "sudo docker run --runtime=nvidia -it --rm -p=8888:8888 nimaid/volta-deep-style:test1 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # volta 2 | A Dockerized, heavily modified version of the Volta Deep Style Transfer script made by Victor Espinoza (vic8760). 3 | 4 | Update 3 5 | 6 | [Docker Hub](https://cloud.docker.com/repository/docker/nimaid/volta-deep-style/general) 7 | 8 | ## WIP! Below is info on using the latest testing image. 9 | 10 | This is a Dockerized environment with CUDA 9.0, cuDNN v7, Torch7, Caffe, and all the required files pre-installed! Just launch with [nvidia-docker](https://github.com/NVIDIA/nvidia-docker) and get dreaming! 11 | 12 | `sudo docker pull nimaid/volta-deep-style` 13 | 14 | `sudo docker run --runtime=nvidia -it nimaid/volta-deep-style` 15 | 16 | The example script is `volta-x1.sh`. It's made for single-GPU machines, and uses only GPU 0 in multi-GPU environments. 17 | 18 | `./volta-x1.sh test_files/style/ test_files/content.jpg` 19 | 20 | Jupyter notebook tag and more code cleanup coming! 21 | 22 | The Docker environment is completely functional, and you can simply load any existing scripts you have over to it and get running! 23 | 24 | The Jupyter notebook is not really working very well yet, but you can get the idea of what I'm trying to do. For some reason, it's not giving the same results as with the `volta-x1.sh`. I really don't know much about multi-res transfers, just Docker. :) If you can lend a hand in helping figure out how to make my algorithm work better, please contact me! 25 | -------------------------------------------------------------------------------- /test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimaid/volta/188c41cb6bb33e38f918a0a0020c107b74119a08/test1.png -------------------------------------------------------------------------------- /volta-files/Neural-Tools/linear-color-transfer.py: -------------------------------------------------------------------------------- 1 | # This script performs the linear color transfer step that 2 | # leongatys/NeuralImageSynthesis' Scale Control code performs. 3 | # https://github.com/leongatys/NeuralImageSynthesis/blob/master/ExampleNotebooks/ScaleControl.ipynb 4 | # Standalone script by github.com/htoyryla, and github.com/ProGamerGov 5 | 6 | import numpy as np 7 | import argparse 8 | import scipy.ndimage as spi 9 | from skimage import io,transform,img_as_float 10 | from skimage.io import imread,imsave 11 | from PIL import Image 12 | from numpy import eye 13 | 14 | parser = argparse.ArgumentParser() 15 | parser.add_argument('--target_image', type=str, help="The image you are transfering color to. Ex: target.png", required=True) 16 | parser.add_argument('--source_image', type=str, help="The image you are transfering color from. Ex: source.png", required=True) 17 | parser.add_argument('--output_image', default='output.png', help="The name of your output image. Ex: output.png", type=str) 18 | parser.add_argument('--mode', default='pca', help="The color transfer mode. Options are pca, chol, or sym.", type=str) 19 | parser.add_argument('--eps', default='1e-5', help="Your epsilon value in scientific notation or normal notation. Ex: 1e-5 or 0.00001", type=float) 20 | parser.parse_args() 21 | args = parser.parse_args() 22 | 23 | 24 | Image.MAX_IMAGE_PIXELS = 1000000000 # Support gigapixel images 25 | 26 | 27 | def main(): 28 | 29 | target_img = spi.imread(args.target_image, mode="RGB").astype(float)/256 30 | source_img = spi.imread(args.source_image, mode="RGB").astype(float)/256 31 | 32 | output_img = match_color(target_img, source_img, mode=args.mode, eps=args.eps) 33 | imsave(args.output_image, output_img) 34 | 35 | 36 | def match_color(target_img, source_img, mode='pca', eps=1e-5): 37 | ''' 38 | Matches the colour distribution of the target image to that of the source image 39 | using a linear transform. 40 | Images are expected to be of form (w,h,c) and float in [0,1]. 41 | Modes are chol, pca or sym for different choices of basis. 42 | ''' 43 | mu_t = target_img.mean(0).mean(0) 44 | t = target_img - mu_t 45 | t = t.transpose(2,0,1).reshape(3,-1) 46 | Ct = t.dot(t.T) / t.shape[1] + eps * eye(t.shape[0]) 47 | mu_s = source_img.mean(0).mean(0) 48 | s = source_img - mu_s 49 | s = s.transpose(2,0,1).reshape(3,-1) 50 | Cs = s.dot(s.T) / s.shape[1] + eps * eye(s.shape[0]) 51 | if mode == 'chol': 52 | chol_t = np.linalg.cholesky(Ct) 53 | chol_s = np.linalg.cholesky(Cs) 54 | ts = chol_s.dot(np.linalg.inv(chol_t)).dot(t) 55 | if mode == 'pca': 56 | eva_t, eve_t = np.linalg.eigh(Ct) 57 | Qt = eve_t.dot(np.sqrt(np.diag(eva_t))).dot(eve_t.T) 58 | eva_s, eve_s = np.linalg.eigh(Cs) 59 | Qs = eve_s.dot(np.sqrt(np.diag(eva_s))).dot(eve_s.T) 60 | ts = Qs.dot(np.linalg.inv(Qt)).dot(t) 61 | if mode == 'sym': 62 | eva_t, eve_t = np.linalg.eigh(Ct) 63 | Qt = eve_t.dot(np.sqrt(np.diag(eva_t))).dot(eve_t.T) 64 | Qt_Cs_Qt = Qt.dot(Cs).dot(Qt) 65 | eva_QtCsQt, eve_QtCsQt = np.linalg.eigh(Qt_Cs_Qt) 66 | QtCsQt = eve_QtCsQt.dot(np.sqrt(np.diag(eva_QtCsQt))).dot(eve_QtCsQt.T) 67 | ts = np.linalg.inv(Qt).dot(QtCsQt).dot(np.linalg.inv(Qt)).dot(t) 68 | matched_img = ts.reshape(*target_img.transpose(2,0,1).shape).transpose(1,2,0) 69 | matched_img += mu_s 70 | matched_img[matched_img>1] = 1 71 | matched_img[matched_img<0] = 0 72 | return matched_img 73 | 74 | 75 | if __name__ == "__main__": 76 | main() 77 | -------------------------------------------------------------------------------- /volta-files/Neural-Tools/lum-transfer.py: -------------------------------------------------------------------------------- 1 | #This script performs the functions required for lumin transfer that 2 | #leongatys/NeuralImageSynthesis' Color Control code performs. 3 | #https://github.com/leongatys/NeuralImageSynthesis/blob/master/ExampleNotebooks/ColourControl.ipynb 4 | #Standalone script by github.com/ProGamerGov 5 | 6 | import skimage 7 | import numpy as np 8 | import argparse 9 | import scipy.ndimage as spi 10 | from skimage import io,transform,img_as_float 11 | from skimage.io import imread,imsave 12 | from PIL import Image 13 | from numpy import eye 14 | 15 | 16 | parser = argparse.ArgumentParser() 17 | parser.add_argument('--content_image', type=str, help="The content image. Ex: content.png") 18 | parser.add_argument('--style_image', type=str, help="The style image. Ex: style.png") 19 | parser.add_argument('--output_content_image', default='output_content.png', help="The name of your output content image. Ex: content_output.png", type=str) 20 | parser.add_argument('--output_style_image', default='output_style.png', help="The name of your output style image. Ex: style_output.png", type=str) 21 | parser.add_argument('--output_image', default='output_style.png', help="The name of your output image. Ex: output.png", type=str) 22 | parser.add_argument('--org_content', default='original_content_image.png', help="The name of your original content image. Ex: org_content.png", type=str) 23 | parser.add_argument('--output_lum2', default='out.png', help="The name of your output image from Neural-Style. Ex: out.png", type=str) 24 | parser.add_argument('--cp_mode', default='lum', help="The script's mode. Options are: lum, lum2, match, and match_style", type=str) 25 | parser.parse_args() 26 | args = parser.parse_args() 27 | cp_mode = args.cp_mode 28 | output_content_name = args.output_content_image 29 | output_style_name = args.output_style_image 30 | output_a_name = args.output_image 31 | 32 | Image.MAX_IMAGE_PIXELS = 1000000000 # Support gigapixel images 33 | 34 | def lum_transform(image): 35 | """ 36 | Returns the projection of a colour image onto the luminance channel 37 | Images are expected to be of form (w,h,c) and float in [0,1]. 38 | """ 39 | img = image.transpose(2,0,1).reshape(3,-1) 40 | lum = np.array([.299, .587, .114]).dot(img).squeeze() 41 | img = np.tile(lum[None,:],(3,1)).reshape((3,image.shape[0],image.shape[1])) 42 | return img.transpose(1,2,0) 43 | 44 | def rgb2luv(image): 45 | img = image.transpose(2,0,1).reshape(3,-1) 46 | luv = np.array([[.299, .587, .114],[-.147, -.288, .436],[.615, -.515, -.1]]).dot(img).reshape((3,image.shape[0],image.shape[1])) 47 | return luv.transpose(1,2,0) 48 | def luv2rgb(image): 49 | img = image.transpose(2,0,1).reshape(3,-1) 50 | rgb = np.array([[1, 0, 1.139],[1, -.395, -.580],[1, 2.03, 0]]).dot(img).reshape((3,image.shape[0],image.shape[1])) 51 | return rgb.transpose(1,2,0) 52 | 53 | def match_color(target_img, source_img, mode='pca', eps=1e-5): 54 | ''' 55 | Matches the colour distribution of the target image to that of the source image 56 | using a linear transform. 57 | Images are expected to be of form (w,h,c) and float in [0,1]. 58 | Modes are chol, pca or sym for different choices of basis. 59 | ''' 60 | mu_t = target_img.mean(0).mean(0) 61 | t = target_img - mu_t 62 | t = t.transpose(2,0,1).reshape(3,-1) 63 | Ct = t.dot(t.T) / t.shape[1] + eps * np.eye(t.shape[0]) 64 | mu_s = source_img.mean(0).mean(0) 65 | s = source_img - mu_s 66 | s = s.transpose(2,0,1).reshape(3,-1) 67 | Cs = s.dot(s.T) / s.shape[1] + eps * np.eye(s.shape[0]) 68 | if mode == 'chol': 69 | chol_t = np.linalg.cholesky(Ct) 70 | chol_s = np.linalg.cholesky(Cs) 71 | ts = chol_s.dot(np.linalg.inv(chol_t)).dot(t) 72 | if mode == 'pca': 73 | eva_t, eve_t = np.linalg.eigh(Ct) 74 | Qt = eve_t.dot(np.sqrt(np.diag(eva_t))).dot(eve_t.T) 75 | eva_s, eve_s = np.linalg.eigh(Cs) 76 | Qs = eve_s.dot(np.sqrt(np.diag(eva_s))).dot(eve_s.T) 77 | ts = Qs.dot(np.linalg.inv(Qt)).dot(t) 78 | if mode == 'sym': 79 | eva_t, eve_t = np.linalg.eigh(Ct) 80 | Qt = eve_t.dot(np.sqrt(np.diag(eva_t))).dot(eve_t.T) 81 | Qt_Cs_Qt = Qt.dot(Cs).dot(Qt) 82 | eva_QtCsQt, eve_QtCsQt = np.linalg.eigh(Qt_Cs_Qt) 83 | QtCsQt = eve_QtCsQt.dot(np.sqrt(np.diag(eva_QtCsQt))).dot(eve_QtCsQt.T) 84 | ts = np.linalg.inv(Qt).dot(QtCsQt).dot(np.linalg.inv(Qt)).dot(t) 85 | matched_img = ts.reshape(*target_img.transpose(2,0,1).shape).transpose(1,2,0) 86 | matched_img += mu_s 87 | matched_img[matched_img>1] = 1 88 | matched_img[matched_img<0] = 0 89 | return matched_img 90 | 91 | if cp_mode == 'lum': 92 | style_img = args.style_image 93 | content_img = args.content_image 94 | org_content = args.org_content 95 | org_content = spi.imread(org_content, mode="RGB").astype(float)/256 96 | style_img = spi.imread(style_img, mode="RGB").astype(float)/256 97 | content_img = spi.imread(content_img, mode="RGB").astype(float)/256 98 | 99 | org_content = content_img.copy() 100 | style_img = lum_transform(style_img) 101 | content_img = lum_transform(content_img) 102 | style_img -= style_img.mean(0).mean(0) 103 | style_img += content_img.mean(0).mean(0) 104 | 105 | style_img [style_img < 0 ] = 0 106 | style_img [style_img > 1 ] = 1 107 | 108 | content_img [content_img < 0 ] = 0 109 | content_img [content_img > 1 ] = 1 110 | 111 | imsave(output_content_name, content_img) 112 | imsave(output_style_name, style_img) 113 | elif cp_mode =='match': 114 | style_img = args.style_image 115 | content_img = args.content_image 116 | style_img = spi.imread(style_img, mode="RGB").astype(float)/256 117 | content_img = spi.imread(content_img, mode="RGB").astype(float)/256 118 | 119 | style_img = match_color(style_img, content_img, mode='pca') 120 | 121 | imsave(output_style_name, style_img) 122 | elif cp_mode == 'match_style': 123 | style_img = args.style_image 124 | content_img = args.content_image 125 | style_img = spi.imread(style_img, mode="RGB").astype(float)/256 126 | content_img = spi.imread(content_img, mode="RGB").astype(float)/256 127 | 128 | content_img = match_color(content_img, style_img, mode='pca') 129 | 130 | imsave(output_content_name, content_img) 131 | elif cp_mode == 'lum2': 132 | output = args.output_lum2 133 | org_content = args.org_content 134 | org_content = spi.imread(org_content, mode="RGB").astype(float)/256 135 | output = spi.imread(output, mode="RGB").astype(float)/256 136 | 137 | org_content = skimage.transform.resize(org_content, output.shape) 138 | 139 | org_content = rgb2luv(org_content) 140 | org_content[:,:,0] = output.mean(2) 141 | output = luv2rgb(org_content) 142 | output[output<0] = 0 143 | output[output>1]=1 144 | imsave(output_a_name, output) 145 | else: 146 | raise NameError('Unknown colour preservation mode') 147 | 148 | -------------------------------------------------------------------------------- /volta-files/models/VGG_ILSVRC_19_layers.caffemodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:31b4c627c40c6ee151325f079b7ac557fddbd1f79af932888796127a4f4f6954 3 | size 574671192 4 | -------------------------------------------------------------------------------- /volta-files/models/VGG_ILSVRC_19_layers_deploy.prototxt: -------------------------------------------------------------------------------- 1 | name: "VGG_ILSVRC_19_layer" 2 | input: "data" 3 | force_backward: true 4 | input_shape { 5 | dim: 1 6 | dim: 3 7 | dim: 224 8 | dim: 224 9 | } 10 | layer { 11 | bottom: "data" 12 | top: "conv1_1" 13 | name: "conv1_1" 14 | type: "Convolution" 15 | convolution_param { 16 | num_output: 64 17 | pad: 1 18 | kernel_size: 3 19 | } 20 | } 21 | layer { 22 | bottom: "conv1_1" 23 | top: "conv1_1" 24 | name: "relu1_1" 25 | type: "ReLU" 26 | } 27 | layer { 28 | bottom: "conv1_1" 29 | top: "conv1_2" 30 | name: "conv1_2" 31 | type: "Convolution" 32 | convolution_param { 33 | num_output: 64 34 | pad: 1 35 | kernel_size: 3 36 | } 37 | } 38 | layer { 39 | bottom: "conv1_2" 40 | top: "conv1_2" 41 | name: "relu1_2" 42 | type: "ReLU" 43 | } 44 | layer { 45 | bottom: "conv1_2" 46 | top: "pool1" 47 | name: "pool1" 48 | type: "Pooling" 49 | pooling_param { 50 | pool: AVE 51 | kernel_size: 2 52 | stride: 2 53 | } 54 | } 55 | layer { 56 | bottom: "pool1" 57 | top: "conv2_1" 58 | name: "conv2_1" 59 | type: "Convolution" 60 | convolution_param { 61 | num_output: 128 62 | pad: 1 63 | kernel_size: 3 64 | } 65 | } 66 | layer { 67 | bottom: "conv2_1" 68 | top: "conv2_1" 69 | name: "relu2_1" 70 | type: "ReLU" 71 | } 72 | layer { 73 | bottom: "conv2_1" 74 | top: "conv2_2" 75 | name: "conv2_2" 76 | type: "Convolution" 77 | convolution_param { 78 | num_output: 128 79 | pad: 1 80 | kernel_size: 3 81 | } 82 | } 83 | layer { 84 | bottom: "conv2_2" 85 | top: "conv2_2" 86 | name: "relu2_2" 87 | type: "ReLU" 88 | } 89 | layer { 90 | bottom: "conv2_2" 91 | top: "pool2" 92 | name: "pool2" 93 | type: "Pooling" 94 | pooling_param { 95 | pool: AVE 96 | kernel_size: 2 97 | stride: 2 98 | } 99 | } 100 | layer { 101 | bottom: "pool2" 102 | top: "conv3_1" 103 | name: "conv3_1" 104 | type: "Convolution" 105 | convolution_param { 106 | num_output: 256 107 | pad: 1 108 | kernel_size: 3 109 | } 110 | } 111 | layer { 112 | bottom: "conv3_1" 113 | top: "conv3_1" 114 | name: "relu3_1" 115 | type: "ReLU" 116 | } 117 | layer { 118 | bottom: "conv3_1" 119 | top: "conv3_2" 120 | name: "conv3_2" 121 | type: "Convolution" 122 | convolution_param { 123 | num_output: 256 124 | pad: 1 125 | kernel_size: 3 126 | } 127 | } 128 | 129 | layer { 130 | bottom: "conv3_2" 131 | top: "conv3_2" 132 | name: "relu3_2" 133 | type: "ReLU" 134 | } 135 | 136 | layer { 137 | bottom: "conv3_2" 138 | top: "conv3_3" 139 | name: "conv3_3" 140 | type: "Convolution" 141 | convolution_param { 142 | num_output: 256 143 | pad: 1 144 | kernel_size: 3 145 | } 146 | } 147 | layer { 148 | bottom: "conv3_3" 149 | top: "conv3_3" 150 | name: "relu3_3" 151 | type: "ReLU" 152 | } 153 | layer { 154 | bottom: "conv3_3" 155 | top: "conv3_4" 156 | name: "conv3_4" 157 | type: "Convolution" 158 | convolution_param { 159 | num_output: 256 160 | pad: 1 161 | kernel_size: 3 162 | } 163 | } 164 | layer { 165 | bottom: "conv3_4" 166 | top: "conv3_4" 167 | name: "relu3_4" 168 | type: "ReLU" 169 | } 170 | layer { 171 | bottom: "conv3_4" 172 | top: "pool3" 173 | name: "pool3" 174 | type: "Pooling" 175 | pooling_param { 176 | pool: AVE 177 | kernel_size: 2 178 | stride: 2 179 | } 180 | } 181 | layer { 182 | bottom: "pool3" 183 | top: "conv4_1" 184 | name: "conv4_1" 185 | type: "Convolution" 186 | convolution_param { 187 | num_output: 512 188 | pad: 1 189 | kernel_size: 3 190 | } 191 | } 192 | layer { 193 | bottom: "conv4_1" 194 | top: "conv4_1" 195 | name: "relu4_1" 196 | type: "ReLU" 197 | } 198 | layer { 199 | bottom: "conv4_1" 200 | top: "conv4_2" 201 | name: "conv4_2" 202 | type: "Convolution" 203 | convolution_param { 204 | num_output: 512 205 | pad: 1 206 | kernel_size: 3 207 | } 208 | } 209 | layer { 210 | bottom: "conv4_2" 211 | top: "conv4_2" 212 | name: "relu4_2" 213 | type: "ReLU" 214 | } 215 | layer { 216 | bottom: "conv4_2" 217 | top: "conv4_3" 218 | name: "conv4_3" 219 | type: "Convolution" 220 | convolution_param { 221 | num_output: 512 222 | pad: 1 223 | kernel_size: 3 224 | } 225 | } 226 | layer { 227 | bottom: "conv4_3" 228 | top: "conv4_3" 229 | name: "relu4_3" 230 | type: "ReLU" 231 | } 232 | layer { 233 | bottom: "conv4_3" 234 | top: "conv4_4" 235 | name: "conv4_4" 236 | type: "Convolution" 237 | convolution_param { 238 | num_output: 512 239 | pad: 1 240 | kernel_size: 3 241 | } 242 | } 243 | layer { 244 | bottom: "conv4_4" 245 | top: "conv4_4" 246 | name: "relu4_4" 247 | type: "ReLU" 248 | } 249 | layer { 250 | bottom: "conv4_4" 251 | top: "pool4" 252 | name: "pool4" 253 | type: "Pooling" 254 | pooling_param { 255 | pool: AVE 256 | kernel_size: 2 257 | stride: 2 258 | } 259 | } 260 | layer { 261 | bottom: "pool4" 262 | top: "conv5_1" 263 | name: "conv5_1" 264 | type: "Convolution" 265 | convolution_param { 266 | num_output: 512 267 | pad: 1 268 | kernel_size: 3 269 | } 270 | } 271 | layer { 272 | bottom: "conv5_1" 273 | top: "conv5_1" 274 | name: "relu5_1" 275 | type: "ReLU" 276 | } 277 | layer { 278 | bottom: "conv5_1" 279 | top: "conv5_2" 280 | name: "conv5_2" 281 | type: "Convolution" 282 | convolution_param { 283 | num_output: 512 284 | pad: 1 285 | kernel_size: 3 286 | } 287 | } 288 | layer { 289 | bottom: "conv5_2" 290 | top: "conv5_2" 291 | name: "relu5_2" 292 | type: "ReLU" 293 | } 294 | layer { 295 | bottom: "conv5_2" 296 | top: "conv5_3" 297 | name: "conv5_3" 298 | type: "Convolution" 299 | convolution_param { 300 | num_output: 512 301 | pad: 1 302 | kernel_size: 3 303 | } 304 | } 305 | layer { 306 | bottom: "conv5_3" 307 | top: "conv5_3" 308 | name: "relu5_3" 309 | type: "ReLU" 310 | } 311 | layer { 312 | bottom: "conv5_3" 313 | top: "conv5_4" 314 | name: "conv5_4" 315 | type: "Convolution" 316 | convolution_param { 317 | num_output: 512 318 | pad: 1 319 | kernel_size: 3 320 | } 321 | } 322 | layer { 323 | bottom: "conv5_4" 324 | top: "conv5_4" 325 | name: "relu5_4" 326 | type: "ReLU" 327 | } 328 | layer { 329 | bottom: "conv5_4" 330 | top: "pool5" 331 | name: "pool5" 332 | type: "Pooling" 333 | pooling_param { 334 | pool: AVE 335 | kernel_size: 2 336 | stride: 2 337 | } 338 | } 339 | -------------------------------------------------------------------------------- /volta-files/models/VGG_ILSVRC_19_layers_deploy_fullconv.prototxt: -------------------------------------------------------------------------------- 1 | #debug_info: true 2 | force_backward: true 3 | name: "VGG_ILSVRC_19_layers" 4 | input: "data" 5 | input_dim: 1 6 | input_dim: 3 7 | input_dim: 224 8 | input_dim: 224 9 | layers { 10 | bottom: "data" 11 | top: "conv1_1" 12 | name: "conv1_1" 13 | type: CONVOLUTION 14 | convolution_param { 15 | num_output: 64 16 | pad: 1 17 | kernel_size: 3 18 | } 19 | } 20 | layers { 21 | bottom: "conv1_1" 22 | top: "conv1_1" 23 | name: "relu1_1" 24 | type: RELU 25 | } 26 | layers { 27 | bottom: "conv1_1" 28 | top: "conv1_2" 29 | name: "conv1_2" 30 | type: CONVOLUTION 31 | convolution_param { 32 | num_output: 64 33 | pad: 1 34 | kernel_size: 3 35 | } 36 | } 37 | layers { 38 | bottom: "conv1_2" 39 | top: "conv1_2" 40 | name: "relu1_2" 41 | type: RELU 42 | } 43 | layers { 44 | bottom: "conv1_2" 45 | top: "pool1" 46 | name: "pool1" 47 | type: POOLING 48 | pooling_param { 49 | pool: MAX 50 | kernel_size: 2 51 | stride: 2 52 | } 53 | } 54 | layers { 55 | bottom: "pool1" 56 | top: "conv2_1" 57 | name: "conv2_1" 58 | type: CONVOLUTION 59 | convolution_param { 60 | num_output: 128 61 | pad: 1 62 | kernel_size: 3 63 | } 64 | } 65 | layers { 66 | bottom: "conv2_1" 67 | top: "conv2_1" 68 | name: "relu2_1" 69 | type: RELU 70 | } 71 | layers { 72 | bottom: "conv2_1" 73 | top: "conv2_2" 74 | name: "conv2_2" 75 | type: CONVOLUTION 76 | convolution_param { 77 | num_output: 128 78 | pad: 1 79 | kernel_size: 3 80 | } 81 | } 82 | layers { 83 | bottom: "conv2_2" 84 | top: "conv2_2" 85 | name: "relu2_2" 86 | type: RELU 87 | } 88 | layers { 89 | bottom: "conv2_2" 90 | top: "pool2" 91 | name: "pool2" 92 | type: POOLING 93 | pooling_param { 94 | pool: MAX 95 | kernel_size: 2 96 | stride: 2 97 | } 98 | } 99 | layers { 100 | bottom: "pool2" 101 | top: "conv3_1" 102 | name: "conv3_1" 103 | type: CONVOLUTION 104 | convolution_param { 105 | num_output: 256 106 | pad: 1 107 | kernel_size: 3 108 | } 109 | } 110 | layers { 111 | bottom: "conv3_1" 112 | top: "conv3_1" 113 | name: "relu3_1" 114 | type: RELU 115 | } 116 | layers { 117 | bottom: "conv3_1" 118 | top: "conv3_2" 119 | name: "conv3_2" 120 | type: CONVOLUTION 121 | convolution_param { 122 | num_output: 256 123 | pad: 1 124 | kernel_size: 3 125 | } 126 | } 127 | layers { 128 | bottom: "conv3_2" 129 | top: "conv3_2" 130 | name: "relu3_2" 131 | type: RELU 132 | } 133 | layers { 134 | bottom: "conv3_2" 135 | top: "conv3_3" 136 | name: "conv3_3" 137 | type: CONVOLUTION 138 | convolution_param { 139 | num_output: 256 140 | pad: 1 141 | kernel_size: 3 142 | } 143 | } 144 | layers { 145 | bottom: "conv3_3" 146 | top: "conv3_3" 147 | name: "relu3_3" 148 | type: RELU 149 | } 150 | layers { 151 | bottom: "conv3_3" 152 | top: "conv3_4" 153 | name: "conv3_4" 154 | type: CONVOLUTION 155 | convolution_param { 156 | num_output: 256 157 | pad: 1 158 | kernel_size: 3 159 | } 160 | } 161 | layers { 162 | bottom: "conv3_4" 163 | top: "conv3_4" 164 | name: "relu3_4" 165 | type: RELU 166 | } 167 | layers { 168 | bottom: "conv3_4" 169 | top: "pool3" 170 | name: "pool3" 171 | type: POOLING 172 | pooling_param { 173 | pool: MAX 174 | kernel_size: 2 175 | stride: 2 176 | } 177 | } 178 | layers { 179 | bottom: "pool3" 180 | top: "conv4_1" 181 | name: "conv4_1" 182 | type: CONVOLUTION 183 | convolution_param { 184 | num_output: 512 185 | pad: 1 186 | kernel_size: 3 187 | } 188 | } 189 | layers { 190 | bottom: "conv4_1" 191 | top: "conv4_1" 192 | name: "relu4_1" 193 | type: RELU 194 | } 195 | layers { 196 | bottom: "conv4_1" 197 | top: "conv4_2" 198 | name: "conv4_2" 199 | type: CONVOLUTION 200 | convolution_param { 201 | num_output: 512 202 | pad: 1 203 | kernel_size: 3 204 | } 205 | } 206 | layers { 207 | bottom: "conv4_2" 208 | top: "conv4_2" 209 | name: "relu4_2" 210 | type: RELU 211 | } 212 | layers { 213 | bottom: "conv4_2" 214 | top: "conv4_3" 215 | name: "conv4_3" 216 | type: CONVOLUTION 217 | convolution_param { 218 | num_output: 512 219 | pad: 1 220 | kernel_size: 3 221 | } 222 | } 223 | layers { 224 | bottom: "conv4_3" 225 | top: "conv4_3" 226 | name: "relu4_3" 227 | type: RELU 228 | } 229 | layers { 230 | bottom: "conv4_3" 231 | top: "conv4_4" 232 | name: "conv4_4" 233 | type: CONVOLUTION 234 | convolution_param { 235 | num_output: 512 236 | pad: 1 237 | kernel_size: 3 238 | } 239 | } 240 | layers { 241 | bottom: "conv4_4" 242 | top: "conv4_4" 243 | name: "relu4_4" 244 | type: RELU 245 | } 246 | layers { 247 | bottom: "conv4_4" 248 | top: "pool4" 249 | name: "pool4" 250 | type: POOLING 251 | pooling_param { 252 | pool: MAX 253 | kernel_size: 2 254 | stride: 2 255 | } 256 | } 257 | layers { 258 | bottom: "pool4" 259 | top: "conv5_1" 260 | name: "conv5_1" 261 | type: CONVOLUTION 262 | convolution_param { 263 | num_output: 512 264 | pad: 1 265 | kernel_size: 3 266 | } 267 | } 268 | layers { 269 | bottom: "conv5_1" 270 | top: "conv5_1" 271 | name: "relu5_1" 272 | type: RELU 273 | } 274 | layers { 275 | bottom: "conv5_1" 276 | top: "conv5_2" 277 | name: "conv5_2" 278 | type: CONVOLUTION 279 | convolution_param { 280 | num_output: 512 281 | pad: 1 282 | kernel_size: 3 283 | } 284 | } 285 | layers { 286 | bottom: "conv5_2" 287 | top: "conv5_2" 288 | name: "relu5_2" 289 | type: RELU 290 | } 291 | layers { 292 | bottom: "conv5_2" 293 | top: "conv5_3" 294 | name: "conv5_3" 295 | type: CONVOLUTION 296 | convolution_param { 297 | num_output: 512 298 | pad: 1 299 | kernel_size: 3 300 | } 301 | } 302 | layers { 303 | bottom: "conv5_3" 304 | top: "conv5_3" 305 | name: "relu5_3" 306 | type: RELU 307 | } 308 | layers { 309 | bottom: "conv5_3" 310 | top: "conv5_4" 311 | name: "conv5_4" 312 | type: CONVOLUTION 313 | convolution_param { 314 | num_output: 512 315 | pad: 1 316 | kernel_size: 3 317 | } 318 | } 319 | layers { 320 | bottom: "conv5_4" 321 | top: "conv5_4" 322 | name: "relu5_4" 323 | type: RELU 324 | } 325 | #layers { 326 | # bottom: "conv5_4" 327 | # top: "pool5" 328 | # name: "pool5" 329 | # type: POOLING 330 | # pooling_param { 331 | # pool: MAX 332 | # kernel_size: 2 333 | # stride: 2 334 | # } 335 | #} 336 | #layers { 337 | # bottom: "pool5" 338 | # top: "fc6" 339 | # name: "fc6" 340 | # type: INNER_PRODUCT 341 | # inner_product_param { 342 | # num_output: 4096 343 | # } 344 | #} 345 | #layers { 346 | # bottom: "fc6" 347 | # top: "fc6" 348 | # name: "relu6" 349 | # type: RELU 350 | #} 351 | #layers { 352 | # bottom: "fc6" 353 | # top: "fc6" 354 | # name: "drop6" 355 | # type: DROPOUT 356 | # dropout_param { 357 | # dropout_ratio: 0.5 358 | # } 359 | #} 360 | #layers { 361 | # bottom: "fc6" 362 | # top: "fc7" 363 | # name: "fc7" 364 | # type: INNER_PRODUCT 365 | # inner_product_param { 366 | # num_output: 4096 367 | # } 368 | #} 369 | #layers { 370 | # bottom: "fc7" 371 | # top: "fc7" 372 | # name: "relu7" 373 | # type: RELU 374 | #} 375 | #layers { 376 | # bottom: "fc7" 377 | # top: "fc7" 378 | # name: "drop7" 379 | # type: DROPOUT 380 | # dropout_param { 381 | # dropout_ratio: 0.5 382 | # } 383 | #} 384 | #layers { 385 | # bottom: "fc7" 386 | # top: "fc8" 387 | # name: "fc8" 388 | # type: INNER_PRODUCT 389 | # inner_product_param { 390 | # num_output: 1000 391 | # } 392 | #} 393 | #layers { 394 | # bottom: "fc8" 395 | # top: "prob" 396 | # name: "prob" 397 | # type: SOFTMAX 398 | #} 399 | -------------------------------------------------------------------------------- /volta-files/models/channel_pruning.caffemodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:f7a90eebe987e945f39bd19c134944e386485b0a0dde613a0ba6ca1d73c57a4a 3 | size 523520023 4 | -------------------------------------------------------------------------------- /volta-files/models/channel_pruning.prototxt: -------------------------------------------------------------------------------- 1 | name: "VGG_ILSVRC_16_layers" 2 | layer { 3 | name: "data" 4 | type: "ImageData" 5 | top: "data" 6 | top: "label" 7 | image_data_param { 8 | new_dim: 256 9 | bicubic: true 10 | shuffle: true 11 | batch_size: 100 12 | source: "path/to/ilsvrc12/sourceval.txt" 13 | } 14 | transform_param { 15 | crop_size: 224 16 | #scale: 0.0078125 17 | mean_file: "temp/bgr.binaryproto" 18 | #mean_value: 104.0 19 | #mean_value: 117.0 20 | #mean_value: 123.0 21 | } 22 | include { 23 | phase: TEST 24 | } 25 | } 26 | layer { 27 | name: "data" 28 | type: "ImageData" 29 | top: "data" 30 | top: "label" 31 | image_data_param { 32 | new_dim: 256 33 | bicubic: true 34 | shuffle: true 35 | batch_size: 32 36 | source: "path/to/ilsvrc12/sourcetrain.txt" 37 | } 38 | transform_param { 39 | crop_size: 224 40 | mirror: true 41 | mean_file: "temp/bgr.binaryproto" 42 | #mean_value: 104.0 43 | #mean_value: 117.0 44 | #mean_value: 123.0 45 | } 46 | include { 47 | phase: TRAIN 48 | } 49 | } 50 | 51 | layer { 52 | name: "conv1_1" 53 | type: "Convolution" 54 | bottom: "data" 55 | top: "conv1_1" 56 | convolution_param { 57 | num_output: 24 58 | pad: 1 59 | kernel_size: 3 60 | } 61 | } 62 | layer { 63 | name: "relu1_1" 64 | type: "ReLU" 65 | bottom: "conv1_1" 66 | top: "conv1_1" 67 | } 68 | layer { 69 | name: "conv1_2" 70 | type: "Convolution" 71 | bottom: "conv1_1" 72 | top: "conv1_2" 73 | convolution_param { 74 | num_output: 22 75 | pad: 1 76 | kernel_size: 3 77 | } 78 | } 79 | layer { 80 | name: "relu1_2" 81 | type: "ReLU" 82 | bottom: "conv1_2" 83 | top: "conv1_2" 84 | } 85 | layer { 86 | name: "pool1" 87 | type: "Pooling" 88 | bottom: "conv1_2" 89 | top: "pool1" 90 | pooling_param { 91 | pool: MAX 92 | kernel_size: 2 93 | stride: 2 94 | } 95 | } 96 | layer { 97 | name: "conv2_1" 98 | type: "Convolution" 99 | bottom: "pool1" 100 | top: "conv2_1" 101 | convolution_param { 102 | num_output: 41 103 | pad: 1 104 | kernel_size: 3 105 | } 106 | } 107 | layer { 108 | name: "relu2_1" 109 | type: "ReLU" 110 | bottom: "conv2_1" 111 | top: "conv2_1" 112 | } 113 | layer { 114 | name: "conv2_2" 115 | type: "Convolution" 116 | bottom: "conv2_1" 117 | top: "conv2_2" 118 | convolution_param { 119 | num_output: 51 120 | pad: 1 121 | kernel_size: 3 122 | } 123 | } 124 | layer { 125 | name: "relu2_2" 126 | type: "ReLU" 127 | bottom: "conv2_2" 128 | top: "conv2_2" 129 | } 130 | layer { 131 | name: "pool2" 132 | type: "Pooling" 133 | bottom: "conv2_2" 134 | top: "pool2" 135 | pooling_param { 136 | pool: MAX 137 | kernel_size: 2 138 | stride: 2 139 | } 140 | } 141 | layer { 142 | name: "conv3_1" 143 | type: "Convolution" 144 | bottom: "pool2" 145 | top: "conv3_1" 146 | convolution_param { 147 | num_output: 108 148 | pad: 1 149 | kernel_size: 3 150 | } 151 | } 152 | layer { 153 | name: "relu3_1" 154 | type: "ReLU" 155 | bottom: "conv3_1" 156 | top: "conv3_1" 157 | } 158 | layer { 159 | name: "conv3_2" 160 | type: "Convolution" 161 | bottom: "conv3_1" 162 | top: "conv3_2" 163 | convolution_param { 164 | num_output: 89 165 | pad: 1 166 | kernel_size: 3 167 | } 168 | } 169 | layer { 170 | name: "relu3_2" 171 | type: "ReLU" 172 | bottom: "conv3_2" 173 | top: "conv3_2" 174 | } 175 | layer { 176 | name: "conv3_3" 177 | type: "Convolution" 178 | bottom: "conv3_2" 179 | top: "conv3_3" 180 | convolution_param { 181 | num_output: 111 182 | pad: 1 183 | kernel_size: 3 184 | } 185 | } 186 | layer { 187 | name: "relu3_3" 188 | type: "ReLU" 189 | bottom: "conv3_3" 190 | top: "conv3_3" 191 | } 192 | layer { 193 | name: "pool3" 194 | type: "Pooling" 195 | bottom: "conv3_3" 196 | top: "pool3" 197 | pooling_param { 198 | pool: MAX 199 | kernel_size: 2 200 | stride: 2 201 | } 202 | } 203 | layer { 204 | name: "conv4_1" 205 | type: "Convolution" 206 | bottom: "pool3" 207 | top: "conv4_1" 208 | convolution_param { 209 | num_output: 184 210 | pad: 1 211 | kernel_size: 3 212 | } 213 | } 214 | layer { 215 | name: "relu4_1" 216 | type: "ReLU" 217 | bottom: "conv4_1" 218 | top: "conv4_1" 219 | } 220 | layer { 221 | name: "conv4_2" 222 | type: "Convolution" 223 | bottom: "conv4_1" 224 | top: "conv4_2" 225 | convolution_param { 226 | num_output: 276 227 | pad: 1 228 | kernel_size: 3 229 | } 230 | } 231 | layer { 232 | name: "relu4_2" 233 | type: "ReLU" 234 | bottom: "conv4_2" 235 | top: "conv4_2" 236 | } 237 | layer { 238 | name: "conv4_3" 239 | type: "Convolution" 240 | bottom: "conv4_2" 241 | top: "conv4_3" 242 | convolution_param { 243 | num_output: 228 244 | pad: 1 245 | kernel_size: 3 246 | } 247 | } 248 | layer { 249 | name: "relu4_3" 250 | type: "ReLU" 251 | bottom: "conv4_3" 252 | top: "conv4_3" 253 | } 254 | layer { 255 | name: "pool4" 256 | type: "Pooling" 257 | bottom: "conv4_3" 258 | top: "pool4" 259 | pooling_param { 260 | pool: MAX 261 | kernel_size: 2 262 | stride: 2 263 | } 264 | } 265 | layer { 266 | name: "conv5_1" 267 | type: "Convolution" 268 | bottom: "pool4" 269 | top: "conv5_1" 270 | convolution_param { 271 | num_output: 512 272 | pad: 1 273 | kernel_size: 3 274 | } 275 | } 276 | layer { 277 | name: "relu5_1" 278 | type: "ReLU" 279 | bottom: "conv5_1" 280 | top: "conv5_1" 281 | } 282 | layer { 283 | name: "conv5_2" 284 | type: "Convolution" 285 | bottom: "conv5_1" 286 | top: "conv5_2" 287 | convolution_param { 288 | num_output: 512 289 | pad: 1 290 | kernel_size: 3 291 | } 292 | } 293 | layer { 294 | name: "relu5_2" 295 | type: "ReLU" 296 | bottom: "conv5_2" 297 | top: "conv5_2" 298 | } 299 | layer { 300 | name: "conv5_3" 301 | type: "Convolution" 302 | bottom: "conv5_2" 303 | top: "conv5_3" 304 | convolution_param { 305 | num_output: 512 306 | pad: 1 307 | kernel_size: 3 308 | } 309 | } 310 | layer { 311 | name: "relu5_3" 312 | type: "ReLU" 313 | bottom: "conv5_3" 314 | top: "conv5_3" 315 | } 316 | layer { 317 | name: "pool5" 318 | type: "Pooling" 319 | bottom: "conv5_3" 320 | top: "pool5" 321 | pooling_param { 322 | pool: MAX 323 | kernel_size: 2 324 | stride: 2 325 | } 326 | } 327 | layer { 328 | name: "fc6" 329 | type: "InnerProduct" 330 | bottom: "pool5" 331 | top: "fc6" 332 | inner_product_param { 333 | num_output: 4096 334 | } 335 | } 336 | layer { 337 | name: "relu6" 338 | type: "ReLU" 339 | bottom: "fc6" 340 | top: "fc6" 341 | } 342 | layer { 343 | name: "drop6" 344 | type: "Dropout" 345 | bottom: "fc6" 346 | top: "fc6" 347 | dropout_param { 348 | dropout_ratio: 0.5 349 | } 350 | } 351 | layer { 352 | name: "fc7" 353 | type: "InnerProduct" 354 | bottom: "fc6" 355 | top: "fc7" 356 | inner_product_param { 357 | num_output: 4096 358 | } 359 | } 360 | layer { 361 | name: "relu7" 362 | type: "ReLU" 363 | bottom: "fc7" 364 | top: "fc7" 365 | } 366 | layer { 367 | name: "drop7" 368 | type: "Dropout" 369 | bottom: "fc7" 370 | top: "fc7" 371 | dropout_param { 372 | dropout_ratio: 0.5 373 | } 374 | } 375 | layer { 376 | name: "fc8" 377 | type: "InnerProduct" 378 | bottom: "fc7" 379 | top: "fc8" 380 | inner_product_param { 381 | num_output: 1000 382 | } 383 | } 384 | layer { 385 | name: "loss" 386 | type: "SoftmaxWithLoss" 387 | bottom: "fc8" 388 | bottom: "label" 389 | top: "loss" 390 | } 391 | layer { 392 | name: "accuracy/top1" 393 | type: "Accuracy" 394 | bottom: "fc8" 395 | bottom: "label" 396 | top: "accuracy@1" 397 | accuracy_param { 398 | top_k: 1 399 | } 400 | } 401 | layer { 402 | name: "accuracy/top5" 403 | type: "Accuracy" 404 | bottom: "fc8" 405 | bottom: "label" 406 | top: "accuracy@5" 407 | accuracy_param { 408 | top_k: 5 409 | } 410 | } 411 | -------------------------------------------------------------------------------- /volta-files/models/nin_imagenet_conv.caffemodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:f9e83cd72d418b460f358e57d44d65c2c6a97d9afd1b2c74fad4fc4f4ac754ce 3 | size 30382874 4 | -------------------------------------------------------------------------------- /volta-files/models/nyud-fcn32s-color-heavy-trainval.prototxt: -------------------------------------------------------------------------------- 1 | layer { 2 | name: "data" 3 | type: "Python" 4 | top: "data" 5 | top: "label" 6 | python_param { 7 | module: "nyud_layers" 8 | layer: "NYUDSegDataLayer" 9 | param_str: "{\'tops\': [\'color\', \'label\'], \'seed\': 1337, \'nyud_dir\': \'../data/nyud\', \'split\': \'trainval\'}" 10 | } 11 | } 12 | layer { 13 | name: "conv1_1" 14 | type: "Convolution" 15 | bottom: "data" 16 | top: "conv1_1" 17 | param { 18 | lr_mult: 1 19 | decay_mult: 1 20 | } 21 | param { 22 | lr_mult: 2 23 | decay_mult: 0 24 | } 25 | convolution_param { 26 | num_output: 64 27 | pad: 100 28 | kernel_size: 3 29 | stride: 1 30 | } 31 | } 32 | layer { 33 | name: "relu1_1" 34 | type: "ReLU" 35 | bottom: "conv1_1" 36 | top: "conv1_1" 37 | } 38 | layer { 39 | name: "conv1_2" 40 | type: "Convolution" 41 | bottom: "conv1_1" 42 | top: "conv1_2" 43 | param { 44 | lr_mult: 1 45 | decay_mult: 1 46 | } 47 | param { 48 | lr_mult: 2 49 | decay_mult: 0 50 | } 51 | convolution_param { 52 | num_output: 64 53 | pad: 1 54 | kernel_size: 3 55 | stride: 1 56 | } 57 | } 58 | layer { 59 | name: "relu1_2" 60 | type: "ReLU" 61 | bottom: "conv1_2" 62 | top: "conv1_2" 63 | } 64 | layer { 65 | name: "pool1" 66 | type: "Pooling" 67 | bottom: "conv1_2" 68 | top: "pool1" 69 | pooling_param { 70 | pool: MAX 71 | kernel_size: 2 72 | stride: 2 73 | } 74 | } 75 | layer { 76 | name: "conv2_1" 77 | type: "Convolution" 78 | bottom: "pool1" 79 | top: "conv2_1" 80 | param { 81 | lr_mult: 1 82 | decay_mult: 1 83 | } 84 | param { 85 | lr_mult: 2 86 | decay_mult: 0 87 | } 88 | convolution_param { 89 | num_output: 128 90 | pad: 1 91 | kernel_size: 3 92 | stride: 1 93 | } 94 | } 95 | layer { 96 | name: "relu2_1" 97 | type: "ReLU" 98 | bottom: "conv2_1" 99 | top: "conv2_1" 100 | } 101 | layer { 102 | name: "conv2_2" 103 | type: "Convolution" 104 | bottom: "conv2_1" 105 | top: "conv2_2" 106 | param { 107 | lr_mult: 1 108 | decay_mult: 1 109 | } 110 | param { 111 | lr_mult: 2 112 | decay_mult: 0 113 | } 114 | convolution_param { 115 | num_output: 128 116 | pad: 1 117 | kernel_size: 3 118 | stride: 1 119 | } 120 | } 121 | layer { 122 | name: "relu2_2" 123 | type: "ReLU" 124 | bottom: "conv2_2" 125 | top: "conv2_2" 126 | } 127 | layer { 128 | name: "pool2" 129 | type: "Pooling" 130 | bottom: "conv2_2" 131 | top: "pool2" 132 | pooling_param { 133 | pool: MAX 134 | kernel_size: 2 135 | stride: 2 136 | } 137 | } 138 | layer { 139 | name: "conv3_1" 140 | type: "Convolution" 141 | bottom: "pool2" 142 | top: "conv3_1" 143 | param { 144 | lr_mult: 1 145 | decay_mult: 1 146 | } 147 | param { 148 | lr_mult: 2 149 | decay_mult: 0 150 | } 151 | convolution_param { 152 | num_output: 256 153 | pad: 1 154 | kernel_size: 3 155 | stride: 1 156 | } 157 | } 158 | layer { 159 | name: "relu3_1" 160 | type: "ReLU" 161 | bottom: "conv3_1" 162 | top: "conv3_1" 163 | } 164 | layer { 165 | name: "conv3_2" 166 | type: "Convolution" 167 | bottom: "conv3_1" 168 | top: "conv3_2" 169 | param { 170 | lr_mult: 1 171 | decay_mult: 1 172 | } 173 | param { 174 | lr_mult: 2 175 | decay_mult: 0 176 | } 177 | convolution_param { 178 | num_output: 256 179 | pad: 1 180 | kernel_size: 3 181 | stride: 1 182 | } 183 | } 184 | layer { 185 | name: "relu3_2" 186 | type: "ReLU" 187 | bottom: "conv3_2" 188 | top: "conv3_2" 189 | } 190 | layer { 191 | name: "conv3_3" 192 | type: "Convolution" 193 | bottom: "conv3_2" 194 | top: "conv3_3" 195 | param { 196 | lr_mult: 1 197 | decay_mult: 1 198 | } 199 | param { 200 | lr_mult: 2 201 | decay_mult: 0 202 | } 203 | convolution_param { 204 | num_output: 256 205 | pad: 1 206 | kernel_size: 3 207 | stride: 1 208 | } 209 | } 210 | layer { 211 | name: "relu3_3" 212 | type: "ReLU" 213 | bottom: "conv3_3" 214 | top: "conv3_3" 215 | } 216 | layer { 217 | name: "pool3" 218 | type: "Pooling" 219 | bottom: "conv3_3" 220 | top: "pool3" 221 | pooling_param { 222 | pool: MAX 223 | kernel_size: 2 224 | stride: 2 225 | } 226 | } 227 | layer { 228 | name: "conv4_1" 229 | type: "Convolution" 230 | bottom: "pool3" 231 | top: "conv4_1" 232 | param { 233 | lr_mult: 1 234 | decay_mult: 1 235 | } 236 | param { 237 | lr_mult: 2 238 | decay_mult: 0 239 | } 240 | convolution_param { 241 | num_output: 512 242 | pad: 1 243 | kernel_size: 3 244 | stride: 1 245 | } 246 | } 247 | layer { 248 | name: "relu4_1" 249 | type: "ReLU" 250 | bottom: "conv4_1" 251 | top: "conv4_1" 252 | } 253 | layer { 254 | name: "conv4_2" 255 | type: "Convolution" 256 | bottom: "conv4_1" 257 | top: "conv4_2" 258 | param { 259 | lr_mult: 1 260 | decay_mult: 1 261 | } 262 | param { 263 | lr_mult: 2 264 | decay_mult: 0 265 | } 266 | convolution_param { 267 | num_output: 512 268 | pad: 1 269 | kernel_size: 3 270 | stride: 1 271 | } 272 | } 273 | layer { 274 | name: "relu4_2" 275 | type: "ReLU" 276 | bottom: "conv4_2" 277 | top: "conv4_2" 278 | } 279 | layer { 280 | name: "conv4_3" 281 | type: "Convolution" 282 | bottom: "conv4_2" 283 | top: "conv4_3" 284 | param { 285 | lr_mult: 1 286 | decay_mult: 1 287 | } 288 | param { 289 | lr_mult: 2 290 | decay_mult: 0 291 | } 292 | convolution_param { 293 | num_output: 512 294 | pad: 1 295 | kernel_size: 3 296 | stride: 1 297 | } 298 | } 299 | layer { 300 | name: "relu4_3" 301 | type: "ReLU" 302 | bottom: "conv4_3" 303 | top: "conv4_3" 304 | } 305 | layer { 306 | name: "pool4" 307 | type: "Pooling" 308 | bottom: "conv4_3" 309 | top: "pool4" 310 | pooling_param { 311 | pool: MAX 312 | kernel_size: 2 313 | stride: 2 314 | } 315 | } 316 | layer { 317 | name: "conv5_1" 318 | type: "Convolution" 319 | bottom: "pool4" 320 | top: "conv5_1" 321 | param { 322 | lr_mult: 1 323 | decay_mult: 1 324 | } 325 | param { 326 | lr_mult: 2 327 | decay_mult: 0 328 | } 329 | convolution_param { 330 | num_output: 512 331 | pad: 1 332 | kernel_size: 3 333 | stride: 1 334 | } 335 | } 336 | layer { 337 | name: "relu5_1" 338 | type: "ReLU" 339 | bottom: "conv5_1" 340 | top: "conv5_1" 341 | } 342 | layer { 343 | name: "conv5_2" 344 | type: "Convolution" 345 | bottom: "conv5_1" 346 | top: "conv5_2" 347 | param { 348 | lr_mult: 1 349 | decay_mult: 1 350 | } 351 | param { 352 | lr_mult: 2 353 | decay_mult: 0 354 | } 355 | convolution_param { 356 | num_output: 512 357 | pad: 1 358 | kernel_size: 3 359 | stride: 1 360 | } 361 | } 362 | layer { 363 | name: "relu5_2" 364 | type: "ReLU" 365 | bottom: "conv5_2" 366 | top: "conv5_2" 367 | } 368 | layer { 369 | name: "conv5_3" 370 | type: "Convolution" 371 | bottom: "conv5_2" 372 | top: "conv5_3" 373 | param { 374 | lr_mult: 1 375 | decay_mult: 1 376 | } 377 | param { 378 | lr_mult: 2 379 | decay_mult: 0 380 | } 381 | convolution_param { 382 | num_output: 512 383 | pad: 1 384 | kernel_size: 3 385 | stride: 1 386 | } 387 | } 388 | layer { 389 | name: "relu5_3" 390 | type: "ReLU" 391 | bottom: "conv5_3" 392 | top: "conv5_3" 393 | } 394 | layer { 395 | name: "pool5" 396 | type: "Pooling" 397 | bottom: "conv5_3" 398 | top: "pool5" 399 | pooling_param { 400 | pool: MAX 401 | kernel_size: 2 402 | stride: 2 403 | } 404 | } 405 | layer { 406 | name: "fc6" 407 | type: "Convolution" 408 | bottom: "pool5" 409 | top: "fc6" 410 | param { 411 | lr_mult: 1 412 | decay_mult: 1 413 | } 414 | param { 415 | lr_mult: 2 416 | decay_mult: 0 417 | } 418 | convolution_param { 419 | num_output: 4096 420 | pad: 0 421 | kernel_size: 7 422 | stride: 1 423 | } 424 | } 425 | layer { 426 | name: "relu6" 427 | type: "ReLU" 428 | bottom: "fc6" 429 | top: "fc6" 430 | } 431 | layer { 432 | name: "drop6" 433 | type: "Dropout" 434 | bottom: "fc6" 435 | top: "fc6" 436 | dropout_param { 437 | dropout_ratio: 0.5 438 | } 439 | } 440 | layer { 441 | name: "fc7" 442 | type: "Convolution" 443 | bottom: "fc6" 444 | top: "fc7" 445 | param { 446 | lr_mult: 1 447 | decay_mult: 1 448 | } 449 | param { 450 | lr_mult: 2 451 | decay_mult: 0 452 | } 453 | convolution_param { 454 | num_output: 4096 455 | pad: 0 456 | kernel_size: 1 457 | stride: 1 458 | } 459 | } 460 | layer { 461 | name: "relu7" 462 | type: "ReLU" 463 | bottom: "fc7" 464 | top: "fc7" 465 | } 466 | layer { 467 | name: "drop7" 468 | type: "Dropout" 469 | bottom: "fc7" 470 | top: "fc7" 471 | dropout_param { 472 | dropout_ratio: 0.5 473 | } 474 | } 475 | layer { 476 | name: "score_fr" 477 | type: "Convolution" 478 | bottom: "fc7" 479 | top: "score_fr" 480 | param { 481 | lr_mult: 1 482 | decay_mult: 1 483 | } 484 | param { 485 | lr_mult: 2 486 | decay_mult: 0 487 | } 488 | convolution_param { 489 | num_output: 40 490 | pad: 0 491 | kernel_size: 1 492 | } 493 | } 494 | layer { 495 | name: "upscore" 496 | type: "Deconvolution" 497 | bottom: "score_fr" 498 | top: "upscore" 499 | param { 500 | lr_mult: 0 501 | } 502 | convolution_param { 503 | num_output: 40 504 | bias_term: false 505 | kernel_size: 64 506 | stride: 32 507 | } 508 | } 509 | layer { 510 | name: "score" 511 | type: "Crop" 512 | bottom: "upscore" 513 | bottom: "data" 514 | top: "score" 515 | crop_param { 516 | axis: 2 517 | offset: 19 518 | } 519 | } 520 | layer { 521 | name: "loss" 522 | type: "SoftmaxWithLoss" 523 | bottom: "score" 524 | bottom: "label" 525 | top: "loss" 526 | loss_param { 527 | ignore_label: 255 528 | normalize: false 529 | } 530 | } 531 | -------------------------------------------------------------------------------- /volta-files/models/nyud-fcn32s-color-heavy.caffemodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:c08763827d0ef76c275084a5e2c5fd254054789a29fd31320cfea9ffc52b8714 3 | size 563915216 4 | -------------------------------------------------------------------------------- /volta-files/models/train_val.prototxt: -------------------------------------------------------------------------------- 1 | name: "nin_imagenet" 2 | layers { 3 | top: "data" 4 | top: "label" 5 | name: "data" 6 | type: DATA 7 | data_param { 8 | source: "/home/linmin/IMAGENET-LMDB/imagenet-train-lmdb" 9 | backend: LMDB 10 | batch_size: 64 11 | } 12 | transform_param { 13 | crop_size: 224 14 | mirror: true 15 | mean_file: "/home/linmin/IMAGENET-LMDB/imagenet-train-mean" 16 | } 17 | include: { phase: TRAIN } 18 | } 19 | layers { 20 | top: "data" 21 | top: "label" 22 | name: "data" 23 | type: DATA 24 | data_param { 25 | source: "/home/linmin/IMAGENET-LMDB/imagenet-val-lmdb" 26 | backend: LMDB 27 | batch_size: 89 28 | } 29 | transform_param { 30 | crop_size: 224 31 | mirror: false 32 | mean_file: "/home/linmin/IMAGENET-LMDB/imagenet-train-mean" 33 | } 34 | include: { phase: TEST } 35 | } 36 | layers { 37 | bottom: "data" 38 | top: "conv1" 39 | name: "conv1" 40 | type: CONVOLUTION 41 | blobs_lr: 1 42 | blobs_lr: 2 43 | weight_decay: 1 44 | weight_decay: 0 45 | convolution_param { 46 | num_output: 96 47 | kernel_size: 11 48 | stride: 4 49 | weight_filler { 50 | type: "gaussian" 51 | mean: 0 52 | std: 0.01 53 | } 54 | bias_filler { 55 | type: "constant" 56 | value: 0 57 | } 58 | } 59 | } 60 | layers { 61 | bottom: "conv1" 62 | top: "conv1" 63 | name: "relu0" 64 | type: RELU 65 | } 66 | layers { 67 | bottom: "conv1" 68 | top: "cccp1" 69 | name: "cccp1" 70 | type: CONVOLUTION 71 | blobs_lr: 1 72 | blobs_lr: 2 73 | weight_decay: 1 74 | weight_decay: 0 75 | convolution_param { 76 | num_output: 96 77 | kernel_size: 1 78 | stride: 1 79 | weight_filler { 80 | type: "gaussian" 81 | mean: 0 82 | std: 0.05 83 | } 84 | bias_filler { 85 | type: "constant" 86 | value: 0 87 | } 88 | } 89 | } 90 | layers { 91 | bottom: "cccp1" 92 | top: "cccp1" 93 | name: "relu1" 94 | type: RELU 95 | } 96 | layers { 97 | bottom: "cccp1" 98 | top: "cccp2" 99 | name: "cccp2" 100 | type: CONVOLUTION 101 | blobs_lr: 1 102 | blobs_lr: 2 103 | weight_decay: 1 104 | weight_decay: 0 105 | convolution_param { 106 | num_output: 96 107 | kernel_size: 1 108 | stride: 1 109 | weight_filler { 110 | type: "gaussian" 111 | mean: 0 112 | std: 0.05 113 | } 114 | bias_filler { 115 | type: "constant" 116 | value: 0 117 | } 118 | } 119 | } 120 | layers { 121 | bottom: "cccp2" 122 | top: "cccp2" 123 | name: "relu2" 124 | type: RELU 125 | } 126 | layers { 127 | bottom: "cccp2" 128 | top: "pool1" 129 | name: "pool1" 130 | type: POOLING 131 | pooling_param { 132 | pool: MAX 133 | kernel_size: 3 134 | stride: 2 135 | } 136 | } 137 | layers { 138 | bottom: "pool1" 139 | top: "conv2" 140 | name: "conv2" 141 | type: CONVOLUTION 142 | blobs_lr: 1 143 | blobs_lr: 2 144 | weight_decay: 1 145 | weight_decay: 0 146 | convolution_param { 147 | num_output: 256 148 | pad: 2 149 | kernel_size: 5 150 | stride: 1 151 | weight_filler { 152 | type: "gaussian" 153 | mean: 0 154 | std: 0.05 155 | } 156 | bias_filler { 157 | type: "constant" 158 | value: 0 159 | } 160 | } 161 | } 162 | layers { 163 | bottom: "conv2" 164 | top: "conv2" 165 | name: "relu3" 166 | type: RELU 167 | } 168 | layers { 169 | bottom: "conv2" 170 | top: "cccp3" 171 | name: "cccp3" 172 | type: CONVOLUTION 173 | blobs_lr: 1 174 | blobs_lr: 2 175 | weight_decay: 1 176 | weight_decay: 0 177 | convolution_param { 178 | num_output: 256 179 | kernel_size: 1 180 | stride: 1 181 | weight_filler { 182 | type: "gaussian" 183 | mean: 0 184 | std: 0.05 185 | } 186 | bias_filler { 187 | type: "constant" 188 | value: 0 189 | } 190 | } 191 | } 192 | layers { 193 | bottom: "cccp3" 194 | top: "cccp3" 195 | name: "relu5" 196 | type: RELU 197 | } 198 | layers { 199 | bottom: "cccp3" 200 | top: "cccp4" 201 | name: "cccp4" 202 | type: CONVOLUTION 203 | blobs_lr: 1 204 | blobs_lr: 2 205 | weight_decay: 1 206 | weight_decay: 0 207 | convolution_param { 208 | num_output: 256 209 | kernel_size: 1 210 | stride: 1 211 | weight_filler { 212 | type: "gaussian" 213 | mean: 0 214 | std: 0.05 215 | } 216 | bias_filler { 217 | type: "constant" 218 | value: 0 219 | } 220 | } 221 | } 222 | layers { 223 | bottom: "cccp4" 224 | top: "cccp4" 225 | name: "relu6" 226 | type: RELU 227 | } 228 | layers { 229 | bottom: "cccp4" 230 | top: "pool2" 231 | name: "pool2" 232 | type: POOLING 233 | pooling_param { 234 | pool: MAX 235 | kernel_size: 3 236 | stride: 2 237 | } 238 | } 239 | layers { 240 | bottom: "pool2" 241 | top: "conv3" 242 | name: "conv3" 243 | type: CONVOLUTION 244 | blobs_lr: 1 245 | blobs_lr: 2 246 | weight_decay: 1 247 | weight_decay: 0 248 | convolution_param { 249 | num_output: 384 250 | pad: 1 251 | kernel_size: 3 252 | stride: 1 253 | weight_filler { 254 | type: "gaussian" 255 | mean: 0 256 | std: 0.01 257 | } 258 | bias_filler { 259 | type: "constant" 260 | value: 0 261 | } 262 | } 263 | } 264 | layers { 265 | bottom: "conv3" 266 | top: "conv3" 267 | name: "relu7" 268 | type: RELU 269 | } 270 | layers { 271 | bottom: "conv3" 272 | top: "cccp5" 273 | name: "cccp5" 274 | type: CONVOLUTION 275 | blobs_lr: 1 276 | blobs_lr: 2 277 | weight_decay: 1 278 | weight_decay: 0 279 | convolution_param { 280 | num_output: 384 281 | kernel_size: 1 282 | stride: 1 283 | weight_filler { 284 | type: "gaussian" 285 | mean: 0 286 | std: 0.05 287 | } 288 | bias_filler { 289 | type: "constant" 290 | value: 0 291 | } 292 | } 293 | } 294 | layers { 295 | bottom: "cccp5" 296 | top: "cccp5" 297 | name: "relu8" 298 | type: RELU 299 | } 300 | layers { 301 | bottom: "cccp5" 302 | top: "cccp6" 303 | name: "cccp6" 304 | type: CONVOLUTION 305 | blobs_lr: 1 306 | blobs_lr: 2 307 | weight_decay: 1 308 | weight_decay: 0 309 | convolution_param { 310 | num_output: 384 311 | kernel_size: 1 312 | stride: 1 313 | weight_filler { 314 | type: "gaussian" 315 | mean: 0 316 | std: 0.05 317 | } 318 | bias_filler { 319 | type: "constant" 320 | value: 0 321 | } 322 | } 323 | } 324 | layers { 325 | bottom: "cccp6" 326 | top: "cccp6" 327 | name: "relu9" 328 | type: RELU 329 | } 330 | layers { 331 | bottom: "cccp6" 332 | top: "pool3" 333 | name: "pool3" 334 | type: POOLING 335 | pooling_param { 336 | pool: MAX 337 | kernel_size: 3 338 | stride: 2 339 | } 340 | } 341 | layers { 342 | bottom: "pool3" 343 | top: "pool3" 344 | name: "drop" 345 | type: DROPOUT 346 | dropout_param { 347 | dropout_ratio: 0.5 348 | } 349 | } 350 | layers { 351 | bottom: "pool3" 352 | top: "conv4" 353 | name: "conv4-1024" 354 | type: CONVOLUTION 355 | blobs_lr: 1 356 | blobs_lr: 2 357 | weight_decay: 1 358 | weight_decay: 0 359 | convolution_param { 360 | num_output: 1024 361 | pad: 1 362 | kernel_size: 3 363 | stride: 1 364 | weight_filler { 365 | type: "gaussian" 366 | mean: 0 367 | std: 0.05 368 | } 369 | bias_filler { 370 | type: "constant" 371 | value: 0 372 | } 373 | } 374 | } 375 | layers { 376 | bottom: "conv4" 377 | top: "conv4" 378 | name: "relu10" 379 | type: RELU 380 | } 381 | layers { 382 | bottom: "conv4" 383 | top: "cccp7" 384 | name: "cccp7-1024" 385 | type: CONVOLUTION 386 | blobs_lr: 1 387 | blobs_lr: 2 388 | weight_decay: 1 389 | weight_decay: 0 390 | convolution_param { 391 | num_output: 1024 392 | kernel_size: 1 393 | stride: 1 394 | weight_filler { 395 | type: "gaussian" 396 | mean: 0 397 | std: 0.05 398 | } 399 | bias_filler { 400 | type: "constant" 401 | value: 0 402 | } 403 | } 404 | } 405 | layers { 406 | bottom: "cccp7" 407 | top: "cccp7" 408 | name: "relu11" 409 | type: RELU 410 | } 411 | layers { 412 | bottom: "cccp7" 413 | top: "cccp8" 414 | name: "cccp8-1024" 415 | type: CONVOLUTION 416 | blobs_lr: 1 417 | blobs_lr: 2 418 | weight_decay: 1 419 | weight_decay: 0 420 | convolution_param { 421 | num_output: 1000 422 | kernel_size: 1 423 | stride: 1 424 | weight_filler { 425 | type: "gaussian" 426 | mean: 0 427 | std: 0.01 428 | } 429 | bias_filler { 430 | type: "constant" 431 | value: 0 432 | } 433 | } 434 | } 435 | layers { 436 | bottom: "cccp8" 437 | top: "cccp8" 438 | name: "relu12" 439 | type: RELU 440 | } 441 | layers { 442 | bottom: "cccp8" 443 | top: "pool4" 444 | name: "pool4" 445 | type: POOLING 446 | pooling_param { 447 | pool: AVE 448 | kernel_size: 6 449 | stride: 1 450 | } 451 | } 452 | layers { 453 | name: "accuracy" 454 | type: ACCURACY 455 | bottom: "pool4" 456 | bottom: "label" 457 | top: "accuracy" 458 | include: { phase: TEST } 459 | } 460 | layers { 461 | bottom: "pool4" 462 | bottom: "label" 463 | name: "loss" 464 | type: SOFTMAX_LOSS 465 | include: { phase: TRAIN } 466 | } 467 | -------------------------------------------------------------------------------- /volta-files/models/vgg_normalised.caffemodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:2e0fb14efd38e98c6889e288d81a6382a2da1f5716587507e5fc4c46779b0c87 3 | size 80099414 4 | -------------------------------------------------------------------------------- /volta-files/neural_style_dir_rng_fix.lua: -------------------------------------------------------------------------------- 1 | -- This modified version of Neural-Style was created by github.com/ProGamerGov on 2017-09-29 2 | -- Use: "luarocks install paths" to install the required package. 3 | -- The -style_image parameter will now automatically determine if the input is a directory, or a string of one or more images. 4 | 5 | -- Code from: https://github.com/jcjohnson/neural-style/pull/408 6 | -- The NIN ImageNet model uses dropout layers with random values, 7 | -- so this version of neural_style.lua removes the unneeded dropout layers entirely. 8 | 9 | require 'torch' 10 | require 'nn' 11 | require 'image' 12 | require 'optim' 13 | require 'paths' 14 | 15 | require 'loadcaffe' 16 | 17 | 18 | local cmd = torch.CmdLine() 19 | 20 | -- Basic options 21 | cmd:option('-style_image', 'examples/inputs/seated-nude.jpg', 22 | 'Style target image or directory') 23 | cmd:option('-style_blend_weights', 'nil') 24 | cmd:option('-content_image', 'examples/inputs/tubingen.jpg', 25 | 'Content target image') 26 | cmd:option('-image_size', 512, 'Maximum height / width of generated image') 27 | cmd:option('-gpu', '0', 'Zero-indexed ID of the GPU to use; for CPU mode set -gpu = -1') 28 | cmd:option('-multigpu_strategy', '', 'Index of layers to split the network across GPUs') 29 | 30 | -- Optimization options 31 | cmd:option('-content_weight', 5e0) 32 | cmd:option('-style_weight', 1e2) 33 | cmd:option('-tv_weight', 1e-3) 34 | cmd:option('-num_iterations', 1000) 35 | cmd:option('-normalize_gradients', false) 36 | cmd:option('-init', 'random', 'random|image') 37 | cmd:option('-init_image', '') 38 | cmd:option('-optimizer', 'lbfgs', 'lbfgs|adam') 39 | cmd:option('-learning_rate', 1e1) 40 | cmd:option('-lbfgs_num_correction', 0) 41 | 42 | -- Output options 43 | cmd:option('-print_iter', 50) 44 | cmd:option('-save_iter', 100) 45 | cmd:option('-output_image', 'out.png') 46 | 47 | -- Other options 48 | cmd:option('-style_scale', 1.0) 49 | cmd:option('-original_colors', 0) 50 | cmd:option('-pooling', 'max', 'max|avg') 51 | cmd:option('-proto_file', 'models/VGG_ILSVRC_19_layers_deploy.prototxt') 52 | cmd:option('-model_file', 'models/VGG_ILSVRC_19_layers.caffemodel') 53 | cmd:option('-backend', 'nn', 'nn|cudnn|clnn') 54 | cmd:option('-cudnn_autotune', false) 55 | cmd:option('-seed', -1) 56 | 57 | cmd:option('-content_layers', 'relu4_2', 'layers for content') 58 | cmd:option('-style_layers', 'relu1_1,relu2_1,relu3_1,relu4_1,relu5_1', 'layers for style') 59 | 60 | 61 | local function main(params) 62 | local dtype, multigpu = setup_gpu(params) 63 | 64 | local loadcaffe_backend = params.backend 65 | if params.backend == 'clnn' then loadcaffe_backend = 'nn' end 66 | local cnn = loadcaffe.load(params.proto_file, params.model_file, loadcaffe_backend):type(dtype) 67 | 68 | local content_image = image.load(params.content_image, 3) 69 | content_image = image.scale(content_image, params.image_size, 'bilinear') 70 | local content_image_caffe = preprocess(content_image):float() 71 | 72 | local style_size = math.ceil(params.style_scale * params.image_size) 73 | local style_image_list, style_input_sorted 74 | local p = 1 75 | local style_input = params.style_image:split(',') 76 | while p <= #style_input do 77 | if not paths.dirp(style_input[p])then 78 | style_input_sorted = (style_input[p]) 79 | p = p + 1 80 | elseif paths.dirp(style_input[p])then 81 | style_input_sorted = styleLoader(style_input[p]) 82 | p = p + 1 83 | end 84 | if p == 2 then 85 | style_image_list = style_input_sorted 86 | else 87 | style_image_list = style_image_list .. "," .. style_input_sorted 88 | end 89 | end 90 | style_image_list = style_image_list:split(',') 91 | 92 | local style_images_caffe = {} 93 | for _, img_path in ipairs(style_image_list) do 94 | local img = image.load(img_path, 3) 95 | img = image.scale(img, style_size, 'bilinear') 96 | local img_caffe = preprocess(img):float() 97 | table.insert(style_images_caffe, img_caffe) 98 | end 99 | 100 | local init_image = nil 101 | if params.init_image ~= '' then 102 | init_image = image.load(params.init_image, 3) 103 | local H, W = content_image:size(2), content_image:size(3) 104 | init_image = image.scale(init_image, W, H, 'bilinear') 105 | init_image = preprocess(init_image):float() 106 | end 107 | 108 | -- Handle style blending weights for multiple style inputs 109 | local style_blend_weights = nil 110 | if params.style_blend_weights == 'nil' then 111 | -- Style blending not specified, so use equal weighting 112 | style_blend_weights = {} 113 | for i = 1, #style_image_list do 114 | table.insert(style_blend_weights, 1.0) 115 | end 116 | else 117 | style_blend_weights = params.style_blend_weights:split(',') 118 | assert(#style_blend_weights == #style_image_list, 119 | '-style_blend_weights and -style_images must have the same number of elements') 120 | end 121 | -- Normalize the style blending weights so they sum to 1 122 | local style_blend_sum = 0 123 | for i = 1, #style_blend_weights do 124 | style_blend_weights[i] = tonumber(style_blend_weights[i]) 125 | style_blend_sum = style_blend_sum + style_blend_weights[i] 126 | end 127 | for i = 1, #style_blend_weights do 128 | style_blend_weights[i] = style_blend_weights[i] / style_blend_sum 129 | end 130 | 131 | local content_layers = params.content_layers:split(",") 132 | local style_layers = params.style_layers:split(",") 133 | 134 | -- Set up the network, inserting style and content loss modules 135 | local content_losses, style_losses = {}, {} 136 | local next_content_idx, next_style_idx = 1, 1 137 | local net = nn.Sequential() 138 | if params.tv_weight > 0 then 139 | local tv_mod = nn.TVLoss(params.tv_weight):type(dtype) 140 | net:add(tv_mod) 141 | end 142 | for i = 1, #cnn do 143 | if next_content_idx <= #content_layers or next_style_idx <= #style_layers then 144 | local layer = cnn:get(i) 145 | local name = layer.name 146 | local layer_type = torch.type(layer) 147 | local is_pooling = (layer_type == 'cudnn.SpatialMaxPooling' or layer_type == 'nn.SpatialMaxPooling') 148 | if is_dropout then 149 | local msg = 'Removing dropout at layer %d' 150 | print(string.format(msg, i)) 151 | elseif is_pooling and params.pooling == 'avg' then 152 | assert(layer.padW == 0 and layer.padH == 0) 153 | local kW, kH = layer.kW, layer.kH 154 | local dW, dH = layer.dW, layer.dH 155 | local avg_pool_layer = nn.SpatialAveragePooling(kW, kH, dW, dH):type(dtype) 156 | local msg = 'Replacing max pooling at layer %d with average pooling' 157 | print(string.format(msg, i)) 158 | net:add(avg_pool_layer) 159 | else 160 | net:add(layer) 161 | end 162 | if name == content_layers[next_content_idx] then 163 | print("Setting up content layer", i, ":", layer.name) 164 | local norm = params.normalize_gradients 165 | local loss_module = nn.ContentLoss(params.content_weight, norm):type(dtype) 166 | net:add(loss_module) 167 | table.insert(content_losses, loss_module) 168 | next_content_idx = next_content_idx + 1 169 | end 170 | if name == style_layers[next_style_idx] then 171 | print("Setting up style layer ", i, ":", layer.name) 172 | local norm = params.normalize_gradients 173 | local loss_module = nn.StyleLoss(params.style_weight, norm):type(dtype) 174 | net:add(loss_module) 175 | table.insert(style_losses, loss_module) 176 | next_style_idx = next_style_idx + 1 177 | end 178 | end 179 | end 180 | if multigpu then 181 | net = setup_multi_gpu(net, params) 182 | end 183 | net:type(dtype) 184 | 185 | -- Capture content targets 186 | for i = 1, #content_losses do 187 | content_losses[i].mode = 'capture' 188 | end 189 | print 'Capturing content targets' 190 | print(net) 191 | content_image_caffe = content_image_caffe:type(dtype) 192 | net:forward(content_image_caffe:type(dtype)) 193 | 194 | -- Capture style targets 195 | for i = 1, #content_losses do 196 | content_losses[i].mode = 'none' 197 | end 198 | for i = 1, #style_images_caffe do 199 | print(string.format('Capturing style target %d', i)) 200 | for j = 1, #style_losses do 201 | style_losses[j].mode = 'capture' 202 | style_losses[j].blend_weight = style_blend_weights[i] 203 | end 204 | net:forward(style_images_caffe[i]:type(dtype)) 205 | end 206 | 207 | -- Set all loss modules to loss mode 208 | for i = 1, #content_losses do 209 | content_losses[i].mode = 'loss' 210 | end 211 | for i = 1, #style_losses do 212 | style_losses[i].mode = 'loss' 213 | end 214 | 215 | -- We don't need the base CNN anymore, so clean it up to save memory. 216 | cnn = nil 217 | for i=1, #net.modules do 218 | local module = net.modules[i] 219 | if torch.type(module) == 'nn.SpatialConvolutionMM' then 220 | -- remove these, not used, but uses gpu memory 221 | module.gradWeight = nil 222 | module.gradBias = nil 223 | end 224 | end 225 | collectgarbage() 226 | 227 | -- Initialize the image 228 | if params.seed >= 0 then 229 | torch.manualSeed(params.seed) 230 | end 231 | local img = nil 232 | if params.init == 'random' then 233 | img = torch.randn(content_image:size()):float():mul(0.001) 234 | elseif params.init == 'image' then 235 | if init_image then 236 | img = init_image:clone() 237 | else 238 | img = content_image_caffe:clone() 239 | end 240 | else 241 | error('Invalid init type') 242 | end 243 | img = img:type(dtype) 244 | 245 | -- Run it through the network once to get the proper size for the gradient 246 | -- All the gradients will come from the extra loss modules, so we just pass 247 | -- zeros into the top of the net on the backward pass. 248 | local y = net:forward(img) 249 | local dy = img.new(#y):zero() 250 | 251 | -- Declaring this here lets us access it in maybe_print 252 | local optim_state = nil 253 | if params.optimizer == 'lbfgs' then 254 | optim_state = { 255 | maxIter = params.num_iterations, 256 | verbose=true, 257 | tolX=-1, 258 | tolFun=-1, 259 | } 260 | if params.lbfgs_num_correction > 0 then 261 | optim_state.nCorrection = params.lbfgs_num_correction 262 | end 263 | elseif params.optimizer == 'adam' then 264 | optim_state = { 265 | learningRate = params.learning_rate, 266 | } 267 | else 268 | error(string.format('Unrecognized optimizer "%s"', params.optimizer)) 269 | end 270 | 271 | local function maybe_print(t, loss) 272 | local verbose = (params.print_iter > 0 and t % params.print_iter == 0) 273 | if verbose then 274 | print(string.format('Iteration %d / %d', t, params.num_iterations)) 275 | for i, loss_module in ipairs(content_losses) do 276 | print(string.format(' Content %d loss: %f', i, loss_module.loss)) 277 | end 278 | for i, loss_module in ipairs(style_losses) do 279 | print(string.format(' Style %d loss: %f', i, loss_module.loss)) 280 | end 281 | print(string.format(' Total loss: %f', loss)) 282 | end 283 | end 284 | 285 | local function maybe_save(t) 286 | local should_save = params.save_iter > 0 and t % params.save_iter == 0 287 | should_save = should_save or t == params.num_iterations 288 | if should_save then 289 | local disp = deprocess(img:double()) 290 | disp = image.minmax{tensor=disp, min=0, max=1} 291 | local filename = build_filename(params.output_image, t) 292 | if t == params.num_iterations then 293 | filename = params.output_image 294 | end 295 | 296 | -- Maybe perform postprocessing for color-independent style transfer 297 | if params.original_colors == 1 then 298 | disp = original_colors(content_image, disp) 299 | end 300 | 301 | image.save(filename, disp) 302 | end 303 | end 304 | 305 | -- Function to evaluate loss and gradient. We run the net forward and 306 | -- backward to get the gradient, and sum up losses from the loss modules. 307 | -- optim.lbfgs internally handles iteration and calls this function many 308 | -- times, so we manually count the number of iterations to handle printing 309 | -- and saving intermediate results. 310 | local num_calls = 0 311 | local function feval(x) 312 | num_calls = num_calls + 1 313 | net:forward(x) 314 | local grad = net:updateGradInput(x, dy) 315 | local loss = 0 316 | for _, mod in ipairs(content_losses) do 317 | loss = loss + mod.loss 318 | end 319 | for _, mod in ipairs(style_losses) do 320 | loss = loss + mod.loss 321 | end 322 | maybe_print(num_calls, loss) 323 | maybe_save(num_calls) 324 | 325 | collectgarbage() 326 | -- optim.lbfgs expects a vector for gradients 327 | return loss, grad:view(grad:nElement()) 328 | end 329 | 330 | -- Run optimization. 331 | if params.optimizer == 'lbfgs' then 332 | print('Running optimization with L-BFGS') 333 | local x, losses = optim.lbfgs(feval, img, optim_state) 334 | elseif params.optimizer == 'adam' then 335 | print('Running optimization with ADAM') 336 | for t = 1, params.num_iterations do 337 | local x, losses = optim.adam(feval, img, optim_state) 338 | end 339 | end 340 | end 341 | 342 | 343 | function setup_gpu(params) 344 | local multigpu = false 345 | if params.gpu:find(',') then 346 | multigpu = true 347 | params.gpu = params.gpu:split(',') 348 | for i = 1, #params.gpu do 349 | params.gpu[i] = tonumber(params.gpu[i]) + 1 350 | end 351 | else 352 | params.gpu = tonumber(params.gpu) + 1 353 | end 354 | local dtype = 'torch.FloatTensor' 355 | if multigpu or params.gpu > 0 then 356 | if params.backend ~= 'clnn' then 357 | require 'cutorch' 358 | require 'cunn' 359 | if multigpu then 360 | cutorch.setDevice(params.gpu[1]) 361 | else 362 | cutorch.setDevice(params.gpu) 363 | end 364 | dtype = 'torch.CudaTensor' 365 | else 366 | require 'clnn' 367 | require 'cltorch' 368 | if multigpu then 369 | cltorch.setDevice(params.gpu[1]) 370 | else 371 | cltorch.setDevice(params.gpu) 372 | end 373 | dtype = torch.Tensor():cl():type() 374 | end 375 | else 376 | params.backend = 'nn' 377 | end 378 | 379 | if params.backend == 'cudnn' then 380 | require 'cudnn' 381 | if params.cudnn_autotune then 382 | cudnn.benchmark = true 383 | end 384 | cudnn.SpatialConvolution.accGradParameters = nn.SpatialConvolutionMM.accGradParameters -- ie: nop 385 | end 386 | return dtype, multigpu 387 | end 388 | 389 | 390 | function setup_multi_gpu(net, params) 391 | local DEFAULT_STRATEGIES = { 392 | [2] = {3}, 393 | } 394 | local gpu_splits = nil 395 | if params.multigpu_strategy == '' then 396 | -- Use a default strategy 397 | gpu_splits = DEFAULT_STRATEGIES[#params.gpu] 398 | -- Offset the default strategy by one if we are using TV 399 | if params.tv_weight > 0 then 400 | for i = 1, #gpu_splits do gpu_splits[i] = gpu_splits[i] + 1 end 401 | end 402 | else 403 | -- Use the user-specified multigpu strategy 404 | gpu_splits = params.multigpu_strategy:split(',') 405 | for i = 1, #gpu_splits do 406 | gpu_splits[i] = tonumber(gpu_splits[i]) 407 | end 408 | end 409 | assert(gpu_splits ~= nil, 'Must specify -multigpu_strategy') 410 | local gpus = params.gpu 411 | 412 | local cur_chunk = nn.Sequential() 413 | local chunks = {} 414 | for i = 1, #net do 415 | cur_chunk:add(net:get(i)) 416 | if i == gpu_splits[1] then 417 | table.remove(gpu_splits, 1) 418 | table.insert(chunks, cur_chunk) 419 | cur_chunk = nn.Sequential() 420 | end 421 | end 422 | table.insert(chunks, cur_chunk) 423 | assert(#chunks == #gpus) 424 | 425 | local new_net = nn.Sequential() 426 | for i = 1, #chunks do 427 | local out_device = nil 428 | if i == #chunks then 429 | out_device = gpus[1] 430 | end 431 | new_net:add(nn.GPU(chunks[i], gpus[i], out_device)) 432 | end 433 | 434 | return new_net 435 | end 436 | 437 | 438 | function build_filename(output_image, iteration) 439 | local ext = paths.extname(output_image) 440 | local basename = paths.basename(output_image, ext) 441 | local directory = paths.dirname(output_image) 442 | return string.format('%s/%s_%d.%s',directory, basename, iteration, ext) 443 | end 444 | 445 | 446 | -- Collect all valid style images and remove all non recognized files. 447 | function styleLoader(dir) 448 | local style_list 449 | local style_image_files = paths.dir(dir) 450 | local i=1 451 | while i <= #style_image_files do 452 | if not string.find(style_image_files[i], 'jpg$') 453 | and not string.find(style_image_files[i], 'JPG$') 454 | and not string.find(style_image_files[i], 'jpeg$') 455 | and not string.find(style_image_files[i], 'JPEG$') 456 | and not string.find(style_image_files[i], 'png$') 457 | and not string.find(style_image_files[i], 'pgm$') 458 | and not string.find(style_image_files[i], 'ppm$')then 459 | table.remove(style_image_files, i) 460 | else 461 | style_image_files[i] = dir .. style_image_files[i] 462 | i = i +1 463 | end 464 | end 465 | style_list = table.concat(style_image_files,",") 466 | return style_list 467 | end 468 | 469 | 470 | -- Preprocess an image before passing it to a Caffe model. 471 | -- We need to rescale from [0, 1] to [0, 255], convert from RGB to BGR, 472 | -- and subtract the mean pixel. 473 | function preprocess(img) 474 | local mean_pixel = torch.DoubleTensor({103.939, 116.779, 123.68}) 475 | local perm = torch.LongTensor{3, 2, 1} 476 | img = img:index(1, perm):mul(256.0) 477 | mean_pixel = mean_pixel:view(3, 1, 1):expandAs(img) 478 | img:add(-1, mean_pixel) 479 | return img 480 | end 481 | 482 | 483 | -- Undo the above preprocessing. 484 | function deprocess(img) 485 | local mean_pixel = torch.DoubleTensor({103.939, 116.779, 123.68}) 486 | mean_pixel = mean_pixel:view(3, 1, 1):expandAs(img) 487 | img = img + mean_pixel 488 | local perm = torch.LongTensor{3, 2, 1} 489 | img = img:index(1, perm):div(256.0) 490 | return img 491 | end 492 | 493 | 494 | -- Combine the Y channel of the generated image and the UV channels of the 495 | -- content image to perform color-independent style transfer. 496 | function original_colors(content, generated) 497 | local generated_y = image.rgb2yuv(generated)[{{1, 1}}] 498 | local content_uv = image.rgb2yuv(content)[{{2, 3}}] 499 | return image.yuv2rgb(torch.cat(generated_y, content_uv, 1)) 500 | end 501 | 502 | 503 | -- Define an nn Module to compute content loss in-place 504 | local ContentLoss, parent = torch.class('nn.ContentLoss', 'nn.Module') 505 | 506 | function ContentLoss:__init(strength, normalize) 507 | parent.__init(self) 508 | self.strength = strength 509 | self.target = torch.Tensor() 510 | self.normalize = normalize or false 511 | self.loss = 0 512 | self.crit = nn.MSECriterion() 513 | self.mode = 'none' 514 | end 515 | 516 | function ContentLoss:updateOutput(input) 517 | if self.mode == 'loss' then 518 | self.loss = self.crit:forward(input, self.target) * self.strength 519 | elseif self.mode == 'capture' then 520 | self.target:resizeAs(input):copy(input) 521 | end 522 | self.output = input 523 | return self.output 524 | end 525 | 526 | function ContentLoss:updateGradInput(input, gradOutput) 527 | if self.mode == 'loss' then 528 | if input:nElement() == self.target:nElement() then 529 | self.gradInput = self.crit:backward(input, self.target) 530 | end 531 | if self.normalize then 532 | self.gradInput:div(torch.norm(self.gradInput, 1) + 1e-8) 533 | end 534 | self.gradInput:mul(self.strength) 535 | self.gradInput:add(gradOutput) 536 | else 537 | self.gradInput:resizeAs(gradOutput):copy(gradOutput) 538 | end 539 | return self.gradInput 540 | end 541 | 542 | 543 | local Gram, parent = torch.class('nn.GramMatrix', 'nn.Module') 544 | 545 | function Gram:__init() 546 | parent.__init(self) 547 | end 548 | 549 | function Gram:updateOutput(input) 550 | assert(input:dim() == 3) 551 | local C, H, W = input:size(1), input:size(2), input:size(3) 552 | local x_flat = input:view(C, H * W) 553 | self.output:resize(C, C) 554 | self.output:mm(x_flat, x_flat:t()) 555 | return self.output 556 | end 557 | 558 | function Gram:updateGradInput(input, gradOutput) 559 | assert(input:dim() == 3 and input:size(1)) 560 | local C, H, W = input:size(1), input:size(2), input:size(3) 561 | local x_flat = input:view(C, H * W) 562 | self.gradInput:resize(C, H * W):mm(gradOutput, x_flat) 563 | self.gradInput:addmm(gradOutput:t(), x_flat) 564 | self.gradInput = self.gradInput:view(C, H, W) 565 | return self.gradInput 566 | end 567 | 568 | 569 | -- Define an nn Module to compute style loss in-place 570 | local StyleLoss, parent = torch.class('nn.StyleLoss', 'nn.Module') 571 | 572 | function StyleLoss:__init(strength, normalize) 573 | parent.__init(self) 574 | self.normalize = normalize or false 575 | self.strength = strength 576 | self.target = torch.Tensor() 577 | self.mode = 'none' 578 | self.loss = 0 579 | 580 | self.gram = nn.GramMatrix() 581 | self.blend_weight = nil 582 | self.G = nil 583 | self.crit = nn.MSECriterion() 584 | end 585 | 586 | function StyleLoss:updateOutput(input) 587 | self.G = self.gram:forward(input) 588 | self.G:div(input:nElement()) 589 | if self.mode == 'capture' then 590 | if self.blend_weight == nil then 591 | self.target:resizeAs(self.G):copy(self.G) 592 | elseif self.target:nElement() == 0 then 593 | self.target:resizeAs(self.G):copy(self.G):mul(self.blend_weight) 594 | else 595 | self.target:add(self.blend_weight, self.G) 596 | end 597 | elseif self.mode == 'loss' then 598 | self.loss = self.strength * self.crit:forward(self.G, self.target) 599 | end 600 | self.output = input 601 | return self.output 602 | end 603 | 604 | function StyleLoss:updateGradInput(input, gradOutput) 605 | if self.mode == 'loss' then 606 | local dG = self.crit:backward(self.G, self.target) 607 | dG:div(input:nElement()) 608 | self.gradInput = self.gram:backward(input, dG) 609 | if self.normalize then 610 | self.gradInput:div(torch.norm(self.gradInput, 1) + 1e-8) 611 | end 612 | self.gradInput:mul(self.strength) 613 | self.gradInput:add(gradOutput) 614 | else 615 | self.gradInput = gradOutput 616 | end 617 | return self.gradInput 618 | end 619 | 620 | 621 | local TVLoss, parent = torch.class('nn.TVLoss', 'nn.Module') 622 | 623 | function TVLoss:__init(strength) 624 | parent.__init(self) 625 | self.strength = strength 626 | self.x_diff = torch.Tensor() 627 | self.y_diff = torch.Tensor() 628 | end 629 | 630 | function TVLoss:updateOutput(input) 631 | self.output = input 632 | return self.output 633 | end 634 | 635 | -- TV loss backward pass inspired by kaishengtai/neuralart 636 | function TVLoss:updateGradInput(input, gradOutput) 637 | self.gradInput:resizeAs(input):zero() 638 | local C, H, W = input:size(1), input:size(2), input:size(3) 639 | self.x_diff:resize(3, H - 1, W - 1) 640 | self.y_diff:resize(3, H - 1, W - 1) 641 | self.x_diff:copy(input[{{}, {1, -2}, {1, -2}}]) 642 | self.x_diff:add(-1, input[{{}, {1, -2}, {2, -1}}]) 643 | self.y_diff:copy(input[{{}, {1, -2}, {1, -2}}]) 644 | self.y_diff:add(-1, input[{{}, {2, -1}, {1, -2}}]) 645 | self.gradInput[{{}, {1, -2}, {1, -2}}]:add(self.x_diff):add(self.y_diff) 646 | self.gradInput[{{}, {1, -2}, {2, -1}}]:add(-1, self.x_diff) 647 | self.gradInput[{{}, {2, -1}, {1, -2}}]:add(-1, self.y_diff) 648 | self.gradInput:mul(self.strength) 649 | self.gradInput:add(gradOutput) 650 | return self.gradInput 651 | end 652 | 653 | 654 | local params = cmd:parse(arg) 655 | main(params) -------------------------------------------------------------------------------- /volta-files/test_files/content.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimaid/volta/188c41cb6bb33e38f918a0a0020c107b74119a08/volta-files/test_files/content.jpg -------------------------------------------------------------------------------- /volta-files/test_files/style/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimaid/volta/188c41cb6bb33e38f918a0a0020c107b74119a08/volta-files/test_files/style/1.jpg -------------------------------------------------------------------------------- /volta-files/test_files/style/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimaid/volta/188c41cb6bb33e38f918a0a0020c107b74119a08/volta-files/test_files/style/2.jpg -------------------------------------------------------------------------------- /volta-files/volta-cpu.sh: -------------------------------------------------------------------------------- 1 | #https://github.com/jcjohnson/neural-style 2 | 3 | STYLE_IMAGE=$1 4 | CONTENT_IMAGE=$2 5 | 6 | 7 | 8 | verify_file() { 9 | if [ -f $1 ]; then 10 | echo "The file '$1' exists. Proceeding..." 11 | else 12 | echo "The file '$1' does not exist, likely the previous step failed." 13 | echo "Exiting..." 14 | exit 1 15 | fi 16 | } 17 | 18 | 19 | 20 | STYLE_WEIGHT=1000 21 | STYLE_SCALE=1 22 | CONTENT_WEIGHT=5 23 | 24 | th neural_style_dir_rng_fix.lua \ 25 | -style_image $STYLE_IMAGE \ 26 | -style_weight $STYLE_WEIGHT \ 27 | -style_scale $STYLE_SCALE \ 28 | -content_image $CONTENT_IMAGE \ 29 | -print_iter 1 \ 30 | -save_iter 100 \ 31 | -image_size 512 \ 32 | -num_iterations 1000 \ 33 | -model_file models/nyud-fcn32s-color-heavy.caffemodel \ 34 | -proto_file models/nyud-fcn32s-color-heavy-trainval.prototxt \ 35 | -content_layers relu1_1,relu2_1,relu3_1,relu4_1,relu5_1 \ 36 | -style_layers relu1_1,relu2_1,relu3_1,relu4_1,relu5_1 \ 37 | -optimizer lbfgs \ 38 | -output_image X1.png \ 39 | -tv_weight 0.00001 \ 40 | -gpu -1 \ 41 | -original_colors 0 \ 42 | -backend cudnn \ 43 | -init random \ 44 | 45 | verify_file X1.png 46 | 47 | 48 | 49 | STYLE_WEIGHT=100 50 | STYLE_SCALE=1 51 | CONTENT_WEIGHT=375 52 | 53 | th neural_style_dir_rng_fix.lua \ 54 | -style_image $STYLE_IMAGE \ 55 | -style_weight $STYLE_WEIGHT \ 56 | -style_scale $STYLE_SCALE \ 57 | -content_image $CONTENT_IMAGE \ 58 | -init image \ 59 | -init_image X1.png \ 60 | -print_iter 1 \ 61 | -image_size 800 \ 62 | -num_iterations 500 \ 63 | -model_file models/nyud-fcn32s-color-heavy.caffemodel \ 64 | -proto_file models/nyud-fcn32s-color-heavy-trainval.prototxt \ 65 | -content_layers relu1_1,relu2_1,relu3_1,relu4_1,relu5_1 \ 66 | -style_layers relu1_1,relu2_1,relu3_1,relu4_1,relu5_1 \ 67 | -optimizer lbfgs \ 68 | -output_image X2.png \ 69 | -tv_weight 0.00001 \ 70 | -gpu -1 \ 71 | -original_colors 0 \ 72 | -normalize_gradients \ 73 | -backend cudnn 74 | 75 | rm X1*.png 76 | 77 | verify_file X2.png 78 | 79 | 80 | 81 | STYLE_WEIGHT=1000 82 | STYLE_SCALE=1 83 | CONTENT_WEIGHT=0 84 | 85 | th neural_style_dir_rng_fix.lua \ 86 | -style_image $STYLE_IMAGE \ 87 | -style_weight $STYLE_WEIGHT \ 88 | -style_scale $STYLE_SCALE \ 89 | -content_image $CONTENT_IMAGE \ 90 | -content_weight $CONTENT_WEIGHT \ 91 | -output_image X3.png \ 92 | -num_iterations 200 \ 93 | -model_file models/nyud-fcn32s-color-heavy.caffemodel \ 94 | -proto_file models/nyud-fcn32s-color-heavy-trainval.prototxt \ 95 | -optimizer adam \ 96 | -print_iter 1 \ 97 | -save_iter 100 \ 98 | -tv_weight 0 \ 99 | -backend cudnn \ 100 | -init image \ 101 | -init_image X2.png \ 102 | -learning_rate 1 \ 103 | -image_size 1148 \ 104 | -gpu -1 \ 105 | -original_colors 0 \ 106 | -normalize_gradients \ 107 | 108 | rm X2*.png 109 | 110 | verify_file X3.png 111 | 112 | 113 | 114 | th neural_style_dir_rng_fix.lua \ 115 | -style_image $STYLE_IMAGE \ 116 | -style_weight $STYLE_WEIGHT \ 117 | -style_scale $STYLE_SCALE \ 118 | -content_image $CONTENT_IMAGE \ 119 | -content_weight $CONTENT_WEIGHT \ 120 | -output_image X4.png \ 121 | -num_iterations 600 \ 122 | -model_file models/channel_pruning.caffemodel \ 123 | -proto_file models/channel_pruning.prototxt \ 124 | -optimizer adam \ 125 | -print_iter 1 \ 126 | -save_iter 100 \ 127 | -tv_weight 0 \ 128 | -backend cudnn \ 129 | -init image \ 130 | -init_image X3.png \ 131 | -learning_rate 1 \ 132 | -image_size 1800 \ 133 | -gpu -1 \ 134 | -original_colors 0 \ 135 | -normalize_gradients \ 136 | 137 | rm X3*.png 138 | 139 | verify_file X4.png 140 | 141 | 142 | 143 | th neural_style_dir_rng_fix.lua \ 144 | -style_image $STYLE_IMAGE \ 145 | -style_weight $STYLE_WEIGHT \ 146 | -style_scale $STYLE_SCALE \ 147 | -content_image $CONTENT_IMAGE \ 148 | -content_weight $CONTENT_WEIGHT \ 149 | -output_image X5.png \ 150 | -model_file models/nin_imagenet_conv.caffemodel \ 151 | -proto_file models/train_val.prototxt \ 152 | -num_iterations 200 \ 153 | -content_layers relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8 \ 154 | -style_layers relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8 \ 155 | -optimizer adam \ 156 | -print_iter 1 \ 157 | -save_iter 100 \ 158 | -tv_weight 0 \ 159 | -backend cudnn \ 160 | -init image \ 161 | -init_image X4.png \ 162 | -learning_rate 1 \ 163 | -image_size 2550 \ 164 | -gpu -1 \ 165 | -original_colors 0 \ 166 | -normalize_gradients \ 167 | 168 | rm X4*.png 169 | 170 | verify_file X5.png 171 | 172 | 173 | 174 | STYLE_WEIGHT=1000 175 | STYLE_SCALE=1 176 | CONTENT_WEIGHT=0 177 | 178 | th neural_style_dir_rng_fix.lua \ 179 | -style_image $STYLE_IMAGE \ 180 | -style_weight $STYLE_WEIGHT \ 181 | -style_scale $STYLE_SCALE \ 182 | -content_image $CONTENT_IMAGE \ 183 | -content_weight $CONTENT_WEIGHT \ 184 | -output_image X6.png \ 185 | -model_file models/nin_imagenet_conv.caffemodel \ 186 | -proto_file models/train_val.prototxt \ 187 | -num_iterations 200 \ 188 | -content_layers relu0,relu1,relu2,relu3,relu5,relu6 \ 189 | -style_layers relu0,relu1,relu2,relu3,relu5,relu6 \ 190 | -optimizer adam \ 191 | -print_iter 1 \ 192 | -save_iter 100 \ 193 | -tv_weight 0 \ 194 | -backend cudnn \ 195 | -init image \ 196 | -init_image X5.png \ 197 | -learning_rate 1 \ 198 | -image_size 2700 \ 199 | -gpu -1 \ 200 | -original_colors 0 \ 201 | -normalize_gradients \ 202 | 203 | rm X5*.png 204 | 205 | verify_file X6.png 206 | 207 | 208 | 209 | th neural_style_dir_rng_fix.lua \ 210 | -style_image $STYLE_IMAGE \ 211 | -style_weight $STYLE_WEIGHT \ 212 | -style_scale $STYLE_SCALE \ 213 | -content_image $CONTENT_IMAGE \ 214 | -content_weight $CONTENT_WEIGHT \ 215 | -output_image X7.png \ 216 | -model_file models/nin_imagenet_conv.caffemodel \ 217 | -proto_file models/train_val.prototxt \ 218 | -num_iterations 200 \ 219 | -content_layers relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8 \ 220 | -style_layers relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8 \ 221 | -optimizer adam \ 222 | -print_iter 1 \ 223 | -save_iter 0 \ 224 | -tv_weight 0 \ 225 | -backend cudnn \ 226 | -init image \ 227 | -init_image X6.png \ 228 | -learning_rate 1 \ 229 | -image_size 2900 \ 230 | -gpu -1 \ 231 | -original_colors 0 \ 232 | -normalize_gradients \ 233 | 234 | rm X6*.png 235 | 236 | verify_file X7.png 237 | 238 | 239 | 240 | th neural_style_dir_rng_fix.lua \ 241 | -style_image $STYLE_IMAGE \ 242 | -style_weight $STYLE_WEIGHT \ 243 | -style_scale $STYLE_SCALE \ 244 | -content_image $CONTENT_IMAGE \ 245 | -content_weight $CONTENT_WEIGHT \ 246 | -output_image X8.png \ 247 | -model_file models/nin_imagenet_conv.caffemodel \ 248 | -proto_file models/train_val.prototxt \ 249 | -num_iterations 200 \ 250 | -content_layers relu0,relu1 \ 251 | -style_layers relu0,relu1 \ 252 | -optimizer adam \ 253 | -print_iter 1 \ 254 | -save_iter 0 \ 255 | -tv_weight 0 \ 256 | -backend cudnn \ 257 | -init image \ 258 | -init_image X7.png \ 259 | -learning_rate 1 \ 260 | -image_size 4000 \ 261 | -gpu -1 \ 262 | -original_colors 0 \ 263 | -normalize_gradients \ 264 | 265 | rm X7*.png 266 | 267 | verify_file X8.png 268 | 269 | 270 | 271 | STYLE_SCALE=0.5 272 | 273 | th neural_style_dir_rng_fix.lua \ 274 | -style_image $STYLE_IMAGE \ 275 | -content_image $CONTENT_IMAGE \ 276 | -output_image X9.png \ 277 | -model_file models/nin_imagenet_conv.caffemodel \ 278 | -proto_file models/train_val.prototxt \ 279 | -num_iterations 20 \ 280 | -content_layers relu0,relu1 \ 281 | -style_layers relu0,relu1 \ 282 | -optimizer adam \ 283 | -print_iter 1 \ 284 | -save_iter 0 \ 285 | -tv_weight 0 \ 286 | -style_scale $STYLE_SCALE \ 287 | -backend cudnn \ 288 | -content_weight $CONTENT_WEIGHT \ 289 | -style_weight $STYLE_WEIGHT \ 290 | -init image \ 291 | -init_image X8.png \ 292 | -learning_rate 1 \ 293 | -image_size 5600 \ 294 | -gpu -1 \ 295 | -original_colors 0 \ 296 | 297 | rm X8*.png 298 | 299 | verify_file X9.png 300 | 301 | 302 | 303 | # ENTERING PART 2 ## 304 | 305 | 306 | 307 | STYLE_WEIGHT=1000 308 | STYLE_SCALE=0.5 309 | CONTENT_WEIGHT=0 310 | 311 | th neural_style_dir_rng_fix.lua \ 312 | -style_image $STYLE_IMAGE \ 313 | -content_image $CONTENT_IMAGE \ 314 | -output_image X9a.png \ 315 | -model_file models/nin_imagenet_conv.caffemodel \ 316 | -proto_file models/train_val.prototxt \ 317 | -num_iterations 20 \ 318 | -content_layers relu0,relu1 \ 319 | -style_layers relu0,relu1 \ 320 | -optimizer adam \ 321 | -print_iter 1 \ 322 | -save_iter 0 \ 323 | -tv_weight 0 \ 324 | -style_scale $STYLE_SCALE \ 325 | -backend cudnn \ 326 | -content_weight $CONTENT_WEIGHT \ 327 | -style_weight $STYLE_WEIGHT \ 328 | -init image \ 329 | -init_image X9.png \ 330 | -learning_rate 1 \ 331 | -image_size 5500 \ 332 | -gpu -1 \ 333 | -original_colors 0 \ 334 | 335 | rm X9.png 336 | 337 | verify_file X9a.png 338 | 339 | 340 | 341 | th neural_style_dir_rng_fix.lua \ 342 | -style_image $STYLE_IMAGE \ 343 | -content_image $CONTENT_IMAGE \ 344 | -output_image X9b.png \ 345 | -model_file models/nin_imagenet_conv.caffemodel \ 346 | -proto_file models/train_val.prototxt \ 347 | -num_iterations 20 \ 348 | -content_layers relu0,relu1 \ 349 | -style_layers relu0,relu1 \ 350 | -optimizer adam \ 351 | -print_iter 1 \ 352 | -save_iter 0 \ 353 | -tv_weight 0 \ 354 | -style_scale $STYLE_SCALE \ 355 | -backend cudnn \ 356 | -content_weight $CONTENT_WEIGHT \ 357 | -style_weight $STYLE_WEIGHT \ 358 | -init image \ 359 | -init_image X9a.png \ 360 | -learning_rate 1 \ 361 | -image_size 5400 \ 362 | -gpu -1 \ 363 | -original_colors 0 \ 364 | 365 | rm X9a.png 366 | 367 | verify_file X9b.png 368 | 369 | 370 | 371 | th neural_style_dir_rng_fix.lua \ 372 | -style_image $STYLE_IMAGE \ 373 | -content_image $CONTENT_IMAGE \ 374 | -output_image X9c.png \ 375 | -model_file models/nin_imagenet_conv.caffemodel \ 376 | -proto_file models/train_val.prototxt \ 377 | -num_iterations 20 \ 378 | -content_layers relu0,relu1 \ 379 | -style_layers relu0,relu1 \ 380 | -optimizer adam \ 381 | -print_iter 1 \ 382 | -save_iter 0 \ 383 | -tv_weight 0 \ 384 | -style_scale $STYLE_SCALE \ 385 | -backend cudnn \ 386 | -content_weight $CONTENT_WEIGHT \ 387 | -style_weight $STYLE_WEIGHT \ 388 | -init image \ 389 | -init_image X9b.png \ 390 | -learning_rate 1 \ 391 | -image_size 5300 \ 392 | -gpu -1 \ 393 | -original_colors 0 \ 394 | 395 | rm X9b.png 396 | 397 | verify_file X9c.png 398 | 399 | 400 | 401 | th neural_style_dir_rng_fix.lua \ 402 | -style_image $STYLE_IMAGE \ 403 | -content_image $CONTENT_IMAGE \ 404 | -output_image X9d.png \ 405 | -model_file models/nin_imagenet_conv.caffemodel \ 406 | -proto_file models/train_val.prototxt \ 407 | -num_iterations 20 \ 408 | -content_layers relu0,relu1 \ 409 | -style_layers relu0,relu1 \ 410 | -optimizer adam \ 411 | -print_iter 1 \ 412 | -save_iter 0 \ 413 | -tv_weight 0 \ 414 | -style_scale $STYLE_SCALE \ 415 | -backend cudnn \ 416 | -content_weight $CONTENT_WEIGHT \ 417 | -style_weight $STYLE_WEIGHT \ 418 | -init image \ 419 | -init_image X9c.png \ 420 | -learning_rate 1 \ 421 | -image_size 5200 \ 422 | -gpu -1 \ 423 | -original_colors 0 \ 424 | 425 | rm X9c.png 426 | 427 | verify_file X9d.png 428 | 429 | 430 | 431 | th neural_style_dir_rng_fix.lua \ 432 | -style_image $STYLE_IMAGE \ 433 | -content_image $CONTENT_IMAGE \ 434 | -output_image X9e.png \ 435 | -model_file models/nin_imagenet_conv.caffemodel \ 436 | -proto_file models/train_val.prototxt \ 437 | -num_iterations 20 \ 438 | -content_layers relu0,relu1 \ 439 | -style_layers relu0,relu1 \ 440 | -optimizer adam \ 441 | -print_iter 1 \ 442 | -save_iter 0 \ 443 | -tv_weight 0 \ 444 | -style_scale $STYLE_SCALE \ 445 | -backend cudnn \ 446 | -content_weight $CONTENT_WEIGHT \ 447 | -style_weight $STYLE_WEIGHT \ 448 | -init image \ 449 | -init_image X9d.png \ 450 | -learning_rate 1 \ 451 | -image_size 5100 \ 452 | -gpu -1 \ 453 | -original_colors 0 \ 454 | 455 | rm X9d.png 456 | 457 | verify_file X9e.png 458 | 459 | 460 | 461 | th neural_style_dir_rng_fix.lua \ 462 | -style_image $STYLE_IMAGE \ 463 | -content_image $CONTENT_IMAGE \ 464 | -output_image X9f.png \ 465 | -model_file models/nin_imagenet_conv.caffemodel \ 466 | -proto_file models/train_val.prototxt \ 467 | -num_iterations 20 \ 468 | -content_layers relu0,relu1 \ 469 | -style_layers relu0,relu1 \ 470 | -optimizer adam \ 471 | -print_iter 1 \ 472 | -save_iter 0 \ 473 | -tv_weight 0 \ 474 | -style_scale $STYLE_SCALE \ 475 | -backend cudnn \ 476 | -content_weight $CONTENT_WEIGHT \ 477 | -style_weight $STYLE_WEIGHT \ 478 | -init image \ 479 | -init_image X9e.png \ 480 | -learning_rate 1 \ 481 | -image_size 5000 \ 482 | -gpu -1 \ 483 | -original_colors 0 \ 484 | 485 | rm X9e.png 486 | 487 | verify_file X9f.png 488 | 489 | 490 | 491 | th neural_style_dir_rng_fix.lua \ 492 | -style_image $STYLE_IMAGE \ 493 | -content_image $CONTENT_IMAGE \ 494 | -output_image X9g.png \ 495 | -model_file models/nin_imagenet_conv.caffemodel \ 496 | -proto_file models/train_val.prototxt \ 497 | -num_iterations 20 \ 498 | -content_layers relu0,relu1 \ 499 | -style_layers relu0,relu1 \ 500 | -optimizer adam \ 501 | -print_iter 1 \ 502 | -save_iter 0 \ 503 | -tv_weight 0 \ 504 | -style_scale $STYLE_SCALE \ 505 | -backend cudnn \ 506 | -content_weight $CONTENT_WEIGHT \ 507 | -style_weight $STYLE_WEIGHT \ 508 | -init image \ 509 | -init_image X9f.png \ 510 | -learning_rate 1 \ 511 | -image_size 4900 \ 512 | -gpu -1 \ 513 | -original_colors 0 \ 514 | 515 | rm X9f.png 516 | 517 | verify_file X9g.png 518 | 519 | 520 | 521 | th neural_style_dir_rng_fix.lua \ 522 | -style_image $STYLE_IMAGE \ 523 | -content_image $CONTENT_IMAGE \ 524 | -output_image X9h.png \ 525 | -model_file models/nin_imagenet_conv.caffemodel \ 526 | -proto_file models/train_val.prototxt \ 527 | -num_iterations 20 \ 528 | -content_layers relu0,relu1 \ 529 | -style_layers relu0,relu1 \ 530 | -optimizer adam \ 531 | -print_iter 1 \ 532 | -save_iter 0 \ 533 | -tv_weight 0 \ 534 | -style_scale $STYLE_SCALE \ 535 | -backend cudnn \ 536 | -content_weight $CONTENT_WEIGHT \ 537 | -style_weight $STYLE_WEIGHT \ 538 | -init image \ 539 | -init_image X9g.png \ 540 | -learning_rate 1 \ 541 | -image_size 4800 \ 542 | -gpu -1 \ 543 | -original_colors 0 \ 544 | 545 | rm X9g.png 546 | 547 | verify_file X9h.png 548 | 549 | 550 | 551 | th neural_style_dir_rng_fix.lua \ 552 | -style_image $STYLE_IMAGE \ 553 | -content_image $CONTENT_IMAGE \ 554 | -output_image X9i.png \ 555 | -model_file models/nin_imagenet_conv.caffemodel \ 556 | -proto_file models/train_val.prototxt \ 557 | -num_iterations 20 \ 558 | -content_layers relu0,relu1 \ 559 | -style_layers relu0,relu1 \ 560 | -optimizer adam \ 561 | -print_iter 1 \ 562 | -save_iter 0 \ 563 | -tv_weight 0 \ 564 | -style_scale $STYLE_SCALE \ 565 | -backend cudnn \ 566 | -content_weight $CONTENT_WEIGHT \ 567 | -style_weight $STYLE_WEIGHT \ 568 | -init image \ 569 | -init_image X9h.png \ 570 | -learning_rate 1 \ 571 | -image_size 4700 \ 572 | -gpu -1 \ 573 | -original_colors 0 \ 574 | 575 | rm X9h.png 576 | 577 | verify_file X9i.png 578 | 579 | 580 | 581 | th neural_style_dir_rng_fix.lua \ 582 | -style_image $STYLE_IMAGE \ 583 | -content_image $CONTENT_IMAGE \ 584 | -output_image X9j.png \ 585 | -model_file models/nin_imagenet_conv.caffemodel \ 586 | -proto_file models/train_val.prototxt \ 587 | -num_iterations 20 \ 588 | -content_layers relu0,relu1 \ 589 | -style_layers relu0,relu1 \ 590 | -optimizer adam \ 591 | -print_iter 1 \ 592 | -save_iter 0 \ 593 | -tv_weight 0 \ 594 | -style_scale $STYLE_SCALE \ 595 | -backend cudnn \ 596 | -content_weight $CONTENT_WEIGHT \ 597 | -style_weight $STYLE_WEIGHT \ 598 | -init image \ 599 | -init_image X9i.png \ 600 | -learning_rate 1 \ 601 | -image_size 4600 \ 602 | -gpu -1 \ 603 | -original_colors 0 \ 604 | 605 | rm X9i.png 606 | 607 | verify_file X9j.png 608 | 609 | 610 | 611 | th neural_style_dir_rng_fix.lua \ 612 | -style_image $STYLE_IMAGE \ 613 | -content_image $CONTENT_IMAGE \ 614 | -output_image X9k.png \ 615 | -model_file models/nin_imagenet_conv.caffemodel \ 616 | -proto_file models/train_val.prototxt \ 617 | -num_iterations 20 \ 618 | -content_layers relu0,relu1 \ 619 | -style_layers relu0,relu1 \ 620 | -optimizer adam \ 621 | -print_iter 1 \ 622 | -save_iter 0 \ 623 | -tv_weight 0 \ 624 | -style_scale $STYLE_SCALE \ 625 | -backend cudnn \ 626 | -content_weight $CONTENT_WEIGHT \ 627 | -style_weight $STYLE_WEIGHT \ 628 | -init image \ 629 | -init_image X9j.png \ 630 | -learning_rate 1 \ 631 | -image_size 4500 \ 632 | -gpu -1 \ 633 | -original_colors 0 \ 634 | 635 | rm X9j.png 636 | 637 | verify_file X9k.png 638 | 639 | 640 | 641 | th neural_style_dir_rng_fix.lua \ 642 | -style_image $STYLE_IMAGE \ 643 | -content_image $CONTENT_IMAGE \ 644 | -output_image X9l.png \ 645 | -model_file models/nin_imagenet_conv.caffemodel \ 646 | -proto_file models/train_val.prototxt \ 647 | -num_iterations 20 \ 648 | -content_layers relu0,relu1 \ 649 | -style_layers relu0,relu1 \ 650 | -optimizer adam \ 651 | -print_iter 1 \ 652 | -save_iter 0 \ 653 | -tv_weight 0 \ 654 | -style_scale $STYLE_SCALE \ 655 | -backend cudnn \ 656 | -content_weight $CONTENT_WEIGHT \ 657 | -style_weight $STYLE_WEIGHT \ 658 | -init image \ 659 | -init_image X9k.png \ 660 | -learning_rate 1 \ 661 | -image_size 4400 \ 662 | -gpu -1 \ 663 | -original_colors 0 \ 664 | 665 | rm X9k.png 666 | 667 | verify_file X9l.png 668 | 669 | 670 | 671 | th neural_style_dir_rng_fix.lua \ 672 | -style_image $STYLE_IMAGE \ 673 | -content_image $CONTENT_IMAGE \ 674 | -output_image final.png \ 675 | -model_file models/nin_imagenet_conv.caffemodel \ 676 | -proto_file models/train_val.prototxt \ 677 | -num_iterations 20 \ 678 | -content_layers relu0,relu1 \ 679 | -style_layers relu0,relu1 \ 680 | -optimizer adam \ 681 | -print_iter 1 \ 682 | -save_iter 0 \ 683 | -tv_weight 0 \ 684 | -style_scale $STYLE_SCALE \ 685 | -backend cudnn \ 686 | -content_weight $CONTENT_WEIGHT \ 687 | -style_weight $STYLE_WEIGHT \ 688 | -init image \ 689 | -init_image X9l.png \ 690 | -learning_rate 1 \ 691 | -image_size 4300 \ 692 | -gpu -1 \ 693 | -original_colors 0 \ 694 | 695 | rm X9l.png 696 | 697 | verify_file final.png 698 | 699 | 700 | 701 | echo "All done!" 702 | -------------------------------------------------------------------------------- /volta-files/volta-mod.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": { 7 | "scrolled": true, 8 | "tags": [ 9 | "hidecode" 10 | ] 11 | }, 12 | "outputs": [], 13 | "source": [ 14 | "# Original neural-style documentation: https://github.com/jcjohnson/neural-style\n", 15 | "\n", 16 | "import os, math\n", 17 | "from PIL import Image\n", 18 | "from IPython.display import display, clear_output\n", 19 | "\n", 20 | "_DEBUG_MODE_ = True\n", 21 | "\n", 22 | "script_style = ['/usr/local/bin/th', 'neural_style_dir_rng_fix.lua']\n", 23 | "script_lincolor = ['python3', 'Neural-Tools/linear-color-transfer.py']\n", 24 | "script_lum = ['python3', 'Neural-Tools/lum-transfer.py']\n", 25 | "\n", 26 | "model_vgg = 'models/VGG_ILSVRC_19_layers.caffemodel'\n", 27 | "model_vggnorm = 'models/vgg_normalised.caffemodel'\n", 28 | "model_nin = 'models/nin_imagenet_conv.caffemodel'\n", 29 | "model_nyud = 'models/nyud-fcn32s-color-heavy.caffemodel'\n", 30 | "model_channelpruning = 'models/channel_pruning.caffemodel'\n", 31 | "\n", 32 | "proto_vgg = 'models/VGG_ILSVRC_19_layers_deploy.prototxt'\n", 33 | "proto_vggnorm = 'models/VGG_ILSVRC_19_layers_deploy_fullconv.prototxt'\n", 34 | "proto_nin = 'models/train_val.prototxt'\n", 35 | "proto_nyud = 'models/nyud-fcn32s-color-heavy-trainval.prototxt'\n", 36 | "proto_channelpruning = 'models/channel_pruning.prototxt'\n", 37 | "\n", 38 | "slayer_vgg = 'relu1_1,relu2_1,relu3_1,relu4_1,relu5_1'\n", 39 | "slayer_vggnorm = slayer_vgg\n", 40 | "slayer_nin = 'relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8'\n", 41 | "slayer_nyud = slayer_vgg\n", 42 | "slayer_channelpruning = slayer_vgg\n", 43 | "\n", 44 | "clayer_vgg = 'relu4_2'\n", 45 | "clayer_vggnorm = clayer_vgg\n", 46 | "clayer_nin = 'relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8'\n", 47 | "clayer_nyud = clayer_vgg\n", 48 | "clayer_channelpruning = clayer_vgg\n", 49 | "\n", 50 | "\n", 51 | "def show_image(image_path):\n", 52 | " with Image.open(image_path) as im:\n", 53 | " display(im)\n", 54 | "\n", 55 | "def style_transfer(style_image,\n", 56 | " content_image,\n", 57 | " image_size=None, #defaults to 512\n", 58 | " style_blend_weights=None, #defaults to equal weights\n", 59 | " gpu=None, #defaults to 0, use -1 for CPU only (why would you?)\n", 60 | " content_weight=None, #defaults to '5e0'\n", 61 | " style_weight=None, #defaults to '1e2'\n", 62 | " tv_weight=None, #defaults to 1e-3\n", 63 | " num_iterations=None, #defaults to 1000\n", 64 | " init=None, #defaults to 'random', pass 'image' to use init_image\n", 65 | " init_image=None,\n", 66 | " optimizer=None, #defaults to 'lbfgs', 'adam' is lower mem but worse\n", 67 | " learning_rate=None, #defaults to '1e1', for ADAM only\n", 68 | " normalize_gradients=None, #defaults to unset, good for ADAM\n", 69 | " output_image='out.png', #defaults to 'out.png'\n", 70 | " print_iter=None, #defaults to 50, 0 to disable\n", 71 | " save_iter=None, #defaults to 100, 0 to disable\n", 72 | " content_layers=None, #defaults to 'relu4_2'\n", 73 | " style_layers=None, #defaults to 'relu1_1,relu2_1,relu3_1,relu4_1,relu5_1'\n", 74 | " style_scale=None, #defaults to 1.0\n", 75 | " original_colors=None, #defaults to 0, 1 for original colors\n", 76 | " proto_file=None, #defaults to 'models/VGG_ILSVRC_19_layers_deploy.prototxt'\n", 77 | " model_file=None, #defaults to 'models/VGG_ILSVRC_19_layers.caffemodel'\n", 78 | " pooling=None, #default is 'max', 'avg' may or may not get better results\n", 79 | " backend=None, #default is 'nn', 'cudnn' and 'clnn' are other options\n", 80 | " cudnn_autotune=None, #default is unset, more mem but faster backend\n", 81 | " multigpu_strategy=None, #default is '', see original documentation\n", 82 | " lbfgs_num_correction=None, #default is 0, higher gets better results I think\n", 83 | " seed=None): #default is -1, for random I believe\n", 84 | " \n", 85 | " arg_names = ['style_image','content_image','image_size','style_blend_weights','gpu',\n", 86 | " 'content_weight','style_weight','tv_weight','num_iterations','init', 'init_image',\n", 87 | " 'optimizer','learning_rate','normalize_gradients','output_image',\n", 88 | " 'print_iter','save_iter','content_layers','style_layers','style_scale',\n", 89 | " 'original_colors','proto_file','model_file','pooling','backend',\n", 90 | " 'cudnn_autotune','multigpu_strategy','lbfgs_num_correction','seed']\n", 91 | " \n", 92 | " command = script_style.copy()\n", 93 | " for arg_name in arg_names:\n", 94 | " arg_val = eval(arg_name)\n", 95 | " if arg_val != None:\n", 96 | " arg_val = str(arg_val)\n", 97 | " command.append('-' + arg_name)\n", 98 | " if arg_name not in ['normalize_gradients', 'cudnn_autotune']:\n", 99 | " command.append(arg_val)\n", 100 | " \n", 101 | " command = ' '.join(command)\n", 102 | " if _DEBUG_MODE_:\n", 103 | " print('\\n' + command + '\\n')\n", 104 | " !{command}\n", 105 | " \n", 106 | " if os.path.isfile(output_image):\n", 107 | " if _DEBUG_MODE_:\n", 108 | " show_image(output_image)\n", 109 | " print('Transfer complete! Saved to \"{}\"'.format(output_image)\n", 110 | " else:\n", 111 | " print('Transfer FAILED!')\n", 112 | "\n", 113 | "def ez_cuda(cuda):\n", 114 | " r = dict()\n", 115 | " if cuda:\n", 116 | " r['backend'] = 'cudnn'\n", 117 | " r['cudnn_autotune'] = True\n", 118 | " else:\n", 119 | " r['backend'] = 'nn'\n", 120 | " r['cudnn_autotune'] = None\n", 121 | " return r\n", 122 | "\n", 123 | "def ez_model(model, clayers_override=None, slayers_override=None):\n", 124 | " r = dict()\n", 125 | " if model in ['vgg', 'vggnorm', 'nin', 'nyud', 'channelpruning']:\n", 126 | " r['model_file'] = eval('model_' + model)\n", 127 | " r['proto_file'] = eval('proto_' + model)\n", 128 | " \n", 129 | " if clayers_override != None:\n", 130 | " r['content_layers'] = clayers_override\n", 131 | " else:\n", 132 | " r['content_layers'] = eval('clayer_' + model)\n", 133 | "\n", 134 | " if slayers_override != None:\n", 135 | " r['style_layers'] = slayers_override\n", 136 | " else:\n", 137 | " r['style_layers'] = eval('slayer_' + model)\n", 138 | " \n", 139 | " else:\n", 140 | " raise Exception('\"{}\" is not a valid model name.'.format(model))\n", 141 | " return r\n", 142 | " \n", 143 | "def ez_style_transfer(style_image,\n", 144 | " content_image,\n", 145 | " image_size=None, #defaults to 512\n", 146 | " style_blend_weights=None, #defaults to equal weights\n", 147 | " gpu=None, #defaults to 0, use -1 for CPU only (why would you?)\n", 148 | " content_weight=None, #defaults to '5e0'\n", 149 | " style_weight=None, #defaults to '1e2'\n", 150 | " tv_weight=None, #defaults to 1e-3\n", 151 | " num_iterations=None, #defaults to 1000\n", 152 | " init=None, #defaults to 'random', pass 'image' to use init_image\n", 153 | " init_image=None,\n", 154 | " optimizer=None, #defaults to 'lbfgs', 'adam' is lower mem but worse\n", 155 | " learning_rate=None, #defaults to '1e1', for ADAM only\n", 156 | " normalize_gradients=None, #defaults to unset, good for ADAM\n", 157 | " output_image=None, #defaults to 'out.png'\n", 158 | " print_iter=None, #defaults to 50, 0 to disable\n", 159 | " save_iter=None, #defaults to 100, 0 to disable\n", 160 | " style_scale=None, #defaults to 1.0\n", 161 | " original_colors=None, #defaults to 0, 1 for original colors\n", 162 | " pooling=None, #default is 'max', 'avg' may or may not get better results\n", 163 | " multigpu_strategy=None, #default is '', see original documentation\n", 164 | " lbfgs_num_correction=None, #default is 0, higher gets better results I think\n", 165 | " seed=None, #default is -1, for random I believe\n", 166 | " \n", 167 | " cuda=True,\n", 168 | " model='vgg', #Options: 'vgg', 'vggnorm', 'nyud', 'nin', 'channelpruning'\n", 169 | " clayers_override=None,\n", 170 | " slayers_override=None): \n", 171 | " \n", 172 | " m = ez_model(model,\n", 173 | " clayers_override = clayers_override,\n", 174 | " slayers_override = slayers_override)\n", 175 | " c = ez_cuda(cuda)\n", 176 | " \n", 177 | " r = style_transfer(style_image=style_image,\n", 178 | " content_image=content_image,\n", 179 | " image_size=image_size, \n", 180 | " style_blend_weights=style_blend_weights, \n", 181 | " gpu=gpu, \n", 182 | " content_weight=content_weight, \n", 183 | " style_weight=style_weight, \n", 184 | " tv_weight=tv_weight, \n", 185 | " num_iterations=num_iterations, \n", 186 | " init=init,\n", 187 | " init_image=init_image,\n", 188 | " optimizer=optimizer, \n", 189 | " learning_rate=learning_rate, \n", 190 | " normalize_gradients=normalize_gradients, \n", 191 | " output_image=output_image, \n", 192 | " print_iter=print_iter, \n", 193 | " save_iter=save_iter, \n", 194 | " content_layers=m['content_layers'], \n", 195 | " style_layers=m['style_layers'], \n", 196 | " style_scale=style_scale, \n", 197 | " original_colors=original_colors, \n", 198 | " proto_file=m['proto_file'],\n", 199 | " model_file=m['model_file'],\n", 200 | " pooling=pooling,\n", 201 | " backend=c['backend'],\n", 202 | " cudnn_autotune=c['cudnn_autotune'],\n", 203 | " multigpu_strategy=multigpu_strategy,\n", 204 | " lbfgs_num_correction=lbfgs_num_correction,\n", 205 | " seed=seed)\n", 206 | "\n", 207 | "def image_max_size(image_in):\n", 208 | " with Image.open(image_in) as im:\n", 209 | " im_size = im.size\n", 210 | " return max(im_size)\n", 211 | "\n", 212 | "def multires_transfer(style_image,\n", 213 | " content_image,\n", 214 | " style_blend_weights=None, #defaults to equal weights\n", 215 | " gpu=None, #defaults to 0, use -1 for CPU only (why would you?)\n", 216 | " content_weight=None, #defaults to '5e0'\n", 217 | " style_weight=None, #defaults to '1e2'\n", 218 | " tv_weight=None, #defaults to 1e-3\n", 219 | " num_iterations=None,\n", 220 | " init=None, #defaults to 'random', pass 'image' to use init_image\n", 221 | " init_image=None,\n", 222 | " optimizer=None, #defaults to 'lbfgs', 'adam' is lower mem but worse\n", 223 | " learning_rate=None, #defaults to '1e1', for ADAM only\n", 224 | " normalize_gradients=None, #defaults to unset, good for ADAM\n", 225 | " output_image=None, #defaults to 'out.png'\n", 226 | " print_iter=None, #defaults to 50, 0 to disable\n", 227 | " content_layers=None, #defaults to 'relu4_2'\n", 228 | " style_layers=None, #defaults to 'relu1_1,relu2_1,relu3_1,relu4_1,relu5_1'\n", 229 | " style_scale=None, #defaults to 1.0\n", 230 | " original_colors=None, #defaults to 0, 1 for original colors\n", 231 | " proto_file=None, #defaults to 'models/VGG_ILSVRC_19_layers_deploy.prototxt'\n", 232 | " model_file=None, #defaults to 'models/VGG_ILSVRC_19_layers.caffemodel'\n", 233 | " pooling=None, #defauls to 'max', 'avg' may or may not get better results\n", 234 | " multigpu_strategy=None, #default is '', see original documentation\n", 235 | " lbfgs_num_correction=None, #defauls to 0, higher gets better results I think\n", 236 | " backend=None,\n", 237 | " cudnn_autotune=None,\n", 238 | " \n", 239 | " start_size=512,\n", 240 | " final_size=None, #defaults to original content size\n", 241 | " step_size=250):\n", 242 | " \n", 243 | " if final_size == None:\n", 244 | " final_size = image_max_size(content_image)\n", 245 | " \n", 246 | " steps = math.ceil((final_size - start_size) // step_size)\n", 247 | " \n", 248 | " for step in range(steps):\n", 249 | " if step == steps - 1:\n", 250 | " curr_size = final_size\n", 251 | " else:\n", 252 | " curr_size = (step * step_size) + start_size\n", 253 | " \n", 254 | " if init != None:\n", 255 | " if step != 0:\n", 256 | " init_image = str(step-1) + '.png'\n", 257 | " \n", 258 | " if step == steps-1:\n", 259 | " img_out = output_image\n", 260 | " else:\n", 261 | " img_out = str(step) + '.png'\n", 262 | " \n", 263 | " print('Starting multires transfer step {}/{}...'.format(step + 1, steps))\n", 264 | " \n", 265 | " r = style_transfer(style_image=style_image,\n", 266 | " content_image=content_image,\n", 267 | " image_size=curr_size, \n", 268 | " style_blend_weights=style_blend_weights, \n", 269 | " gpu=gpu, \n", 270 | " content_weight=content_weight, \n", 271 | " style_weight=style_weight, \n", 272 | " tv_weight=tv_weight, \n", 273 | " num_iterations=num_iterations, \n", 274 | " init=init,\n", 275 | " init_image=init_image,\n", 276 | " optimizer=optimizer, \n", 277 | " learning_rate=learning_rate, \n", 278 | " normalize_gradients=normalize_gradients, \n", 279 | " output_image=img_out, \n", 280 | " print_iter=print_iter, \n", 281 | " save_iter=0, \n", 282 | " content_layers=content_layers, \n", 283 | " style_layers=style_layers, \n", 284 | " style_scale=style_scale, \n", 285 | " original_colors=original_colors, \n", 286 | " proto_file=proto_file,\n", 287 | " model_file=model_file,\n", 288 | " pooling=pooling,\n", 289 | " backend=backend,\n", 290 | " cudnn_autotune=cudnn_autotune,\n", 291 | " multigpu_strategy=multigpu_strategy,\n", 292 | " lbfgs_num_correction=lbfgs_num_correction,\n", 293 | " seed=-1)\n", 294 | " \n", 295 | " \n", 296 | " if not _DEBUG_MODE_:\n", 297 | " clear_output()\n", 298 | " else: \n", 299 | " show_image(img_out)\n", 300 | " \n", 301 | " if os.path.isfile(img_out):\n", 302 | " if step > 0:\n", 303 | " os.remove(init_image)\n", 304 | " \n", 305 | " if step < steps - 1:\n", 306 | " print('Step {}/{} complete! Proceeding...'.format(step+1, steps))\n", 307 | " else:\n", 308 | " print('All {} steps complete!'.format(steps))\n", 309 | " print('Final image saved to \"{}\"'.format(output_image))\n", 310 | " else:\n", 311 | " print('Step {}/{} FAILED!'.format(step+1, steps))\n", 312 | " if step > 0:\n", 313 | " os.rename(init_image, output_image)\n", 314 | " print('Image from previous step saved to \"{}\"'.format(output_image))\n", 315 | " return\n", 316 | "\n", 317 | "def ez_multires_transfer(style_image,\n", 318 | " content_image,\n", 319 | " style_blend_weights=None, #defaults to equal weights\n", 320 | " gpu=None, #defaults to 0, use -1 for CPU only (why would you?)\n", 321 | " content_weight=None, #defaults to '5e0'\n", 322 | " style_weight=None, #defaults to '1e2'\n", 323 | " tv_weight=None, #defaults to 1e-3\n", 324 | " num_iterations=None, #defaults to 1000\n", 325 | " init=None, #defaults to 'random', pass 'image' to use init_image\n", 326 | " init_image=None,\n", 327 | " optimizer=None, #defaults to 'lbfgs', 'adam' is lower mem but worse\n", 328 | " learning_rate=None, #defaults to '1e1', for ADAM only\n", 329 | " normalize_gradients=None, #defaults to unset, good for ADAM\n", 330 | " output_image=None, #defaults to 'out.png'\n", 331 | " print_iter=None, #defaults to 50, 0 to disable\n", 332 | " style_scale=None, #defaults to 1.0\n", 333 | " original_colors=None, #defaults to 0, 1 for original colors\n", 334 | " pooling=None, #defauls to 'max', 'avg' may or may not get better results\n", 335 | " multigpu_strategy=None, #default is '', see original documentation\n", 336 | " lbfgs_num_correction=None, #defauls to 0, higher gets better results I think\n", 337 | " \n", 338 | " start_size=512,\n", 339 | " final_size=None, #defaults to original content size\n", 340 | " step_size=250,\n", 341 | " cuda=True,\n", 342 | " model='vgg',\n", 343 | " clayers_override=None,\n", 344 | " slayers_override=None):\n", 345 | " \n", 346 | " m = ez_model(model,\n", 347 | " clayers_override = clayers_override,\n", 348 | " slayers_override = slayers_override)\n", 349 | " c = ez_cuda(cuda)\n", 350 | " \n", 351 | " r = multires_transfer(style_image,\n", 352 | " content_image,\n", 353 | " style_blend_weights=style_blend_weights,\n", 354 | " gpu=gpu,\n", 355 | " content_weight=content_weight,\n", 356 | " style_weight=style_weight, \n", 357 | " tv_weight=tv_weight,\n", 358 | " num_iterations=num_iterations,\n", 359 | " init=init, \n", 360 | " init_image=init_image,\n", 361 | " optimizer=optimizer, \n", 362 | " learning_rate=learning_rate, \n", 363 | " normalize_gradients=normalize_gradients,\n", 364 | " output_image=output_image,\n", 365 | " print_iter=print_iter,\n", 366 | " content_layers=m['content_layers'],\n", 367 | " style_layers=m['style_layers'],\n", 368 | " style_scale=style_scale,\n", 369 | " original_colors=original_colors,\n", 370 | " proto_file=m['proto_file'],\n", 371 | " model_file=m['model_file'],\n", 372 | " pooling=pooling,\n", 373 | " multigpu_strategy=multigpu_strategy,\n", 374 | " lbfgs_num_correction=lbfgs_num_correction,\n", 375 | " backend=c['backend'],\n", 376 | " cudnn_autotune=c['cudnn_autotune'],\n", 377 | " start_size=start_size,\n", 378 | " final_size=final_size,\n", 379 | " step_size=step_size)\n", 380 | "\n", 381 | "print('Notebook ready!')" 382 | ] 383 | }, 384 | { 385 | "cell_type": "code", 386 | "execution_count": null, 387 | "metadata": { 388 | "scrolled": true 389 | }, 390 | "outputs": [], 391 | "source": [ 392 | "ez_style_transfer(style_image = 'test_files/style/',\n", 393 | " content_image = 'test_files/content.jpg',\n", 394 | " style_weight = '1000',\n", 395 | " content_weight = '5',\n", 396 | " tv_weight = 0.00001,\n", 397 | " num_iterations = 1000,\n", 398 | " image_size = 512,\n", 399 | " print_iter = 50,\n", 400 | " save_iter = 0,\n", 401 | " model = 'nyud',\n", 402 | " output_image = 'start.png',\n", 403 | " normalize_gradients = True,\n", 404 | " clayers_override = 'relu1_1,relu2_1,relu3_1,relu4_1,relu5_1',\n", 405 | " slayers_override = 'relu1_1,relu2_1,relu3_1,relu4_1,relu5_1')\n", 406 | "\n", 407 | "print('Step complete!')" 408 | ] 409 | }, 410 | { 411 | "cell_type": "code", 412 | "execution_count": null, 413 | "metadata": { 414 | "scrolled": true 415 | }, 416 | "outputs": [], 417 | "source": [ 418 | "ez_style_transfer(style_image = 'test_files/style/',\n", 419 | " content_image = 'test_files/content.jpg',\n", 420 | " style_weight = '100',\n", 421 | " content_weight = '375',\n", 422 | " tv_weight = 0.00001,\n", 423 | " num_iterations = 500,\n", 424 | " image_size = 800,\n", 425 | " print_iter = 50,\n", 426 | " save_iter = 0,\n", 427 | " model = 'nyud',\n", 428 | " init = 'image',\n", 429 | " init_image = 'start.png',\n", 430 | " output_image = 'start2.png',\n", 431 | " normalize_gradients = True,\n", 432 | " clayers_override = 'relu1_1,relu2_1,relu3_1,relu4_1,relu5_1',\n", 433 | " slayers_override = 'relu1_1,relu2_1,relu3_1,relu4_1,relu5_1')\n", 434 | "\n", 435 | "print('Step complete!')" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "execution_count": null, 441 | "metadata": { 442 | "scrolled": true 443 | }, 444 | "outputs": [], 445 | "source": [ 446 | "ez_style_transfer(style_image = 'test_files/style/',\n", 447 | " content_image = 'test_files/content.jpg',\n", 448 | " style_weight = '1000',\n", 449 | " content_weight = '0',\n", 450 | " tv_weight = 0,\n", 451 | " num_iterations = 200,\n", 452 | " image_size = 1148,\n", 453 | " print_iter = 50,\n", 454 | " save_iter = 0,\n", 455 | " model = 'nyud',\n", 456 | " init = 'image',\n", 457 | " init_image = 'start2.png',\n", 458 | " output_image = 'start3.png',\n", 459 | " normalize_gradients = True,\n", 460 | " optimizer = 'adam',\n", 461 | " learning_rate = 1)\n", 462 | "\n", 463 | "print('Step complete!')" 464 | ] 465 | }, 466 | { 467 | "cell_type": "code", 468 | "execution_count": null, 469 | "metadata": { 470 | "scrolled": true 471 | }, 472 | "outputs": [], 473 | "source": [ 474 | "ez_style_transfer(style_image = 'test_files/style/',\n", 475 | " content_image = 'test_files/content.jpg',\n", 476 | " style_weight = '1000',\n", 477 | " content_weight = '0',\n", 478 | " tv_weight = 0,\n", 479 | " num_iterations = 600,\n", 480 | " image_size = 1800,\n", 481 | " print_iter = 50,\n", 482 | " save_iter = 0,\n", 483 | " model = 'channelpruning',\n", 484 | " output_image = 'pruned.png',\n", 485 | " init = 'image',\n", 486 | " init_image = 'start3.png',\n", 487 | " normalize_gradients = True,\n", 488 | " optimizer = 'adam',\n", 489 | " learning_rate = 1)\n", 490 | "\n", 491 | "print('Step complete!')" 492 | ] 493 | }, 494 | { 495 | "cell_type": "code", 496 | "execution_count": null, 497 | "metadata": { 498 | "scrolled": false 499 | }, 500 | "outputs": [], 501 | "source": [ 502 | "ez_multires_transfer(style_image = 'test_files/style/',\n", 503 | " content_image = 'test_files/content.jpg',\n", 504 | " style_weight = '1000',\n", 505 | " content_weight = '0',\n", 506 | " tv_weight = 0,\n", 507 | " num_iterations = 200,\n", 508 | " output_image = 'result.png',\n", 509 | " start_size = 2500,\n", 510 | " step_size = 250,\n", 511 | " init = 'image',\n", 512 | " init_image = 'pruned.png',\n", 513 | " final_size = 4500,\n", 514 | " print_iter = 50,\n", 515 | " model = 'nin',\n", 516 | " normalize_gradients = True,\n", 517 | " optimizer = 'adam',\n", 518 | " learning_rate = 1)\n", 519 | "\n", 520 | "print('Step complete!')" 521 | ] 522 | }, 523 | { 524 | "cell_type": "code", 525 | "execution_count": null, 526 | "metadata": { 527 | "scrolled": false 528 | }, 529 | "outputs": [], 530 | "source": [] 531 | } 532 | ], 533 | "metadata": { 534 | "kernelspec": { 535 | "display_name": "Python 3", 536 | "language": "python", 537 | "name": "python3" 538 | }, 539 | "language_info": { 540 | "codemirror_mode": { 541 | "name": "ipython", 542 | "version": 3 543 | }, 544 | "file_extension": ".py", 545 | "mimetype": "text/x-python", 546 | "name": "python", 547 | "nbconvert_exporter": "python", 548 | "pygments_lexer": "ipython3", 549 | "version": "3.6.8" 550 | } 551 | }, 552 | "nbformat": 4, 553 | "nbformat_minor": 2 554 | } 555 | -------------------------------------------------------------------------------- /volta-files/volta-x1.sh: -------------------------------------------------------------------------------- 1 | #https://github.com/jcjohnson/neural-style 2 | 3 | STYLE_IMAGE=$1 4 | CONTENT_IMAGE=$2 5 | 6 | 7 | 8 | verify_file() { 9 | if [ -f $1 ]; then 10 | echo "The file '$1' exists. Proceeding..." 11 | else 12 | echo "The file '$1' does not exist, likely the previous step failed." 13 | echo "Exiting..." 14 | exit 1 15 | fi 16 | } 17 | 18 | 19 | 20 | STYLE_WEIGHT=1000 21 | STYLE_SCALE=1 22 | CONTENT_WEIGHT=5 23 | 24 | th neural_style_dir_rng_fix.lua \ 25 | -style_image $STYLE_IMAGE \ 26 | -style_weight $STYLE_WEIGHT \ 27 | -style_scale $STYLE_SCALE \ 28 | -content_image $CONTENT_IMAGE \ 29 | -print_iter 1 \ 30 | -save_iter 100 \ 31 | -image_size 512 \ 32 | -num_iterations 1000 \ 33 | -model_file models/nyud-fcn32s-color-heavy.caffemodel \ 34 | -proto_file models/nyud-fcn32s-color-heavy-trainval.prototxt \ 35 | -content_layers relu1_1,relu2_1,relu3_1,relu4_1,relu5_1 \ 36 | -style_layers relu1_1,relu2_1,relu3_1,relu4_1,relu5_1 \ 37 | -optimizer lbfgs \ 38 | -output_image X1.png \ 39 | -tv_weight 0.00001 \ 40 | -gpu 0 \ 41 | -original_colors 0 \ 42 | -backend cudnn \ 43 | -init random \ 44 | 45 | verify_file X1.png 46 | 47 | 48 | 49 | STYLE_WEIGHT=100 50 | STYLE_SCALE=1 51 | CONTENT_WEIGHT=375 52 | 53 | th neural_style_dir_rng_fix.lua \ 54 | -style_image $STYLE_IMAGE \ 55 | -style_weight $STYLE_WEIGHT \ 56 | -style_scale $STYLE_SCALE \ 57 | -content_image $CONTENT_IMAGE \ 58 | -init image \ 59 | -init_image X1.png \ 60 | -print_iter 1 \ 61 | -image_size 800 \ 62 | -num_iterations 500 \ 63 | -model_file models/nyud-fcn32s-color-heavy.caffemodel \ 64 | -proto_file models/nyud-fcn32s-color-heavy-trainval.prototxt \ 65 | -content_layers relu1_1,relu2_1,relu3_1,relu4_1,relu5_1 \ 66 | -style_layers relu1_1,relu2_1,relu3_1,relu4_1,relu5_1 \ 67 | -optimizer lbfgs \ 68 | -output_image X2.png \ 69 | -tv_weight 0.00001 \ 70 | -gpu 0 \ 71 | -original_colors 0 \ 72 | -normalize_gradients \ 73 | -backend cudnn 74 | 75 | rm X1*.png 76 | 77 | verify_file X2.png 78 | 79 | 80 | 81 | STYLE_WEIGHT=1000 82 | STYLE_SCALE=1 83 | CONTENT_WEIGHT=0 84 | 85 | th neural_style_dir_rng_fix.lua \ 86 | -style_image $STYLE_IMAGE \ 87 | -style_weight $STYLE_WEIGHT \ 88 | -style_scale $STYLE_SCALE \ 89 | -content_image $CONTENT_IMAGE \ 90 | -content_weight $CONTENT_WEIGHT \ 91 | -output_image X3.png \ 92 | -num_iterations 200 \ 93 | -model_file models/nyud-fcn32s-color-heavy.caffemodel \ 94 | -proto_file models/nyud-fcn32s-color-heavy-trainval.prototxt \ 95 | -optimizer adam \ 96 | -print_iter 1 \ 97 | -save_iter 100 \ 98 | -tv_weight 0 \ 99 | -backend cudnn \ 100 | -init image \ 101 | -init_image X2.png \ 102 | -learning_rate 1 \ 103 | -image_size 1148 \ 104 | -gpu 0 \ 105 | -original_colors 0 \ 106 | -normalize_gradients \ 107 | 108 | rm X2*.png 109 | 110 | verify_file X3.png 111 | 112 | 113 | 114 | th neural_style_dir_rng_fix.lua \ 115 | -style_image $STYLE_IMAGE \ 116 | -style_weight $STYLE_WEIGHT \ 117 | -style_scale $STYLE_SCALE \ 118 | -content_image $CONTENT_IMAGE \ 119 | -content_weight $CONTENT_WEIGHT \ 120 | -output_image X4.png \ 121 | -num_iterations 600 \ 122 | -model_file models/channel_pruning.caffemodel \ 123 | -proto_file models/channel_pruning.prototxt \ 124 | -optimizer adam \ 125 | -print_iter 1 \ 126 | -save_iter 100 \ 127 | -tv_weight 0 \ 128 | -backend cudnn \ 129 | -init image \ 130 | -init_image X3.png \ 131 | -learning_rate 1 \ 132 | -image_size 1800 \ 133 | -gpu 0 \ 134 | -original_colors 0 \ 135 | -normalize_gradients \ 136 | 137 | rm X3*.png 138 | 139 | verify_file X4.png 140 | 141 | 142 | 143 | th neural_style_dir_rng_fix.lua \ 144 | -style_image $STYLE_IMAGE \ 145 | -style_weight $STYLE_WEIGHT \ 146 | -style_scale $STYLE_SCALE \ 147 | -content_image $CONTENT_IMAGE \ 148 | -content_weight $CONTENT_WEIGHT \ 149 | -output_image X5.png \ 150 | -model_file models/nin_imagenet_conv.caffemodel \ 151 | -proto_file models/train_val.prototxt \ 152 | -num_iterations 200 \ 153 | -content_layers relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8 \ 154 | -style_layers relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8 \ 155 | -optimizer adam \ 156 | -print_iter 1 \ 157 | -save_iter 100 \ 158 | -tv_weight 0 \ 159 | -backend cudnn \ 160 | -init image \ 161 | -init_image X4.png \ 162 | -learning_rate 1 \ 163 | -image_size 2550 \ 164 | -gpu 0 \ 165 | -original_colors 0 \ 166 | -normalize_gradients \ 167 | 168 | rm X4*.png 169 | 170 | verify_file X5.png 171 | 172 | 173 | 174 | STYLE_WEIGHT=1000 175 | STYLE_SCALE=1 176 | CONTENT_WEIGHT=0 177 | 178 | th neural_style_dir_rng_fix.lua \ 179 | -style_image $STYLE_IMAGE \ 180 | -style_weight $STYLE_WEIGHT \ 181 | -style_scale $STYLE_SCALE \ 182 | -content_image $CONTENT_IMAGE \ 183 | -content_weight $CONTENT_WEIGHT \ 184 | -output_image X6.png \ 185 | -model_file models/nin_imagenet_conv.caffemodel \ 186 | -proto_file models/train_val.prototxt \ 187 | -num_iterations 200 \ 188 | -content_layers relu0,relu1,relu2,relu3,relu5,relu6 \ 189 | -style_layers relu0,relu1,relu2,relu3,relu5,relu6 \ 190 | -optimizer adam \ 191 | -print_iter 1 \ 192 | -save_iter 100 \ 193 | -tv_weight 0 \ 194 | -backend cudnn \ 195 | -init image \ 196 | -init_image X5.png \ 197 | -learning_rate 1 \ 198 | -image_size 2700 \ 199 | -gpu 0 \ 200 | -original_colors 0 \ 201 | -normalize_gradients \ 202 | 203 | rm X5*.png 204 | 205 | verify_file X6.png 206 | 207 | 208 | 209 | th neural_style_dir_rng_fix.lua \ 210 | -style_image $STYLE_IMAGE \ 211 | -style_weight $STYLE_WEIGHT \ 212 | -style_scale $STYLE_SCALE \ 213 | -content_image $CONTENT_IMAGE \ 214 | -content_weight $CONTENT_WEIGHT \ 215 | -output_image X7.png \ 216 | -model_file models/nin_imagenet_conv.caffemodel \ 217 | -proto_file models/train_val.prototxt \ 218 | -num_iterations 200 \ 219 | -content_layers relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8 \ 220 | -style_layers relu0,relu1,relu2,relu3,relu5,relu6,relu7,relu8 \ 221 | -optimizer adam \ 222 | -print_iter 1 \ 223 | -save_iter 0 \ 224 | -tv_weight 0 \ 225 | -backend cudnn \ 226 | -init image \ 227 | -init_image X6.png \ 228 | -learning_rate 1 \ 229 | -image_size 2900 \ 230 | -gpu 0 \ 231 | -original_colors 0 \ 232 | -normalize_gradients \ 233 | 234 | rm X6*.png 235 | 236 | verify_file X7.png 237 | 238 | 239 | 240 | th neural_style_dir_rng_fix.lua \ 241 | -style_image $STYLE_IMAGE \ 242 | -style_weight $STYLE_WEIGHT \ 243 | -style_scale $STYLE_SCALE \ 244 | -content_image $CONTENT_IMAGE \ 245 | -content_weight $CONTENT_WEIGHT \ 246 | -output_image X8.png \ 247 | -model_file models/nin_imagenet_conv.caffemodel \ 248 | -proto_file models/train_val.prototxt \ 249 | -num_iterations 200 \ 250 | -content_layers relu0,relu1 \ 251 | -style_layers relu0,relu1 \ 252 | -optimizer adam \ 253 | -print_iter 1 \ 254 | -save_iter 0 \ 255 | -tv_weight 0 \ 256 | -backend cudnn \ 257 | -init image \ 258 | -init_image X7.png \ 259 | -learning_rate 1 \ 260 | -image_size 4000 \ 261 | -gpu 0 \ 262 | -original_colors 0 \ 263 | -normalize_gradients \ 264 | 265 | rm X7*.png 266 | 267 | verify_file X8.png 268 | 269 | 270 | 271 | STYLE_SCALE=0.5 272 | 273 | th neural_style_dir_rng_fix.lua \ 274 | -style_image $STYLE_IMAGE \ 275 | -content_image $CONTENT_IMAGE \ 276 | -output_image X9.png \ 277 | -model_file models/nin_imagenet_conv.caffemodel \ 278 | -proto_file models/train_val.prototxt \ 279 | -num_iterations 20 \ 280 | -content_layers relu0,relu1 \ 281 | -style_layers relu0,relu1 \ 282 | -optimizer adam \ 283 | -print_iter 1 \ 284 | -save_iter 0 \ 285 | -tv_weight 0 \ 286 | -style_scale $STYLE_SCALE \ 287 | -backend cudnn \ 288 | -content_weight $CONTENT_WEIGHT \ 289 | -style_weight $STYLE_WEIGHT \ 290 | -init image \ 291 | -init_image X8.png \ 292 | -learning_rate 1 \ 293 | -image_size 5600 \ 294 | -gpu 0 \ 295 | -original_colors 0 \ 296 | 297 | rm X8*.png 298 | 299 | verify_file X9.png 300 | 301 | 302 | 303 | # ENTERING PART 2 ## 304 | 305 | 306 | 307 | STYLE_WEIGHT=1000 308 | STYLE_SCALE=0.5 309 | CONTENT_WEIGHT=0 310 | 311 | th neural_style_dir_rng_fix.lua \ 312 | -style_image $STYLE_IMAGE \ 313 | -content_image $CONTENT_IMAGE \ 314 | -output_image X9a.png \ 315 | -model_file models/nin_imagenet_conv.caffemodel \ 316 | -proto_file models/train_val.prototxt \ 317 | -num_iterations 20 \ 318 | -content_layers relu0,relu1 \ 319 | -style_layers relu0,relu1 \ 320 | -optimizer adam \ 321 | -print_iter 1 \ 322 | -save_iter 0 \ 323 | -tv_weight 0 \ 324 | -style_scale $STYLE_SCALE \ 325 | -backend cudnn \ 326 | -content_weight $CONTENT_WEIGHT \ 327 | -style_weight $STYLE_WEIGHT \ 328 | -init image \ 329 | -init_image X9.png \ 330 | -learning_rate 1 \ 331 | -image_size 5500 \ 332 | -gpu 0 \ 333 | -original_colors 0 \ 334 | 335 | rm X9.png 336 | 337 | verify_file X9a.png 338 | 339 | 340 | 341 | th neural_style_dir_rng_fix.lua \ 342 | -style_image $STYLE_IMAGE \ 343 | -content_image $CONTENT_IMAGE \ 344 | -output_image X9b.png \ 345 | -model_file models/nin_imagenet_conv.caffemodel \ 346 | -proto_file models/train_val.prototxt \ 347 | -num_iterations 20 \ 348 | -content_layers relu0,relu1 \ 349 | -style_layers relu0,relu1 \ 350 | -optimizer adam \ 351 | -print_iter 1 \ 352 | -save_iter 0 \ 353 | -tv_weight 0 \ 354 | -style_scale $STYLE_SCALE \ 355 | -backend cudnn \ 356 | -content_weight $CONTENT_WEIGHT \ 357 | -style_weight $STYLE_WEIGHT \ 358 | -init image \ 359 | -init_image X9a.png \ 360 | -learning_rate 1 \ 361 | -image_size 5400 \ 362 | -gpu 0 \ 363 | -original_colors 0 \ 364 | 365 | rm X9a.png 366 | 367 | verify_file X9b.png 368 | 369 | 370 | 371 | th neural_style_dir_rng_fix.lua \ 372 | -style_image $STYLE_IMAGE \ 373 | -content_image $CONTENT_IMAGE \ 374 | -output_image X9c.png \ 375 | -model_file models/nin_imagenet_conv.caffemodel \ 376 | -proto_file models/train_val.prototxt \ 377 | -num_iterations 20 \ 378 | -content_layers relu0,relu1 \ 379 | -style_layers relu0,relu1 \ 380 | -optimizer adam \ 381 | -print_iter 1 \ 382 | -save_iter 0 \ 383 | -tv_weight 0 \ 384 | -style_scale $STYLE_SCALE \ 385 | -backend cudnn \ 386 | -content_weight $CONTENT_WEIGHT \ 387 | -style_weight $STYLE_WEIGHT \ 388 | -init image \ 389 | -init_image X9b.png \ 390 | -learning_rate 1 \ 391 | -image_size 5300 \ 392 | -gpu 0 \ 393 | -original_colors 0 \ 394 | 395 | rm X9b.png 396 | 397 | verify_file X9c.png 398 | 399 | 400 | 401 | th neural_style_dir_rng_fix.lua \ 402 | -style_image $STYLE_IMAGE \ 403 | -content_image $CONTENT_IMAGE \ 404 | -output_image X9d.png \ 405 | -model_file models/nin_imagenet_conv.caffemodel \ 406 | -proto_file models/train_val.prototxt \ 407 | -num_iterations 20 \ 408 | -content_layers relu0,relu1 \ 409 | -style_layers relu0,relu1 \ 410 | -optimizer adam \ 411 | -print_iter 1 \ 412 | -save_iter 0 \ 413 | -tv_weight 0 \ 414 | -style_scale $STYLE_SCALE \ 415 | -backend cudnn \ 416 | -content_weight $CONTENT_WEIGHT \ 417 | -style_weight $STYLE_WEIGHT \ 418 | -init image \ 419 | -init_image X9c.png \ 420 | -learning_rate 1 \ 421 | -image_size 5200 \ 422 | -gpu 0 \ 423 | -original_colors 0 \ 424 | 425 | rm X9c.png 426 | 427 | verify_file X9d.png 428 | 429 | 430 | 431 | th neural_style_dir_rng_fix.lua \ 432 | -style_image $STYLE_IMAGE \ 433 | -content_image $CONTENT_IMAGE \ 434 | -output_image X9e.png \ 435 | -model_file models/nin_imagenet_conv.caffemodel \ 436 | -proto_file models/train_val.prototxt \ 437 | -num_iterations 20 \ 438 | -content_layers relu0,relu1 \ 439 | -style_layers relu0,relu1 \ 440 | -optimizer adam \ 441 | -print_iter 1 \ 442 | -save_iter 0 \ 443 | -tv_weight 0 \ 444 | -style_scale $STYLE_SCALE \ 445 | -backend cudnn \ 446 | -content_weight $CONTENT_WEIGHT \ 447 | -style_weight $STYLE_WEIGHT \ 448 | -init image \ 449 | -init_image X9d.png \ 450 | -learning_rate 1 \ 451 | -image_size 5100 \ 452 | -gpu 0 \ 453 | -original_colors 0 \ 454 | 455 | rm X9d.png 456 | 457 | verify_file X9e.png 458 | 459 | 460 | 461 | th neural_style_dir_rng_fix.lua \ 462 | -style_image $STYLE_IMAGE \ 463 | -content_image $CONTENT_IMAGE \ 464 | -output_image X9f.png \ 465 | -model_file models/nin_imagenet_conv.caffemodel \ 466 | -proto_file models/train_val.prototxt \ 467 | -num_iterations 20 \ 468 | -content_layers relu0,relu1 \ 469 | -style_layers relu0,relu1 \ 470 | -optimizer adam \ 471 | -print_iter 1 \ 472 | -save_iter 0 \ 473 | -tv_weight 0 \ 474 | -style_scale $STYLE_SCALE \ 475 | -backend cudnn \ 476 | -content_weight $CONTENT_WEIGHT \ 477 | -style_weight $STYLE_WEIGHT \ 478 | -init image \ 479 | -init_image X9e.png \ 480 | -learning_rate 1 \ 481 | -image_size 5000 \ 482 | -gpu 0 \ 483 | -original_colors 0 \ 484 | 485 | rm X9e.png 486 | 487 | verify_file X9f.png 488 | 489 | 490 | 491 | th neural_style_dir_rng_fix.lua \ 492 | -style_image $STYLE_IMAGE \ 493 | -content_image $CONTENT_IMAGE \ 494 | -output_image X9g.png \ 495 | -model_file models/nin_imagenet_conv.caffemodel \ 496 | -proto_file models/train_val.prototxt \ 497 | -num_iterations 20 \ 498 | -content_layers relu0,relu1 \ 499 | -style_layers relu0,relu1 \ 500 | -optimizer adam \ 501 | -print_iter 1 \ 502 | -save_iter 0 \ 503 | -tv_weight 0 \ 504 | -style_scale $STYLE_SCALE \ 505 | -backend cudnn \ 506 | -content_weight $CONTENT_WEIGHT \ 507 | -style_weight $STYLE_WEIGHT \ 508 | -init image \ 509 | -init_image X9f.png \ 510 | -learning_rate 1 \ 511 | -image_size 4900 \ 512 | -gpu 0 \ 513 | -original_colors 0 \ 514 | 515 | rm X9f.png 516 | 517 | verify_file X9g.png 518 | 519 | 520 | 521 | th neural_style_dir_rng_fix.lua \ 522 | -style_image $STYLE_IMAGE \ 523 | -content_image $CONTENT_IMAGE \ 524 | -output_image X9h.png \ 525 | -model_file models/nin_imagenet_conv.caffemodel \ 526 | -proto_file models/train_val.prototxt \ 527 | -num_iterations 20 \ 528 | -content_layers relu0,relu1 \ 529 | -style_layers relu0,relu1 \ 530 | -optimizer adam \ 531 | -print_iter 1 \ 532 | -save_iter 0 \ 533 | -tv_weight 0 \ 534 | -style_scale $STYLE_SCALE \ 535 | -backend cudnn \ 536 | -content_weight $CONTENT_WEIGHT \ 537 | -style_weight $STYLE_WEIGHT \ 538 | -init image \ 539 | -init_image X9g.png \ 540 | -learning_rate 1 \ 541 | -image_size 4800 \ 542 | -gpu 0 \ 543 | -original_colors 0 \ 544 | 545 | rm X9g.png 546 | 547 | verify_file X9h.png 548 | 549 | 550 | 551 | th neural_style_dir_rng_fix.lua \ 552 | -style_image $STYLE_IMAGE \ 553 | -content_image $CONTENT_IMAGE \ 554 | -output_image X9i.png \ 555 | -model_file models/nin_imagenet_conv.caffemodel \ 556 | -proto_file models/train_val.prototxt \ 557 | -num_iterations 20 \ 558 | -content_layers relu0,relu1 \ 559 | -style_layers relu0,relu1 \ 560 | -optimizer adam \ 561 | -print_iter 1 \ 562 | -save_iter 0 \ 563 | -tv_weight 0 \ 564 | -style_scale $STYLE_SCALE \ 565 | -backend cudnn \ 566 | -content_weight $CONTENT_WEIGHT \ 567 | -style_weight $STYLE_WEIGHT \ 568 | -init image \ 569 | -init_image X9h.png \ 570 | -learning_rate 1 \ 571 | -image_size 4700 \ 572 | -gpu 0 \ 573 | -original_colors 0 \ 574 | 575 | rm X9h.png 576 | 577 | verify_file X9i.png 578 | 579 | 580 | 581 | th neural_style_dir_rng_fix.lua \ 582 | -style_image $STYLE_IMAGE \ 583 | -content_image $CONTENT_IMAGE \ 584 | -output_image X9j.png \ 585 | -model_file models/nin_imagenet_conv.caffemodel \ 586 | -proto_file models/train_val.prototxt \ 587 | -num_iterations 20 \ 588 | -content_layers relu0,relu1 \ 589 | -style_layers relu0,relu1 \ 590 | -optimizer adam \ 591 | -print_iter 1 \ 592 | -save_iter 0 \ 593 | -tv_weight 0 \ 594 | -style_scale $STYLE_SCALE \ 595 | -backend cudnn \ 596 | -content_weight $CONTENT_WEIGHT \ 597 | -style_weight $STYLE_WEIGHT \ 598 | -init image \ 599 | -init_image X9i.png \ 600 | -learning_rate 1 \ 601 | -image_size 4600 \ 602 | -gpu 0 \ 603 | -original_colors 0 \ 604 | 605 | rm X9i.png 606 | 607 | verify_file X9j.png 608 | 609 | 610 | 611 | th neural_style_dir_rng_fix.lua \ 612 | -style_image $STYLE_IMAGE \ 613 | -content_image $CONTENT_IMAGE \ 614 | -output_image X9k.png \ 615 | -model_file models/nin_imagenet_conv.caffemodel \ 616 | -proto_file models/train_val.prototxt \ 617 | -num_iterations 20 \ 618 | -content_layers relu0,relu1 \ 619 | -style_layers relu0,relu1 \ 620 | -optimizer adam \ 621 | -print_iter 1 \ 622 | -save_iter 0 \ 623 | -tv_weight 0 \ 624 | -style_scale $STYLE_SCALE \ 625 | -backend cudnn \ 626 | -content_weight $CONTENT_WEIGHT \ 627 | -style_weight $STYLE_WEIGHT \ 628 | -init image \ 629 | -init_image X9j.png \ 630 | -learning_rate 1 \ 631 | -image_size 4500 \ 632 | -gpu 0 \ 633 | -original_colors 0 \ 634 | 635 | rm X9j.png 636 | 637 | verify_file X9k.png 638 | 639 | 640 | 641 | th neural_style_dir_rng_fix.lua \ 642 | -style_image $STYLE_IMAGE \ 643 | -content_image $CONTENT_IMAGE \ 644 | -output_image X9l.png \ 645 | -model_file models/nin_imagenet_conv.caffemodel \ 646 | -proto_file models/train_val.prototxt \ 647 | -num_iterations 20 \ 648 | -content_layers relu0,relu1 \ 649 | -style_layers relu0,relu1 \ 650 | -optimizer adam \ 651 | -print_iter 1 \ 652 | -save_iter 0 \ 653 | -tv_weight 0 \ 654 | -style_scale $STYLE_SCALE \ 655 | -backend cudnn \ 656 | -content_weight $CONTENT_WEIGHT \ 657 | -style_weight $STYLE_WEIGHT \ 658 | -init image \ 659 | -init_image X9k.png \ 660 | -learning_rate 1 \ 661 | -image_size 4400 \ 662 | -gpu 0 \ 663 | -original_colors 0 \ 664 | 665 | rm X9k.png 666 | 667 | verify_file X9l.png 668 | 669 | 670 | 671 | th neural_style_dir_rng_fix.lua \ 672 | -style_image $STYLE_IMAGE \ 673 | -content_image $CONTENT_IMAGE \ 674 | -output_image final.png \ 675 | -model_file models/nin_imagenet_conv.caffemodel \ 676 | -proto_file models/train_val.prototxt \ 677 | -num_iterations 20 \ 678 | -content_layers relu0,relu1 \ 679 | -style_layers relu0,relu1 \ 680 | -optimizer adam \ 681 | -print_iter 1 \ 682 | -save_iter 0 \ 683 | -tv_weight 0 \ 684 | -style_scale $STYLE_SCALE \ 685 | -backend cudnn \ 686 | -content_weight $CONTENT_WEIGHT \ 687 | -style_weight $STYLE_WEIGHT \ 688 | -init image \ 689 | -init_image X9l.png \ 690 | -learning_rate 1 \ 691 | -image_size 4300 \ 692 | -gpu 0 \ 693 | -original_colors 0 \ 694 | 695 | rm X9l.png 696 | 697 | verify_file final.png 698 | 699 | 700 | 701 | echo "All done!" 702 | --------------------------------------------------------------------------------