Spherical CNNs代码配置过程

ICLR18 best paper: Spherical CNNs

论文链接:https://arxiv.org/abs/1801.10130

GITHUB地址:https://github.com/jonas-koehler/s2cnn

中文讲解地址:

 

简介:

In this paper we introduce the building blocks for constructing spherical CNNs. We propose a definition for the spherical cross-correlation that is both expressive and rotation-equivariant. The spherical correlation satisfies a generalized Fourier theorem, which allows us to compute it efficiently using a generalized (non-commutative) Fast Fourier Transform (FFT) algorithm. We demonstrate the computational efficiency, numerical accuracy, and effectiveness of spherical CNNs applied to 3D model recognition and atomization energy regression.

 

下面是详细的代码配置过程:

 

1. 运行环境配置

1.1    安装Anaconda

下载地址:https://www.anaconda.com/download/

 

安装参考:致Python初学者:Anaconda入门使用指南

注意如果你想随时使用conda,就要将anaconda添加到环境变量中(其实在安装的时候会问你是否加入环境变量,选择yes后,还是可能会没有被添加),即在/home/yourname目录下,输入(如果你在使用bash就输入下面的命令,否则改成相应的如.zshrc):

vim .bashrc

然后在文件末尾添加上:

export PATH=/home/yourname/anaconda3/bin:$PATH

再输入以下命令使环境变量立刻生效:

source .bashrc

 

如果你不想更改系统的python环境变量,就不要把conda加入到系统的环境变量里,

而是每次都在虚拟环境里使用conda

 

安装虚拟环境,并切换至虚拟环境,参考:https://segmentfault.com/a/1190000005828284

比如这里使用了:

# 创建虚拟环境
~/anaconda3/bin/conda create -n py3 python=3.6

# 激活虚拟环境
source ~/anaconda3/bin/activate py3

 

1.1.1    为了下载速度更快,更换conda下载源为清华大学镜像

 参考:https://blog.csdn.net/huludan/article/details/52711550

运行以下两行命令即可:

conda config --add channels 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/'
conda config --set show_channel_urls yes

 

 

1.2    安装Pytorch

地址:http://pytorch.org

请选择适合自己的安装方法,这里我们选择了运行以下命令:

conda install pytorch torchvision cuda91 -c pytorch

 

1.3    安装CUPY

地址:https://github.com/cupy/cupy

安装方法:

conda install cupy
不要使用!!!!这个可能就是导致一直出BUG的元凶!!!!!
pip install cupy --user

 

1.4    安装lie_learn

地址:https://github.com/AMLab-Amsterdam/lie_learn.git

输入以下命令:

git clone https://github.com/AMLab-Amsterdam/lie_learn.git
python setup.py install

 中间需要从Google Drive获取J_dense_0-278.npy(下载链接),嗯……自己想办法吧

或者手动下载下来,然后将其放在这个路径:(会有路径提示,认真看)

~/anaconda3/lib/python3.6/site-packages/lie_learn/representations/SO3/pinchon_hoggan

  

1.5    安装pynvrtc

输入命令:

pip install pynvrtc --user

 

2. Spherical CNNs

2.1    安装Spherical CNNs

执行以下命令:

git clone https://github.com/jonas-koehler/s2cnn
cd s2cnn
vim setup.py [怎么修改请看下面,需要删除一个'r']
python setup.py install

 在setup.py中有一行是读取README.md文件,但是报错说编码格式错误,

请参考:https://github.com/jonas-koehler/s2cnn/issues/3

adding , encoding='utf-8' instead of 'r', encoding='utf8' in open() function in setup.py file

这个如果不解决,之后会出现报错:module 's2cnn.ops.gpu.lib_cufft' has no attribute 'destroy'

作者已经把源代码改了,无需关注此问题

 

2.2    运行equivariance_error 的例子来测试是否真正安装成功

运行命令:

python main.py

如果出现返回以下结果,则证明安装成功:

main.py:38: UserWarning: volatile was removed and now has no effect. Use with torch.no_grad(): instead.
x = torch.autograd.Variable(torch.randn(1, 12, 128, 128), volatile=True).cuda() # [batch, feature, beta, alpha]
relative error = 0.022134914994239807

2.2.1    如果出现module 's2cnn.ops.gpu.lib_cufft' has no attribute 'destroy'

参见我的提问:https://github.com/jonas-koehler/s2cnn/issues/5

我尝试在不同的3个服务器上安装了7、8次,最终有一次安装成功了,没有报出这个错误。但是和之前的安装方案并没有什么区别,所以这里也很迷茫。

有一位网友说在s2cnn/setup.py中,修改为

long_description=open(os.path.join(os.path.dirname(__file__), "README.md"), 'r', encoding='utf8').read()

而目前(20180502)作者将这里修改为了

long_description=open(os.path.join(os.path.dirname(__file__), "README.md"), encoding='utf8').read()

 

实测网友给出的方案后,会出现新的BUG,详见https://github.com/jonas-koehler/s2cnn/issues/3

所以,目前只能多试试了

 

下面给出作者的安装流程:https://github.com/jonas-koehler/s2cnn/issues/5

I created a new anaconda environment and I installed everything.
I didn't manage to install cupy with cuda9 so I did all with cuda8.

Create new env:
conda create --name s2cnn_test python=3.6
conda activate s2cnn_test
Compile s2cnn:
conda install pytorch torchvision -c pytorch (version0.4.0-py36_cuda8.0.61_cudnn7.1.2_1)
pip install cupy-cuda80 (version cupy-cuda80-4.0.0)
pip install pynvrtc
python setup.py install
Install lie_learn:
conda install -c anaconda cython
conda install -c anaconda requests
git clone https://github.com/AMLab-Amsterdam/lie_learn.git
python setup.py install
Run the equivariance_error example
conda install -c anaconda scipy
python main.py

 

2.3    运行example之shrec17

例子地址:https://github.com/jonas-koehler/s2cnn/tree/master/examples/shrec17

2.3.1    安装trimesh和pyembree

仓库地址:https://github.com/mikedh/trimesh

# install modules for spatial indexing and  polygon manipulation
# these generally install cleanly on Linux, Windows, and OSX
conda install -c conda-forge rtree shapely

# install pyembree for fast ray queries
# Linux and OSX only
conda install -c conda-forge pyembree

# install Trimesh and soft dependencies that are easy to install # these generally install cleanly on Linux, Windows, and OSX pip install trimesh[easy]

 

2.3.2    训练网络

python train.py --model_path model.py --log_dir my_run --dataset train --batch_size 32 --augmentation 4

这行命令执行过程中会下载一个很大很大的数据集,数据集的主页:https://shapenet.cs.stanford.edu/shrec17/

 

2.3.3    验证训练后的网络

在运行之前,先安装nodejs才行,

这里使用了以下命令来进行安装

conda install nodejs

然后执行验证程序

python test.py --log_dir my_run --dataset val --batch_size 32 --augmentation 4
cat my_run/summary.csv | grep micro

 

2.3.4    报错处理

如果出现这个错误:No such file or directory: 'nodejs': 'nodejs'

解决方案:通过conda,在虚拟环境中安装的包,都在虚拟环境下能够找到,比如这里,我的包的路径在:

~/anaconda3/envs/s2cnn_test/bin

在bin目录下能够找到一个文件叫做node,所以,执行以下命令:

cd ~/anaconda3/envs/s2cnn_test/bin
cp -r node nodejs

就可以解决这个报错了

 

如果出现找不到scipy:

不要使用 conda install scipy,

这行命令会把pytorch降级到0.1.0版本。

应该使用如下命令:

conda install -c anaconda scipy 

 

posted on 2018-04-25 20:06  Oliver-cs  阅读(2756)  评论(3编辑  收藏  举报

导航