├── .clang-format ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE.txt ├── NeuralStyle ├── CMakeLists.txt └── src │ ├── convert_image_multi.py │ └── main.cpp ├── README.md └── README_ja.md /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: Google 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeFiles 2 | CMakeCache.txt 3 | Makefile 4 | cmake_install.cmake 5 | 6 | lib -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "opentoonz_plugin_utility"] 2 | path = opentoonz_plugin_utility 3 | url = https://github.com/opentoonz/opentoonz_plugin_utility.git 4 | [submodule "neural_style_synthesizer"] 5 | path = neural_style_synthesizer 6 | url = https://github.com/dwango/neural_style_synthesizer.git 7 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.4) 2 | project(neural_style_plugin) 3 | 4 | if(WIN32) 5 | if(CMAKE_SIZEOF_VOID_P EQUAL 4) 6 | set(PLATFORM1 32) 7 | set(PLATFORM2) 8 | else() 9 | set(PLATFORM1 64) 10 | set(PLATFORM2 _64) 11 | endif() 12 | 13 | if(PLATFORM1 EQUAL 64) 14 | add_definitions(-Dx64) 15 | endif() 16 | 17 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /openmp") 18 | set(PLUGIN_UTILITY_LIB "${CMAKE_CURRENT_SOURCE_DIR}/opentoonz_plugin_utility/lib/${CMAKE_CFG_INTDIR}/libopentoonz_plugin_utility") 19 | endif(WIN32) 20 | 21 | if(APPLE) 22 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -stdlib=libc++") 23 | set(PLUGIN_UTILITY_LIB "${CMAKE_CURRENT_SOURCE_DIR}/opentoonz_plugin_utility/lib/${CMAKE_CFG_INTDIR}/libopentoonz_plugin_utility.a") 24 | endif(APPLE) 25 | 26 | find_package(OpenCV REQUIRED) 27 | set(LIBS ${OpenCV_LIBS} "${PLUGIN_UTILITY_LIB}") 28 | 29 | include_directories(opentoonz_plugin_utility/include 30 | opentoonz_plugin_utility/opentoonz_plugin_headers 31 | "${OpenCV_INCLUDE_DIRS}") 32 | link_directories("${OpenCV_LIBS}") 33 | 34 | add_subdirectory(opentoonz_plugin_utility) 35 | add_subdirectory(NeuralStyle) 36 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, DWANGO Co., Ltd. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | -------------------------------------------------------------------------------- /NeuralStyle/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PLUGIN_NAME NeuralStyle) 2 | set(PLUGIN_VENDOR DWANGO) 3 | 4 | set(SOURCES 5 | src/main.cpp) 6 | 7 | add_library(${PLUGIN_NAME} SHARED ${HEADERS} ${SOURCES} ) 8 | 9 | set_target_properties(${PLUGIN_NAME} PROPERTIES 10 | PREFIX "${PLUGIN_VENDOR}_" 11 | SUFFIX ".plugin" 12 | ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../lib" 13 | LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../lib" 14 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin") 15 | 16 | add_definitions(-DPLUGIN_NAME="${PLUGIN_NAME}") 17 | add_definitions(-DPLUGIN_VENDOR="${PLUGIN_VENDOR}") 18 | 19 | target_link_libraries(${PLUGIN_NAME} ${LIBS}) 20 | -------------------------------------------------------------------------------- /NeuralStyle/src/convert_image_multi.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import shutil 3 | import time 4 | 5 | parser = argparse.ArgumentParser() 6 | parser.add_argument("content_image") 7 | parser.add_argument("texture_image") 8 | parser.add_argument("--output_image", required=True) 9 | parser.add_argument("--content_weight", type=float, default=0.005) 10 | parser.add_argument("--gpu", type=int, default=-1) 11 | parser.add_argument("--iteration", type=int, default=1000) 12 | parser.add_argument("--xsplit", type=int, default=1) 13 | parser.add_argument("--ysplit", type=int, default=1) 14 | parser.add_argument("--resize", type=int, default=300, 15 | help="maximum size of height and width for content and texture images") 16 | parser.add_argument("--out_dir", required=True) 17 | parser.add_argument("--no_optimize", dest="optimize", action="store_false") 18 | args = parser.parse_args() 19 | 20 | shutil.copyfile(args.content_image, args.output_image) 21 | -------------------------------------------------------------------------------- /NeuralStyle/src/main.cpp: -------------------------------------------------------------------------------- 1 | #define TNZU_DEFINE_INTERFACE 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | class MyFx : public tnzu::Fx { 9 | public: 10 | // 11 | // PORT 12 | // 13 | enum { 14 | PORT_CONTENT, 15 | PORT_STYLE, 16 | PORT_COUNT, 17 | }; 18 | 19 | int port_count() const override { return PORT_COUNT; } 20 | 21 | char const* port_name(int i) const override { 22 | static std::array names = { 23 | "Content", "Style", 24 | }; 25 | return names[i]; 26 | } 27 | 28 | // 29 | // PARAM GROUP 30 | // 31 | enum { 32 | PARAM_GROUP_DEFAULT, 33 | PARAM_GROUP_COUNT, 34 | }; 35 | 36 | int param_group_count() const override { return PARAM_GROUP_COUNT; } 37 | 38 | char const* param_group_name(int i) const override { 39 | static std::array names = { 40 | "Default", 41 | }; 42 | return names[i]; 43 | } 44 | 45 | // 46 | // PARAM 47 | // 48 | enum { 49 | PARAM_XSPLIT, 50 | PARAM_YSPLIT, 51 | PARAM_RESIZE, 52 | PARAM_ITERATION, 53 | PARAM_METHOD, 54 | PARAM_MODEL, 55 | PARAM_SMOOTH, 56 | PARAM_OPTIMIZE, 57 | PARAM_GPU, 58 | PARAM_CONTENT_WEIGHT, 59 | PARAM_PAUSE, 60 | PARAM_COUNT, 61 | }; 62 | 63 | int param_count() const override { return PARAM_COUNT; } 64 | 65 | ParamPrototype const* param_prototype(int i) const override { 66 | static std::array const params = { 67 | ParamPrototype{"xsplit", PARAM_GROUP_DEFAULT, 1, 1, 16}, 68 | ParamPrototype{"ysplit", PARAM_GROUP_DEFAULT, 1, 1, 16}, 69 | ParamPrototype{"resize", PARAM_GROUP_DEFAULT, 1, 0, 1}, 70 | ParamPrototype{"iteration", PARAM_GROUP_DEFAULT, 10, 0, 1000}, 71 | ParamPrototype{"method", PARAM_GROUP_DEFAULT, 1, 0, 1}, 72 | ParamPrototype{"model", PARAM_GROUP_DEFAULT, 0, 0, 1}, 73 | ParamPrototype{"smooth", PARAM_GROUP_DEFAULT, 0, 0, 1}, 74 | ParamPrototype{"optimize", PARAM_GROUP_DEFAULT, 1, 0, 1}, 75 | ParamPrototype{"gpu", PARAM_GROUP_DEFAULT, -1, -1, 3}, 76 | ParamPrototype{"content_weight", PARAM_GROUP_DEFAULT, 0.005, 0, 0.1}, 77 | ParamPrototype{"pause", PARAM_GROUP_DEFAULT, 0, 0, 1}, 78 | }; 79 | return ¶ms[i]; 80 | } 81 | 82 | public: 83 | int end_render() override { 84 | std::lock_guard lock(mutex_); 85 | for (auto&& file : history_) { 86 | remove(file.c_str()); 87 | } 88 | history_.clear(); 89 | return 0; 90 | } 91 | 92 | int enlarge(Config const& config, Params const& params, 93 | cv::Rect2d& retrc) override { 94 | retrc = tnzu::make_infinite_rect(); 95 | return 0; 96 | } 97 | 98 | int compute(Config const& config, Params const& params, Args const& args, 99 | cv::Mat& retimg) override try { 100 | DEBUG_PRINT(__FUNCTION__); 101 | if (args.invalid(PORT_STYLE)) { 102 | if (args.valid(PORT_CONTENT)) { 103 | tnzu::draw_image(retimg, args.get(PORT_CONTENT), 104 | args.offset(PORT_CONTENT)); 105 | } 106 | return 0; 107 | } 108 | 109 | if (args.invalid(PORT_CONTENT)) { 110 | if (args.valid(PORT_STYLE)) { 111 | tnzu::draw_image(retimg, args.get(PORT_STYLE), args.offset(PORT_STYLE)); 112 | } 113 | return 0; 114 | } 115 | 116 | // params 117 | cv::Size const size = retimg.size(); 118 | int const xsplit = params.get(PARAM_XSPLIT); 119 | int const ysplit = params.get(PARAM_YSPLIT); 120 | int const resize = 121 | params.get(PARAM_RESIZE, std::max(size.width, size.height)); 122 | int const iteration = params.get(PARAM_ITERATION); 123 | bool const method = params.get(PARAM_METHOD); 124 | bool const model = params.get(PARAM_MODEL); 125 | bool const smooth = params.get(PARAM_SMOOTH); 126 | bool const optimize = params.get(PARAM_OPTIMIZE); 127 | int const gpu = params.get(PARAM_GPU); 128 | double const content_weight = params.get(PARAM_CONTENT_WEIGHT); 129 | bool const pause = params.get(PARAM_PAUSE); 130 | 131 | std::string const out_dir = 132 | #ifdef _WIN32 133 | "C:/TEMP/" 134 | #else 135 | "/tmp/" 136 | #endif 137 | ; 138 | 139 | std::string content; 140 | { 141 | std::ostringstream out; 142 | out << out_dir << port_name(PORT_CONTENT) << "[" << config.frame 143 | << "].png"; 144 | content = out.str(); 145 | } 146 | 147 | std::string style; 148 | { 149 | std::ostringstream out; 150 | out << out_dir << port_name(PORT_STYLE) << "[" << config.frame << "].png"; 151 | style = out.str(); 152 | } 153 | 154 | std::string output; 155 | { 156 | cv::Mat const& content_img = args.get(PORT_CONTENT); 157 | cv::Mat const& style_img = args.get(PORT_STYLE); 158 | 159 | std::uint64_t const content_hash = tnzu::hash(content_img); 160 | std::uint64_t const style_hash = tnzu::hash(style_img); 161 | 162 | std::ostringstream out; 163 | out << out_dir << tnzu::plugin_info()->name << '[' << config.frame 164 | << "]{C{w=" << content_img.cols << ",h=" << content_img.rows 165 | << ",t=" << content_img.type() << ",n=" << content_hash << "}" 166 | << ",S{w=" << style_img.cols << ",h=" << style_img.rows 167 | << ",t=" << style_img.type() << ",n=" << style_hash << "}" 168 | << ",w=" << retimg.cols << ",h=" << retimg.rows 169 | << ",t=" << retimg.type() << ",x=" << xsplit << ",y=" << ysplit 170 | << ",r=" << resize << ",i=" << iteration << ",p=" << method 171 | << ",m=" << model << ",s=" << smooth << ",c=" << content_weight 172 | << "}.png"; 173 | output = out.str(); 174 | } 175 | 176 | std::string init_image; 177 | if (smooth) { 178 | std::lock_guard lock(mutex_); 179 | if (!history_.empty()) { 180 | init_image = history_.back(); 181 | } 182 | } 183 | 184 | std::string command_line; 185 | { 186 | std::ostringstream out; 187 | #ifdef _WIN32 188 | out << "pushd \"%VS120COMNTOOLS%/../../VC\" & vcvarsall.bat amd64 & popd " 189 | "& pushd \"" << Fx::get_stuff_dir() 190 | << "/plugins/neural_style_synthesizer\" & "; 191 | #endif 192 | out << "python bin/convert_image_multi.py" 193 | << " --iteration=" << iteration << " --gpu=" << gpu 194 | << " --xsplit=" << xsplit << " --ysplit=" << ysplit << " \"" 195 | << content << "\" \"" << style << "\"" 196 | << " --model=" << (model ? "vgg" : "nin") << " --output_image=\"" 197 | << output << "\" --out_dir=\"" << out_dir << "\"" 198 | << " --content_weight=" << content_weight; 199 | if (resize > 0) { 200 | out << " --resize=" << resize; 201 | } 202 | if (method) { 203 | out << " --average_pooling"; 204 | } 205 | if (smooth && !init_image.empty()) { 206 | out << " --init_image=\"" << init_image << '\"'; 207 | } 208 | if (!optimize) { 209 | out << " --no_optimize"; 210 | } 211 | #ifdef _WIN32 212 | out << " & popd"; 213 | if (pause) { 214 | out << " & pause"; 215 | } 216 | #endif 217 | command_line = out.str(); 218 | } 219 | DEBUG_PRINT(command_line.c_str()); 220 | 221 | tnzu::draw_image(retimg, args.get(PORT_CONTENT), args.offset(PORT_CONTENT)); 222 | 223 | if (!tnzu::file_exists(output.c_str())) { 224 | try { 225 | cv::imwrite(content, retimg); 226 | } catch (std::runtime_error const& e) { 227 | DEBUG_PRINT("failed to save a content image: " << e.what()); 228 | return 0; 229 | } 230 | 231 | try { 232 | cv::imwrite(style, args.get(PORT_STYLE)); 233 | } catch (std::runtime_error const& e) { 234 | DEBUG_PRINT("failed to save a style image: " << e.what()); 235 | remove(content.c_str()); 236 | return 0; 237 | } 238 | 239 | if (gpu >= 0) { 240 | std::lock_guard lock(mutexes_[gpu]); 241 | system(command_line.c_str()); 242 | } else { 243 | system(command_line.c_str()); 244 | } 245 | 246 | remove(content.c_str()); 247 | remove(style.c_str()); 248 | } 249 | 250 | cv::Mat src = cv::imread(output); 251 | 252 | if ((src.cols <= 0) || (src.rows <= 0)) { 253 | DEBUG_PRINT("failed to load a output image"); 254 | return 0; 255 | } 256 | 257 | cv::resize(src, src, size); 258 | 259 | if (retimg.type() == CV_8UC4) { 260 | for (int y = 0; y < size.height; ++y) { 261 | cv::Vec3b const* s = src.ptr(y); 262 | cv::Vec4b* d = retimg.ptr(y); 263 | for (int x = 0; x < size.width; ++x) { 264 | d[x][0] = s[x][0]; 265 | d[x][1] = s[x][1]; 266 | d[x][2] = s[x][2]; 267 | // without an alpha channel 268 | } 269 | } 270 | } else { 271 | for (int y = 0; y < size.height; ++y) { 272 | cv::Vec3b const* s = src.ptr(y); 273 | cv::Vec4w* d = retimg.ptr(y); 274 | for (int x = 0; x < size.width; ++x) { 275 | d[x][0] = s[x][0] << 8; 276 | d[x][1] = s[x][1] << 8; 277 | d[x][2] = s[x][2] << 8; 278 | // without an alpha channel 279 | } 280 | } 281 | } 282 | 283 | { 284 | // register history 285 | std::lock_guard lock(mutex_); 286 | history_.push_back(output); 287 | } 288 | 289 | return 0; 290 | } catch (cv::Exception const& e) { 291 | DEBUG_PRINT(e.what()); 292 | } 293 | 294 | private: 295 | std::mutex mutex_; 296 | std::vector history_; 297 | 298 | std::array mutexes_; 299 | }; 300 | 301 | namespace tnzu { 302 | PluginInfo const* plugin_info() { 303 | static PluginInfo const info(TNZU_PP_STR(PLUGIN_NAME), // name 304 | TNZU_PP_STR(PLUGIN_VENDOR), // vendor 305 | "", // note 306 | "http://dwango.co.jp/"); // helpurl 307 | return &info; 308 | } 309 | 310 | Fx* make_fx() { return new MyFx(); } 311 | } 312 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NeuralStyle Plugin ([日本語](./README_ja.md)) 2 | ==================== 3 | 4 | This plugin effect transfers style of `style image` to `content image` using neural network. 5 | 6 | The model files of neural networks are not contained in this repository. 7 | You can get them from [nin_imagenet.caffemodel](https://gist.github.com/mavenlin/d802a5849de39225bcc6) and [VGG_ILSVRC_16_layers.caffemodel](https://gist.github.com/ksimonyan/211839e770f7b538e2d8#file-readme-md). 8 | 9 | ## How to install 10 | 11 | ### OS X 12 | 13 | TBD 14 | 15 | ### Windows 16 | 17 | #### w/ GPU 18 | 19 | 0. install `Visual Studio 2013` 20 | * [link1](https://www.visualstudio.com/en-US/downloads/download-visual-studio-vs.aspx) 21 | 0. install `CUDA Toolkit 7.5` (Windows x86_64) 22 | * [link2](https://developer.nvidia.com/cuda-downloads) 23 | 0. install `cuDNN v4 Library for Windows` 24 | * [link3](https://developer.nvidia.com/rdp/cudnn-download) 25 | * copy `bin`, `include`, and `lib` directories to `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5`. 26 | 0. install `Python 2.7 WIndows 64-bit` 27 | * [link4](https://www.continuum.io/downloads) 28 | 0. install `openopt` 29 | * exec `pip install openopt` on command prompt 30 | 0. install `cvxopt` 31 | * download `cvxopt-1.1.7+openblas-cp27-none-win_amd64.whl` from [link5](http://www.lfd.uci.edu/~gohlke/pythonlibs/#cvxopt) 32 | * exec `pip install cvxopt-1.1.7+openblas-cp27-none-win_amd64.whl` on command prompt 33 | 0. install `chainer` 34 | * exec ```set VS100COMNTOOLS=%VS120COMNTOOLS%` ; set PATH=%VS120COMNTOOLS%\..\..\VC\bin;%PATH%` ; pip install chainer``` on command prompt 35 | 0. copy `neural_style_synthesizer` directory and `DWANGO_NeuralStyle.plugin` to `${path-to-stuff}/plugins` 36 | 0. copy `nin_imagenet.caffemodel` and `VGG_ILSVRC_16_layers.caffemodel` to `${path-to-stuff}/plugins/neural_style_synthesizer` 37 | 38 | #### w/o GPU 39 | 40 | 0. install `Python 2.7 WIndows 64-bit` 41 | * [link4](https://www.continuum.io/downloads) 42 | 0. install `openopt` 43 | * exec `pip install openopt` on command prompt 44 | 0. install `cvxopt` 45 | * download `cvxopt-1.1.7+openblas-cp27-none-win_amd64.whl` from [link5](http://www.lfd.uci.edu/~gohlke/pythonlibs/#cvxopt) 46 | * exec `pip install cvxopt-1.1.7+openblas-cp27-none-win_amd64.whl` on command prompt 47 | 0. install `chainer` 48 | * exec ```pip install chainer``` on command prompt 49 | 0. copy `neural_style_synthesizer` directory and `DWANGO_NeuralStyle.plugin` to `${path-to-stuff}/plugins` 50 | 0. copy `nin_imagenet.caffemodel` and `VGG_ILSVRC_16_layers.caffemodel` to `${path-to-stuff}/plugins/neural_style_synthesizer` 51 | 52 | ## How to use 53 | 54 | ### input ports 55 | 56 | | port name | | 57 | | --- | --- | 58 | | `Content` | content image | 59 | | `Style` | style image | 60 | 61 | ### parameters 62 | 63 | | param name | default value | min value | max value | | 64 | | --- | ---:| ---:| ---:| --- | 65 | | `xsplit` | 1.000 | 1 | 16.0 | the number of horizontal style image splits | 66 | | `ysplit` | 1.000 | 1 | 16.0 | the number of vertical style image splits | 67 | | `resize` | 1.000 | 0 | 1.0 | resize factor: 1 (original size), 0.5 (half size), 0.1 (1/10 size), and so on. | 68 | | `iteration` | 10.000 | 0 | 1000.0 | the number of iterations for style optimization | 69 | | `method` | 1.000 | 0 | 1.0 | method flag for neural network: `{0: max_pooling, 1: average_pooling}`. The default value is recommended. | 70 | | `model` | 0.000 | 0 | 1.0 | model of neural network: `{0: nin, 1: vgg}`, `nin` is a small and `vgg` is a large model (*) | 71 | | `smooth` | 0.000 | 0 | 1.0 | sequential processing flag: `{0: off, 1: on}` (*) | 72 | | `optimize` | 1.000 | 0 | 1.0 | whether to optimize the mixture ratio of style image parts: `{0: off, 1: on}`. The default value is recommended. | 73 | | `gpu` | -1.000 | -1 | 3.0 | GPU id (CPUs are used when `gpu` euqals to `-1`) | 74 | | `content_weight` | 0.005 | 0 | 0.1 | content image weight for style optimization | 75 | | `pause` | 0.000 | 0 | 1.0 | do-not-automatically-close-consoles flag for debugging: `{0: off, 1: on}` (only for Windows) | 76 | 77 | (*) You have to set `Dedicated CPUs` to `Single` at `Preview Settings` and `Output Settings`, when you use the `vgg` model or enable the `smooth` flag. 78 | 79 | The first execution is time-consuming, because the plugin generates a cache of the neural network models. 80 | -------------------------------------------------------------------------------- /README_ja.md: -------------------------------------------------------------------------------- 1 | NeuralStyle Plugin ([English](./README.md)) 2 | ==================== 3 | 4 | 本プラグインは、ニューラルネットワークを利用して、スタイル画像の画風をコンテンツ画像に転写するエフェクトです。 5 | 6 | ニューラルネットワークのモデルファイルは同梱していないので、動作させるためには、 [nin_imagenet.caffemodel](https://gist.github.com/mavenlin/d802a5849de39225bcc6) および [VGG_ILSVRC_16_layers.caffemodel](https://gist.github.com/ksimonyan/211839e770f7b538e2d8#file-readme-md) を入手してください。 7 | 8 | ## インストール 9 | 10 | ### OS X 11 | 12 | TBD 13 | 14 | ### Windows 15 | 16 | 本プラグインを Windows 上で動作させるためには、下記の環境設定が必要になります。 17 | 18 | #### GPU を使う場合 19 | 20 | 0. `Visual Studio Community 2013` をインストールする 21 | * [link1](https://www.visualstudio.com/ja-jp/downloads/download-visual-studio-vs.aspx) から Web インストーラをダウンロードして実行します 22 | 0. `CUDA Toolkit 7.5` をインストールする 23 | * [link2](https://developer.nvidia.com/cuda-downloads) で `Windows` `x86_64` を選択して、インストーラをダウンロード、実行します 24 | 0. `cuDNN` をインストールする 25 | * [link3](https://developer.nvidia.com/rdp/cudnn-download) から、ライセンスに同意後、`cuDNN v4 Library for Windows` をダウンロードします 26 | * 解凍してできる `bin`, `include`, `lib` ディレクトリを `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5` 以下に、上書きコピーします 27 | 0. `Python` をインストールする 28 | * [link4](https://www.continuum.io/downloads) から `PYTHON 2.7` の Windows 64-bit 版をダウンロードして、インストールします 29 | 0. `openopt` をインストールする 30 | * コマンドプロンプトから `pip install openopt` を実行します 31 | 0. `cvxopt` をインストールする 32 | * [link5](http://www.lfd.uci.edu/~gohlke/pythonlibs/#cvxopt) から `cvxopt-1.1.7+openblas-cp27-none-win_amd64.whl` をダウンロードします 33 | * コマンドプロンプトから `pip install cvxopt-1.1.7+openblas-cp27-none-win_amd64.whl` を実行します 34 | 0. `chainer` をインストールする 35 | * コマンドプロンプトから ```set VS100COMNTOOLS=%VS120COMNTOOLS%` ; set PATH=%VS120COMNTOOLS%\..\..\VC\bin;%PATH% ; pip install chainer``` を実行します。 36 | 0. `neural_style_synthesizer` ディレクトリと `DWANGO_NeuralStyle.plugin` を `${path-to-stuff}/plugins` にコピーする 37 | 0. `${path-to-stuff}/plugins/neural_style_synthesizer` に `nin_imagenet.caffemodel` と `VGG_ILSVRC_16_layers.caffemodel` をコピーする 38 | 39 | お疲れ様でした。 40 | 41 | #### GPU を使わない場合 42 | 43 | 0. `Python` をインストールする 44 | * [link4](https://www.continuum.io/downloads) から `PYTHON 2.7` の Windows 64-bit 版をダウンロードして、インストールします 45 | 0. `openopt` をインストールする 46 | * コマンドプロンプトから `pip install openopt` を実行します 47 | 0. `cvxopt` をインストールする 48 | * [link5](http://www.lfd.uci.edu/~gohlke/pythonlibs/#cvxopt) から `cvxopt-1.1.7+openblas-cp27-none-win_amd64.whl` をダウンロードします 49 | * コマンドプロンプトから `pip install cvxopt-1.1.7+openblas-cp27-none-win_amd64.whl` を実行します 50 | 0. `chainer` をインストールする 51 | * コマンドプロンプトから ```pip install chainer``` を実行します 52 | * CUDA Toolkit がインストールされていると、実行に失敗する場合があります。その際は、上記の GPU を使う場合の手順を試すか、CUDA Toolkit をアンインストールしてください。 53 | 0. `neural_style_synthesizer` ディレクトリと `DWANGO_NeuralStyle.plugin` を `${path-to-stuff}/plugins` にコピーする 54 | 0. `${path-to-stuff}/plugins/neural_style_synthesizer` に `nin_imagenet.caffemodel` と `VGG_ILSVRC_16_layers.caffemodel` をコピーする 55 | 56 | ## マニュアル 57 | 58 | ### 入力ポート 59 | 60 | | ポート名 | 説明 | 61 | | --- | --- | 62 | | `Content` | コンテンツ画像 | 63 | | `Style` | スタイル画像 | 64 | 65 | ### パラメータ 66 | 67 | | パラメータ名 | デフォルト値 | 最小値 | 最大値 | 説明 | 68 | | --- | ---:| ---:| ---:| --- | 69 | | `xsplit` | 1.000 | 1 | 16.0 | スタイル画像の横方向の分割数 | 70 | | `ysplit` | 1.000 | 1 | 16.0 | スタイル画像の縦方向の分割数 | 71 | | `resize` | 1.000 | 0 | 1.0 | 画面のリサイズ: そのまま 1, 半分 0.5, 十分の一 0.1 など | 72 | | `iteration` | 10.000 | 0 | 1000.0 | 最適化の反復回数 | 73 | | `method` | 1.000 | 0 | 1.0 | `{0: max_pooling, 1: average_pooling}`。通常、デフォルト値から変更する必要はありません | 74 | | `model` | 0.000 | 0 | 1.0 | `{0: nin, 1: vgg}`。`nin` が軽量なモデルで、`vgg` が大きいモデルです (※) | 75 | | `smooth` | 0.000 | 0 | 1.0 | `{0: off, 1: on}`。連番処理をするかのフラグ (※) | 76 | | `optimize` | 1.000 | 0 | 1.0 | `{0: off, 1: on}`、分割したスタイルを最適化するかのフラグ。通常、デフォルト値から変更する必要はありません | 77 | | `gpu` | -1.000 | -1 | 3.0 | 利用する GPU 番号 (-1 は CPU を意味します) | 78 | | `content_weight` | 0.005 | 0 | 0.1 | コンテンツ画像らしさを残す重み | 79 | | `pause` | 0.000 | 0 | 1.0 | デバッグ用に実行時に表示されるコンソールを開いたままにする (Windows 専用) | 80 | 81 | ※ `vgg` のような大きいモデルを使う場合や、`smooth` フラグで連番処理する場合は、必ず `プレビュー設定` と `出力設定` の `使用 CPU 数` を `1 つ` に設定してください。 82 | 83 | モデルファイルのキャッシュを生成するために、初期起動時は時間がかかります。 84 | --------------------------------------------------------------------------------