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 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM