deep-photo-styletransfer介绍

1.介绍

deep-photo-styletransfer:

2.安装

环境为mac10.13.2

2.1安装依赖

2.1.1 Torch

Torch是基于Lua语言的深度学习框架. 安装:

1
2
3
curl -s https://raw.githubusercontent.com/torch/ezinstall/master/install-deps | bash
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; ./install.sh

第一条命令安装了LuaJIT 和 Torch的依赖库。第二条命令安装LuaJIT, LuaRocks,然后用 LuaRocks (lua 包管理工具)安装核心包:torch, nn and paths, 和其它包。上面命令把 torch 加入到了你的PATH环境变量中了,用 source 更新一下让环境变量生效:

1
2
3
4
5
6
# 在 Linux 上
source ~/.bashrc
# 在 OSX 上
source ~/.profile

source ~/.bash_profile

如果你想要卸载 torch,执行:

1
rm -rf ~/torch

现在在你可以用 Luarocks 安装新的包

1
2
luarocks install image
luarocks list

安装完之后,你可以在终端用 th 命令运行 torch,现在进入了 torch 的交互模式,类似Python的交互模式。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ th

______ __ | Torch7
/_ __/__ ________/ / | Scientific computing for Lua.
/ / / _ / __/ __/ _ |
/_/ ___/_/ __/_//_/ | https://github.com/torch
| http://torch.ch

th> torch.Tensor{1,2,3}
1
2
3
[torch.DoubleTensor of dimension 3]

th>

要退出交互模式,两次Ctrl+C,或输入 os.exit()。 要执行 file.lua, 写 th> dofile “file.lua”。 在非交互模式下执行文件:

1
th file.lua

th 命令有很多选项,类似 perl 和 ruby。

1
2
3
4
5
6
7
8
9
10
11
12
13
$ th -h
Usage: th [options] [script.lua [arguments]]

Options:
-l name load library name
-e statement execute statement
-h,--help print this help
-a,--async preload async (libuv) and start async repl (BETA)
-g,--globals monitor global variables (print a warning on creation/access)
-gg,--gglobals monitor global variables (throw an error on creation/access)
-x,--gfx start gfx server and load gfx env
-i,--interactive enter the REPL after executing a script
Share the post "Mac OS X/Ubuntu 安装 Torch"

安装deep-photo-styletransfer所需依赖:

2.1.2Matlab or Octave

Matlab较大,而且是商用软件,所以选择了octave Octave是一款用于数值计算和绘图的开源软件, 精于矩阵运算:求解联立方程组、计算矩阵特征值和特征向量等等,并能够通过多种形式将数据可视化。Octave最简单的使用方式就是像使用一个计算器一样在命令提示符下输入相应的计算式。Octave能识别通常的计算表达式。例如,在终端输入

1
octave:##>2+2

mac下首先确保自己的Mac安装了Xcode和Command Line Tool,通过以下命令安装Command Line Tool,

1
xcode-select --install

之后安装Mac下的包管理神器Homebrew,命令如下,

1
curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local --strip 1

通过以下命令升级Homebrew:

1
sudo brew update && sudo brew upgrade

之后通过以下命令安装gcc、XQuartz,最后就可以通过Homebrew安装Octave了,

1
2
3
sudo brew install gcc
sudo brew install Caskroom/cask/xquartz
sudo brew install octave

mac下使用brew安装的octave是4.2版本,使用imread等函数时会提示:

1
2
3
4
5
error: Magick++ exception: octave-cli-4.2: Unable to access configuration file (delegates.mgk) reported by magick/blob.c:2101 (GetConfigureBlob)
error: called from
__imread__ at line 80 column 10
imageIO at line 117 column 26
imread at line 106 column 30

未找到原因,最后在https://wiki.octave.org/Octave_for_macOS#Simple_Installation_Instructions_2中下载[Mac OS X Bundle](https://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/2016-07-11-binary-octave-4.0.3/octave_gui_403_appleblas.dmg/download)中下载[4.0.3-gui](https://jaist.dl.sourceforge.net/project/octave/Octave%20MacOSX%20Binary/2016-07-11-binary-octave-4.0.3/octave_gui_403_appleblas.dmg)及[4.0.2 command line](https://jaist.dl.sourceforge.net/project/octave/Octave%20MacOSX%20Binary/2016-06-06-binary-octave-4.0.2/octave_cli_402.dmg)执行imread会出现:

1
warning: your version of GraphicsMagick limits images to <16> bits per pixel

根据GraphicsMagick中介绍是GraphicsMagick编译是参数不对,后下载(地址)使用

1
2
3
4
./configure --with-quantum-depth=16 --enable-shared --disable-static --with-magick-plus-plus=yes
make
make check
sudo make install

仍然不对,好像bound包依赖的库不是默认安装路径的. 使用最新的GraphicsMagick为1.3.27,命令行下可以使用gm命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ gm
GraphicsMagick 1.3.27 Q32 http://www.GraphicsMagick.org/
Copyright (C) 2002-2017 GraphicsMagick Group.
Additional copyrights and licenses apply to this software.
See http://www.GraphicsMagick.org/www/Copyright.html for details.
Usage: gm command [options ...]

Where commands include:
batch - issue multiple commands in interactive or batch mode
benchmark - benchmark one of the other commands
compare - compare two images
composite - composite images together
conjure - execute a Magick Scripting Language (MSL) XML script
convert - convert an image or sequence of images
help - obtain usage message for named command
identify - describe an image or image sequence
mogrify - transform an image or sequence of images
montage - create a composite image (in a grid) from separate images
time - time one of the other commands
version - obtain release version

可以使用pkg install -forge package安装Octave-Forge 中的包,如默认使用的image包:

1
pkg install -forge image

也可以下载其他版本的image包到本地执行pkg install image-2.4.1.tar.gz pkg list可列出已安装的包,安装好后不能直接使用,使用前要load

1
warning: the 'col2im' function belongs to the image package from Octave Forge which you have installed but not loaded.  To load the package, run 'pkg load image' from the Octave prompt.

有人使用docker容器解决了这个问题:https://github.com/martinbenson/deep-photo-styletransfer, 但是未尝试

GraphicsMagick UNIX/Cygwin/MinGW Compilation octave-devel 3.6.3 GraphicsMagick limits images to 8 bits per pixel Octave教程 Octave Tutorial Octave requirements Is removing the Matlab dependency possible? Added Matlab dependency alternative Re: [GM-apis] PythonMagick

2.1.3CUDA cudnn

NVIDIA cuDNN官网下载,文档地址

2.1.4下载VGG-19
1
sh models/download_models.sh
2.1.5Compile cuda_utils.cu (Adjust PREFIX and NVCC_PREFIX in makefile for your machine)

遇到问题:

1
THC.h includes THCGeneral.h, does not exist

解决:

1
2
3
4
I've fixed this issue by executing the following commands in terminal:

cd to you torch directory, and execute the update.sh script
second, execute "luarocks install cutorch"

可能有xcode Command Line Tool版本不兼容问题:

1
nvcc fatal : The version ('80100') of the host compiler ('Apple clang') is not supported

替换版本即可:

1
2
3
4
5
登录 https://developer.apple.com/downloads/
下载Xcode CLT (Command Line Tools) 8.2
安装 CLT
执行 sudo xcode-select --switch /Library/Developer/CommandLineTools
输入命令行查看clang版本 clang --version

THC.h includes THCGeneral.h, does not exist

相关资源

相关问题

  1. configure :error: No usable version of sed found: I did ./configure to make a makefile

but it ran into an error: configure :error: No usable version of sed found:

I then typed which see

it shows /usr/bin/sed.

so, what’s wrong? why can’t ./configure find sed?

I happened to have this problem on my mac. This is because OS X uses an old version of sed. Installing gnu-sed by brew install gnu-sed and alias gsed=sed solved this problem. You may install gnu-sed with other method.

https://stackoverflow.com/questions/26351285/configure-error-no-usable-version-of-sed-found

  1. gm-bin convert: Unable to access configuration file (delegates.mgk) [No such file or directory].

I am attempting to install GraphicsMagick in a hosting account…

I used this info to get it to work in most cases:

How do you specify the location of libraries to a binary? (linux)

However, it still cannot find the delegates.mgk (which is in ./lib/GraphicsMagick-1.3.14/delegates.mgk) as witnessed in this error:

gm-bin convert: Unable to access configuration file (delegates.mgk) [No such file or directory].

Either, a) how do find out where the binary thinks this file should be, or b) how do I extend the wrapper script to help it out?

Figured it out after looking through the binary for /PATH/

The binaries require these additional path variables:

1
2
3
$MAGICK_CONFIG_PATH
$MAGICK_CODER_MODULE_PATH
$MAGICK_FILTER_MODULE_PATH

…here is the resulting script modification form my setup:

1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
if [ -n "$LD_LIBRARY_PATH" ]; then
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/USER/lib
else
LD_LIBRARY_PATH=/home/USER/lib
fi
[ -z "${MAGICK_CONFIGURE_PATH}" ] && export MAGICK_CONFIGURE_PATH=/home/USER/lib/GraphicsMagick-1.3.14/config
[ -z "${MAGICK_CODER_MODULE_PATH}" ] && export MAGICK_CODER_MODULE_PATH=/home/USER/lib/GraphicsMagick-1.3.14/modules-Q8/coders
[ -z "${MAGICK_FILTER_MODULE_PATH}" ] && export MAGICK_FILTER_MODULE_PATH=/home/USER/lib/GraphicsMagick-1.3.14/modules-Q8/filters
export LD_LIBRARY_PATH
exec /home/USER/bin/gm-bin "$@"
坚持原创技术分享,您的支持将鼓励我继续创作!