華為雲服務器,4核心8G內存,沒有顯卡,性能算湊合,趕上雙11才不到1000,性價比還可以,打算配置一套訓練densenet的環境。
首先自帶的python版本是2.7,由於明年開始就不再維護了,所以安裝了個conda。
wget https://repo.continuum.io/archive/Anaconda3-5.3.0-Linux-x86_64.sh
https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh 2020-4-9 updated
發現實在太慢,找了個清華的源,快了很多。
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.3.0-Linux-x86_64.sh
Anaconda3-5.3.1-MacOSX-x86_64.sh
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2020.02-Linux-x86_64.sh
(這里4.3.0可以換成5.3.0,4.3.0的python版本好像是3.6 ,后面再安裝pytorch和torchvision的時候可能還需要升級python版本)
chmod 777 anaconda3.4.3.0-Linux-x86_64.sh
./anaconda3.4.3.0-Linux-x86_64.sh
一直yes,安裝好后,會提示是否加入系統變量中,點擊yes,再執行命令 :source ~/.bachrc
輸入python --version 檢查是否版本從2.7升級到3.6
輸入conda list,檢查conda是否安裝好
然后安裝pytorch和torchvision
conda config --add channels https://repo.continuum.io/pkgs/free/
conda config --add channels https://repo.continuum.io/pkgs/main/
conda config --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda install pytorch torchvision
也可以conda install pytorch torchvision cudatoolkit=10.0.130,因為沒有cuda顯卡,所以不用帶也沒關系。
也可以這樣:conda install pytorch -c pytorch
conda install torchvision -c pytorch
安裝好以后,使用測試程序
import torch
train_on_gpu = torch.cuda.is_available()
if not train_on_gpu:
print('Training on CPU ...')
else:
print('Training on GPU ...')
將數據集上傳到服務器,開始訓練。
1:報了個lr_scheduler的錯,升級一下pytorch和torchvision
conda install pytorch==0.4.0
conda upgrade torchvision
2:報了個錯,pytorch:ValueError: optimizing a parameter that doesn't require gradients
但是這個錯,同樣在windows環境和centos7 + python 2.7兩種環境下沒有出現過。
有兩種解決辦法,一個是將param.requires_grad = False ➡param.requires_grad = True,但是內存可能扛不住。
還有一個辦法是將optimizer = optim.Adadelta(model.parameters()) ➡ optimizer = optim.Adadelta(filter(lambda p: p.requires_grad,model.parameters()))
推薦第二種方法,第一種方法由於求導數還慢占內存。
3:報了個錯:json.decoder.JSONDecodeError: Expecting property name enclosed in double quo
好像是json文件最后多了個“,”號,排除這種錯看log就搞定了。