安裝 Anaconda
- 在官網下載安裝文件。
- 選擇所需的python版本(我的是python3.7)
- 選擇合適的系統(linux 64)
- 下載後的文件名爲:Anaconda3-2019.07-Linux-x86_64.sh
-
在終端或命令行中輸入安裝命令,按提示安裝
bash Anaconda3-2019.07-Linux-x86_64.sh
-
設置環境變量
- 打開配置文件
vim ~/.bashrc
- 在最後一行添加
export PATH=/home/XXX/anaconda3/bin:$PATH
(注意改成自己的路徑) - 更新配置文件
source ~/.bashrc
安裝latent_3d_points所需的庫
-
添加conda國內鏡像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ conda config --set show_channel_urls yes
-
新建環境 latent_3d_points
conda activate -n latent_3d_points python=2.7 tensorflow=1.3.0
-
激活環境
conda activate latent_3d_points
可以進入python環境,檢驗tensorflow是否成功安裝了,輸入:python
>>>import tensorflow as tf
若未提示錯誤則成功安裝
-
安裝numpy, scipy, matplotlib, notebook
conda install numpy scipy matplotlib notebook
-
安裝cuda, cudnn
conda install cudatoolkit=8.0 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/ conda install cudnn=6.0 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/
-
安裝tflearn
conda install -c contango tflearn
同樣,進入python環境,檢驗tflearn是否成功安裝。輸入:python
>>>import tflearn
若未提示錯誤則成功安裝
latent_3d_points前期準備
-
下載latent_3d_points源碼
git clone https://github.com/optas/latent_3d_points
-
官網指示,進入latent_3d_points/external/structural_losses目錄,修改makefile文件的前三行,改爲自己的目錄。
with your editor modify the first three lines of the makefile to point to
your nvcc, cudalib and tensorflow library.但這樣修改在之後運行中會出現問題,所以這裏我們先不修改。
NameError: global name ‘nn_distance’ is not defined
-
先確定自己的tensorflow路徑
新建find.py文件:vim find.py
find.py文件內容:from __future__ import print_function import tensorflow as tf print(tf.sysconfig.get_compile_flags(),'\n') print(tf.sysconfig.get_link_flags())
輸出結果:
['-I/home/xxj/.local/lib/python2.7/site-packages/tensorflow/include', '-D_GLIBCXX_USE_CXX11_ABI=0'] ['-L/home/xxj/.local/lib/python2.7/site-packages/tensorflow', '-l:libtensorflow_framework.so.1']
-
根據上個步驟的輸出結果,修改makefile文件,-I之後的內容爲TF_INC,-L之後的內容爲TF_LIB。
注意makefile中的D_GLIBCXX_USE_CXX11_ABI等於0還是1,以及-l:libtensorflow_framework.so.1,這兩部分都需對應自己上一步的輸出。vim makefile
nvcc=/usr/local/cuda-8.0/bin/nvcc cudalib=/usr/local/cuda-8.0/lib64 nsync=/home/xxj/.local/lib/python2.7/site-packages/tensorflow/include/external/nsync/public TF_INC=/home/xxj/.local/lib/python2.7/site-packages/tensorflow/include TF_LIB=/home/xxj/.local/lib/python2.7/site-packages/tensorflow all: tf_approxmatch_so.so tf_approxmatch_g.cu.o tf_nndistance_so.so tf_nndistance_g.cu.o tf_approxmatch_so.so: tf_approxmatch_g.cu.o tf_approxmatch.cpp g++ -std=c++11 tf_approxmatch.cpp tf_approxmatch_g.cu.o -o tf_approxmatch_so.so -shared -fPIC -I $(TF_INC) -I $(nsync) -lcudart -L $(cudalib) -L $(TF_LIB) -l:libtensorflow_framework.so.1 -O2 -D_GLIBCXX_USE_CXX11_ABI=0 tf_approxmatch_g.cu.o: tf_approxmatch_g.cu $(nvcc) -std=c++11 -c -o tf_approxmatch_g.cu.o tf_approxmatch_g.cu -I $(TF_INC) -I $(nsync) -DGOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -O2 -D_GLIBCXX_USE_CXX11_ABI=0 tf_nndistance_so.so: tf_nndistance_g.cu.o tf_nndistance.cpp g++ -std=c++11 tf_nndistance.cpp tf_nndistance_g.cu.o -o tf_nndistance_so.so -shared -fPIC -I $(TF_INC) -I $(nsync) -lcudart -L $(cudalib) -L $(TF_LIB) -l:libtensorflow_framework.so.1 -O2 -D_GLIBCXX_USE_CXX11_ABI=0 tf_nndistance_g.cu.o: tf_nndistance_g.cu $(nvcc) -std=c++11 -c -o tf_nndistance_g.cu.o tf_nndistance_g.cu -I $(TF_INC) -I $(nsync) -DGOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -O2 -D_GLIBCXX_USE_CXX11_ABI=0 clean: rm tf_approxmatch_so.so rm tf_nndistance_so.so rm *.cu.o
修改完之後重新
make
如果修改過程中出了錯,先make clean
,再make
。 -
新建test.py文件驗證
vim test.py
文件內容如下
import tensorflow as tf nn_distance_module = tf.load_op_library('./tf_nndistance_so.so')
沒問題就可以繼續往下了
-
下載訓練集,進入latent_3d_points/目錄,運行.sh文件
cd latent_3d_points/ ./download_data.sh
-
親測,數據集網站需要科學上網。服務器沒法翻牆的,可以在本地先下好文件。數據集網址
-
將數據集文件上傳到服務器上
scp shape_net_core_uniform_samples_2048.zip username@serverIP:~/yourdir/
-
隨後在服務器上進行一系列操作
unzip shape_net_core_uniform_samples_2048.zip rm shape_net_core_uniform_samples_2048.zip mkdir -p data mv shape_net_core_uniform_samples_2048 data
train_single_class_ae.ipynb
終於可以運行AE啦
-
進入latent_3d_points/notebook目錄,在遠程服務器上,啓動jupyter notebook
jupyter notebook --no-browser --port=8889
-
在本地終端中啓動ssh,-N告訴ssh沒有命令要被遠程執行;-f高速ssh在後臺執行;-L是制定port forwarding的配置,遠程端口是8889,本地端口是8888,username和serverIP改爲自己服務器的IP和用戶名。
ssh -N -f -L localhost:8888:localhost:8889 username@serverIP
-
修改第一個代碼塊的前三行
import os.path as osp import sys sys.path.append(osp.abspath('../../'))
-
一步一步運行代碼塊,完成訓練
('Epoch:', '0001', 'training time (minutes)=', '3.7933', 'loss=', '0.003890567') ('Epoch:', '0002', 'training time (minutes)=', '3.7374', 'loss=', '0.001670681') ('Epoch:', '0003', 'training time (minutes)=', '3.7908', 'loss=', '0.001491568') ('Epoch:', '0004', 'training time (minutes)=', '3.7857', 'loss=', '0.001336398') ('Epoch:', '0005', 'training time (minutes)=', '3.7789', 'loss=', '0.001254967') ('Epoch:', '0006', 'training time (minutes)=', '3.7355', 'loss=', '0.001193760') ('Epoch:', '0007', 'training time (minutes)=', '3.7446', 'loss=', '0.001187483') ('Epoch:', '0008', 'training time (minutes)=', '3.7677', 'loss=', '0.001118673') ('Epoch:', '0009', 'training time (minutes)=', '3.7224', 'loss=', '0.001070869') ('Epoch:', '0010', 'training time (minutes)=', '3.6812', 'loss=', '0.001053343')
參考:
ubuntu利用conda創建虛擬環境,並安裝cuda,cudnn,pytorch
latent_3d_points代碼復現:train_single_class_ae.ipynb
遠程訪問服務器Jupyter Notebook的兩種方法