域自適應的代碼環境再次配置筆記

有用的文章參考:
https://github.com/jwyang/faster-rcnn.pytorch

https://github.com/tiancity-NJU/da-faster-rcnn-PyTorch

https://github.com/divyam02/dafrcnn-pytorch

https://blog.csdn.net/xinyu_cheng/article/details/89321655

https://github.com/naoto0804/cross-domain-detection

https://github.com/VisionLearningGroup/DA_Detection

https://www.cnblogs.com/wzyuan/p/11105758.html

https://www.commonlounge.com/discussion/da0c2181dbd34c4aa7776f0a351408b8

https://zhuanlan.zhihu.com/p/57737230

#########################################################################
在服務器上新建立用戶,然後安裝anaconda

bash Anaconda3-5.2.0-Linux-x86_64.sh
conda create -n tch04 python=3.6
conda activate tch04
conda install pytorch=0.4.0 cuda90 -c pytorch
conda install torchvision=0.2.1
conda install cudatoolkit=9.0
conda update -n base -c defaults conda
conda update numpy
pip install numpy==1.17.0
pip install --upgrade numpy
conda install scipy=1.2.1

========================================================================
查看驅動

nvidia-smi


安裝cuda9.0

sudo sh cuda_9.0.176_384.81_linux.run --no-opengl-libs

Do you accept the previously read EULA?
 2 accept/decline/quit: accept
 3 Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?
 4 (y)es/(n)o/(q)uit: n
 5 Install the CUDA 9.0 Toolkit?
 6 (y)es/(n)o/(q)uit: y
 7 Enter Toolkit Location
 8 [ default is /usr/local/cuda-9.0 ]:  
 9 Do you want to install a symbolic link at /usr/local/cuda?
10 (y)es/(n)o/(q)uit: y
11 Install the CUDA 9.0 Samples?
12 (y)es/(n)o/(q)uit: y
13 Enter CUDA Samples Location
14 [ default is /home/pertor ]:  
15 Installing the CUDA Toolkit in /usr/local/cuda-9.0 ...
16 Missing recommended library: libXmu.so

sudo vim ~/.bashrc

“i”
export PATH=/usr/local/cuda-9.0/bin:$PATH 
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
“esc” “:wq:”

source ~/.bashrc

檢查是否安裝成功

cd /usr/local/cuda-9.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery

安裝cudnn

cd -
tar -zxvf cudnn-9.0-linux-x64-v7.6.2.24.tgz
shenfanshu@ubuntu-server:~/A_ment$ cd /usr/local/cuda
shenfanshu@ubuntu-server:/usr/local/cuda$ ls
bin     include  libnsight         nvml       samples  tools
doc     jre      libnvvp           nvvm       share    version.txt
extras  lib64    nsightee_plugins  pkgconfig  src
shenfanshu@ubuntu-server:/usr/local/cuda$ sudo rm -rf /usr/local/cuda
shenfanshu@ubuntu-server:/usr/local/cuda$ cd ..
shenfanshu@ubuntu-server:/usr/local$ sudo rm -rf /usr/local/cuda
shenfanshu@ubuntu-server:/usr/local$ ls
bin       cuda-9.0  games    lib  python  share
cuda-8.0  etc       include  man  sbin    src
shenfanshu@ubuntu-server:/usr/local$ sudo ln -s /usr/local/cuda-9.0 /usr/local/cuda 
shenfanshu@ubuntu-server:/usr/local$ ls
bin   cuda-8.0  etc    include  man     sbin   src
cuda  cuda-9.0  games  lib      python  share

shenfanshu@ubuntu-server:/usr/local/cuda$ cd /home/shenfanshu/A_ment
shenfanshu@ubuntu-server:~/A_ment$ 
shenfanshu@ubuntu-server:~/A_ment$ sudo cp cuda/include/cudnn.h /usr/local/cuda-9.0/include/
shenfanshu@ubuntu-server:~/A_ment$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda-9.0/lib64/ -d
shenfanshu@ubuntu-server:~/A_ment$ sudo chmod a+r /usr/local/cuda-9.0/include/cudnn.h
shenfanshu@ubuntu-server:~/A_ment$ sudo chmod a+r /usr/local/cuda-9.0/lib64/libcudnn*
shenfanshu@ubuntu-server:~/A_ment$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176


========================================================================
測試torch0.4.0的安裝

(tch04) shenfanshu@ubuntu-server:~/B_code/faster-rcnn.pytorch-master$ python
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 19:07:31) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__ 
'0.4.0'
>>> torch.version.cuda
'9.0.176'
>>> quit()

========================================================================
測試例程的運行
#############################
faster-rcnn.pytorch-master 
-----------------------------
簡單的faster-rcnn,已經事先參照官網步驟下載好了所有需要使用到的數據集
torch = 0.4.0
python = 3.6 
torchvision=0.2.1
cuda = 9.0
#############################

(tch04) shen@ubuntu-server:~/myments/anaconda/doc$ cd /home/shen/C_codeTemplate/faster-rcnn.pytorch-master
(tch04) shen@ubuntu-server:~/C_codeTemplate/faster-rcnn.pytorch-master$ pip install -r requirements.txt 
(tch04) shen@ubuntu-server:~/C_codeTemplate/faster-rcnn.pytorch-master$ cd lib
(tch04) shen@ubuntu-server:~/C_codeTemplate/faster-rcnn.pytorch-master/lib$ sh make.sh
(tch04) shen@ubuntu-server:~/C_codeTemplate/faster-rcnn.pytorch-master/lib$ cd ..
(tch04) shen@ubuntu-server:~/C_codeTemplate/faster-rcnn.pytorch-master$


###訓練###

CUDA_VISIBLE_DEVICES=2 python trainval_net.py --dataset pascal_voc --net vgg16 --bs 1 --nw 4  --cuda

 

[session 1][epoch  1][iter 2100/10022] loss: 0.9306, lr: 1.00e-03
            fg/bg=(14/242), time cost: 17.289636
            rpn_cls: 0.1146, rpn_box: 0.0270, rcnn_cls: 0.2293, rcnn_box 0.1312


###批量測試###

python test_net.py --dataset pascal_voc --net vgg16 --checksession 1 --checkepoch 20 --checkpoint 10021  --cuda

###demo###

(tch04) shen@ubuntu-server:~/C_codeTemplate/faster-rcnn.pytorch-master
python demo.py --net vgg16  --checksession 1 --checkepoch 20 --checkpoint 10021 --cuda


會生成det結尾的圖片
========================================================================

例程代碼運行2 
da-faster-rcnn-PyTorch-master
-----------------------------

簡單的faster-rcnn,已經事先參照官網步驟下載好了所有需要使用到的數據集


#############################

cd /home/shen/C_codeTemplate/da-faster-rcnn-PyTorch-master
(tch04) shenfanshu@ubuntu-server:~/B_code/da-faster-rcnn-PyTorch-master$ pip install -r requirements.txt 
(tch04) shenfanshu@ubuntu-server:~/B_code/da-faster-rcnn-PyTorch-master$ cd lib(tch04) shenfanshu@ubuntu-server:~/B_code/da-faster-rcnn-PyTorch-master/lib$ sh make.sh
(tch04) shenfanshu@ubuntu-server:~/B_code/da-faster-rcnn-PyTorch-master/lib$ cd ..

#-----------------------------------------
# train cityscapes -> cityscapes-foggy
#-----------------------------------------

CUDA_VISIBLE_DEVICES=0 python da_trainval_net.py --dataset cityscape --net vgg16 --bs 1 --lr 2e-3 --lr_decay_step 6 --cuda

   

 allow_unreachable=True)  # allow_unreachable flag
RuntimeError: cuda runtime error (2) : out of memory at /opt/conda/conda-bld/pytorch_1524586445097/work/aten/src/THC/generic/THCStorage.cu:58

超內存了,確實運行的程序有點多了不行,哈哈哈
驚訝的發現服務器有4塊1080,一直用的是第0塊,可以用第1塊,哈哈哈

(base) shenfanshu@ubuntu-server:~/B_code/da-faster-rcnn-PyTorch-master$ conda activate tch04
(tch04) shenfanshu@ubuntu-server:~/B_code/da-faster-rcnn-PyTorch-master$ CUDA_VISIBLE_DEVICES=1 python da_trainval_net.py --dataset cityscape --net vgg16 --bs 1 --lr 2e-3 --lr_decay_step 6 --cuda

############################################################################
遠程連接服務器,關閉終端離線運行程序
############################################################################
首先,創建你自己的screen:

screen -S 你的screen名字

我在這裏輸入的是  screen -S ShenfanshuCode。


然後,當你想看看程序跑的咋樣了,可以用如下命令查看服務器當前運行的screen:

screen -ls

可以看到這臺服務器上運行着兩個程序,12115.ShenfanshuCode這個就是我剛剛創建的screen
(base) shenfanshu@ubuntu-server:~$ screen -ls
There is a screen on:
    12115.ShenfanshuCode    (2019年09月22日 09時11分07秒)    (Attached)
1 Socket in /var/run/screen/S-shenfanshu.

再輸入如下命令重新鏈接:

screen -r 12115.ShenfanshuCode
回來了~ 

當你不需要這個screen時,直接輸入 kill 12115 就ok了。

############################################################################
# 給pycharm 自動註釋
############################################################################

"""
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @project : ${PROJECT_NAME}
# @Time : ${DATE} ${TIME}
# @Author : twinkle 
# @File : ${NAME}.py
# @Software: ${PRODUCT_NAME}
"""


############################################################################ 
安裝jupyter notebook
https://www.cnblogs.com/honway/p/9559324.html

https://blog.csdn.net/weixin_40321858/article/details/89487375
############################################################################
1.打開命令行,重新生成一個jupyter配置文件:

jupyter notebook --generate-config

 
修個配置文件,找到這個新生成的文件 jupyter_notebook_config.py

(base) twinkle@twinkle-ubuntu:~$ conda activate tch04
(tch04) twinkle@twinkle-ubuntu:~$ cd /home/twinkle/Myments/anaconda3/envs/tch04
(tch04) twinkle@twinkle-ubuntu:~/Myments/anaconda3/envs/tch04$ jupyter notebook --generate-config
Writing default config to: /home/twinkle/.jupyter/jupyter_notebook_config.py
(tch04) twinkle@twinkle-ubuntu:~/Myments/anaconda3/envs/tch04$ gedit /home/twinkle/.jupyter/jupyter_notebook_config.py
(tch04) twinkle@twinkle-ubuntu:~/Myments/anaconda3/envs/tch04$ vim /home/twinkle/.jupyter/jupyter_notebook_config.py
(tch04) twinkle@twinkle-ubuntu:~/Myments/anaconda3/envs/tch04$ sudo gedit /home/twinkle/.jupyter/jupyter_notebook_config.py
[sudo] twinkle 的密碼: 


2.搜索 NotebookApp.allow_password_change,改爲:NotebookApp.allow_password_change=False ,記得去掉註釋的#3.回到windows命令行,運行jupyter notebook password

(base) twinkle@twinkle-ubuntu:~$ jupyter notebook password
Traceback (most recent call last):
  File "/home/twinkle/Myments/anaconda3/bin/jupyter", line 7, in <module>
    from jupyter_core.command import main
ModuleNotFoundError: No module named 'jupyter_core'
(base) twinkle@twinkle-ubuntu:~$ conda activate tch04
(tch04) twinkle@twinkle-ubuntu:~$ jupyter notebook password
Enter password: 1234..[]
Verify password: 
[NotebookPasswordApp] Wrote hashed password to /home/twinkle/.jupyter/jupyter_notebook_config.json
(tch04) twinkle@twinkle-ubuntu:~$ sudo gedit /home/twinkle/.jupyter/jupyter_notebook_config.json
[sudo] twinkle 的密碼:  

{
  "NotebookApp": {
    "password": "sha1:085ece0d1dd1:553443e277c35932f210c940014394220d25157a"
  }
}

#密碼生成的一串sha1,寫入到了這個文件,等下要把這串sha1,複製到第一個生成的配置文件中
4.還差一步密碼纔可以生效使用,在第一個jupyter_notebook_config.py配置文件中找到“c.NotebookApp.password“,等於,剛生成的那個密碼sha1,效果如下:去掉前面的”#“
c.NotebookApp.password =u'sha1:085ece0d1dd1:553443e277c35932f210c940014394220d25157a'

 
5.保險起見,把jupyter重啓,之後,無論是更換瀏覽器還是Logout登陸,新密碼都可以正常使用了。

6. 將anaconda3的相關環境與包關聯到jupyter notebook上。然後網頁 conda 選項卡下就會顯示anaconda中的已經安裝的環境,選中環境,還可以在下方看到該環境已經安裝的包,並且可以直接給環境安裝需要的包

conda install nb_conda

7. 顯示anaconda中已經安裝的虛擬環境,過程中保證打開jupyter-notebook的終端不要關閉

activate 環境名稱

conda install ipykernel

python -m ipykernel install --user --name 環境名稱 --display-name "Python (環境名稱)"

 

2019年9月20日 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章