deep-painterly-harmonization测试记录
安装CUDA & cudnn
参见另一篇Ubuntu 16.04 GTX950M + cuda9.0 + cuDNN7.0 + TensorFlow 1.5 / 1.8 安装记录
安装Pytorch
最后发现要求的不是pytorch而是torch
中文文档:http://pytorch-cn.readthedocs.io/zh/latest/
# pip3 Python3.5 CUDA9.0
pip3 install http://download.pytorch.org/whl/cu90/torch-0.4.0-cp35-cp35m-linux_x86_64.whl
pip3 install torchvision
#pip2 Python2.7 CUDA9.0
pip install http://download.pytorch.org/whl/cu90/torch-0.4.0-cp27-cp27mu-linux_x86_64.whl
pip install torchvision
# if the above command does not work, then you have python 2.7 UCS2, use this command 如果上面的命令不起作用,那么你有python 2.7 UCS2,使用这个命令
pip install http://download.pytorch.org/whl/cu90/torch-0.4.0-cp27-cp27m-linux_x86_64.whl
查看当前pytorch的版本
import torch
print(torch.__version__)
安装torch
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch
bash install-deps
./install.sh
不幸的是,编译出错:
lib/THC/CMakeFiles/THC.dir/build.make:4243: recipe for target 'lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMathPairwise.cu.o' failed
make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMathPairwise.cu.o] Error 1
/pkgbuild/torch/torch/extra/cutorch/lib/THC/generic/THCTensorMath.cu(393): error: more than one operator "==" matches these operands:
function "operator==(const __half &, const __half &)"
function "operator==(half, half)"
operand types are: half == half
/pkgbuild/torch/torch/extra/cutorch/lib/THC/generic/THCTensorMath.cu(414): error: more than one operator "==" matches these operands:
function "operator==(const __half &, const __half &)"
function "operator==(half, half)"
operand types are: half == half
原因是cuda和torch的头文件都提供了相同的重载运算符,编译器不知道用哪一个。输入下面shell命令禁止使用cuda的头文件编译torch即可:
export TORCH_NVCC_FLAGS="-D__CUDA_NO_HALF_OPERATORS__"
重新运行./install.sh
重新开始编译就OK了。
source ~/.zshrc
之后输入命令th
,如果能够出现下边的界面,安装成功
安装loadcaffe
# 依赖th
sudo apt-get install libprotobuf-dev protobuf-compiler
# Then install the package itself:
luarocks install loadcaffe
# In Ubuntu 16.04 you need to use gcc-5:
CC=gcc-5 CXX=g++-5 luarocks install loadcaffe
# 测试
$ th
th> require 'loadcaffe'
{
load : function: 0x4182c4c8
C : userdata: 0x40636248
}
[0.0719s]
th>
export TORCH_NVCC_FLAGS="-D__CUDA_NO_HALF_OPERATORS__"
直接在命令行用export添加路径,只能在当前shell脚本下可用,切换到另一个终端就会失效。要使设置永久有效,需要在如下文本里面添加命令,比如:
/etc/profile #开机执行,对所有shell用户执行环境变量设置,重启生效;常用
~/.bashrc #开机和登录执行bash shell采用;source ~/.bashrc生效,常用
/etc/bash.bashrc #~/.bashrc更广的版本
~/.profile #不能被bash读取
调用顺序:/etc/profile/-----> ~/.bashrc ------> /etc/bash.bashrc
# 参考 https://blog.csdn.net/Ychan_cc/article/details/66970190
**错误信息:**Couldn’t load .caffemodel
Couldn't load models/VGG_ILSVRC_19_layers.caffemodel /home/sun/torch/install/bin/luajit: neural_gram.lua:98: attempt to index a nil value stack traceback: neural_gram.lua:98: in function 'main' neural_gram.lua:450: in main chunk [C]: in function 'dofile' .../sun/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk [C]: at 0x00405d50 # 解决 检查.caffemodel文件是否损坏。 重新下载
Out of memory
THCudaCheck FAIL file=/home/sun/torch/extra/cutorch/lib/THC/generic/THCStorage.cu line=66 error=2 : out of memory /home/sun/torch/install/bin/luajit: neural_gram.lua:134: cuda runtime error (2) : out of memory at /home/sun/torch/extra/cutorch/lib/THC/generic/THCStorage.cu:66 stack traceback: [C]: in function 'patchmatch_r' neural_gram.lua:134: in function 'main' neural_gram.lua:450: in main chunk [C]: in function 'dofile' .../sun/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk [C]: at 0x00405d50 # 解决 这是因为GPU内存不够用。用小一点的图片作为输入或者用小点的网络。 vim gen_all.py # 找到 -image_size 700 一共有两行这个 i7-6700HQ Geforce 950M 4G显存 -image_size 500 # 可以运行 但是很慢很慢 显存使用情况 3920MiB / 4046MiB -image_size 300 # 这个还好一点
安装Octave
经查阅,通过sudo apt-get install octave
默认安装的为Octave-4.0.0
, 4.0.0
版本的好像有Bug,于是选择下面这个方式安装:
sudo apt-add-repository ppa:octave/stable
sudo apt-get update
sudo apt-get install octave
# 移除已安装的所有版本的Octave
# sudo apt-get remove octave
命令行 输入 octave 即可启动,然后固定在启动栏
运行deep-painterly-harmonization
# Download VGG-19:
sh models/download_models.sh
# Compile cuda_utils.cu (Adjust PREFIX and NVCC_PREFIX in makefile for your machine):
make clean && make
# To generate all results (in data/) using the provided scripts, simply run this in Python
python gen_all.py
# and then run in Matlab or Octave. The final output will be in results/.
run('filt_cnn_artifact.m')
部分错误参考链接 Github issue