之前在自己筆記本上配置過一次caffe,只用的cpu,啊,簡直不能要。。。後來換了TX1試試,又得重新編譯一邊caffe,每次在編譯python包時總是難以滿足,嘗試好久,有點心得,主要整理一下python依賴解決過程,免得遺忘。
1、開始步驟
下載caffe,參考教程一大堆,自己找~
Note:Makefile也要修改一下,不只是Makefile.config,不然會出現找不到lhdf5_hl 和 lhdf5
參考文章:https://blog.csdn.net/u012841667/article/details/53316948
#出現下面錯誤
/usr/bin/ld: 找不到 -lhdf5_hl
/usr/bin/ld: 找不到 -lhdf5
collect2: error: ld returned 1 exit status
Makefile:566: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1
#Makefile 181行,更改hdf5_hl 和 hdf5
#LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_regex m hdf5_hl hdf5
LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_regex m hdf5_serial_hl hdf5_serial
然後你會來到下面這一步
cd ~/caffe
sudo apt-get install gfortran
cd ./python
su
for req in $(cat requirements.txt); do pip install $req; done
2、解決requirements依賴
執行完最後一句命令,會出現各種包不滿足,這個時候直接打開requirements.txt,然後對照出錯的包,一條一條的執行,這樣錯誤比較清晰,方便解決。
pip install scipy #不滿足的包
此時可能會出現一些簡單的錯誤,解決後,如果還是不能安裝,可以嘗試
sudo apt-get install python-scipy #記得用Tab
我的scipy和leveldb就是用這種方法安裝的,pip怎麼都安不上,用apt-get很容易就安上了。
3、解決scikit-image包的安裝問題
採用pip install scikit-image 每次都卡在Installing build dependencies ... |好久也沒什麼反應,然後我就取消了,發現它有好幾個依賴包,每次取消後同樣都需要重新下載,我就決定單個依賴安裝。
nvidia@tegra-ubuntu:~$ sudo pip install dask
nvidia@tegra-ubuntu:~$ sudo pip install cloudpickle
nvidia@tegra-ubuntu:~$ sudo pip install PyWavelets
....
#安完各個依賴後,最後嘗試
nvidia@tegra-ubuntu:~$ sudo pip install scikit-image
#終於出現了
Collecting scikit-image
Downloading https://files.pythonhosted.org/packages/a4/5d/05d40ad281cb16bc9dbd91982a918162b374c43e84eb2c8f7070e4be6729/scikit-image-0.14.1.tar.gz (27.5MB)
100% |████████████████████████████████| 27.5MB 688kB/s
Installing build dependencies ... done
Requirement already satisfied: networkx>=1.8 in /usr/local/lib/python2.7/dist-packages (from scikit-image) (2.2)
Requirement already satisfied: six>=1.10.0 in /usr/lib/python2.7/dist-packages (from scikit-image) (1.10.0)
Requirement already satisfied: pillow>=4.3.0 in ./.local/lib/python2.7/site-packages (from scikit-image) (5.1.0)
Requirement already satisfied: PyWavelets>=0.4.0 in /usr/local/lib/python2.7/dist-packages (from scikit-image) (1.0.1)
Requirement already satisfied: dask[array]>=0.9.0 in /usr/local/lib/python2.7/dist-packages (from scikit-image) (1.0.0)
Requirement already satisfied: cloudpickle>=0.2.1 in /usr/local/lib/python2.7/dist-packages (from scikit-image) (0.6.1)
Requirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python2.7/dist-packages (from networkx>=1.8->scikit-image) (4.3.0)
Requirement already satisfied: numpy>=1.9.1 in ./.local/lib/python2.7/site-packages (from PyWavelets>=0.4.0->scikit-image) (1.14.5)
Requirement already satisfied: toolz>=0.7.3; extra == "array" in /usr/local/lib/python2.7/dist-packages (from dask[array]>=0.9.0->scikit-image) (0.9.0)
Installing collected packages: scikit-image
Running setup.py install for scikit-image ... done
Successfully installed scikit-image-0.14.1
NOTE:
1、在Running setup.py 那裏至少停了有十分鐘,千萬不要着急關閉窗口,可能機器正編譯着呢,突然回想起之間我的多次中斷。。。所以年輕還是要耐得住性子,哈哈
2、pip安裝過程中可能會出現讓你升級pip,升級pip後出現ImportError: cannot import name main
參考鏈接:https://blog.csdn.net/accumulate_zhang/article/details/80269313
cd /usr/bin
sudo gedit pip
#修改下面三行
from pip import main
if __name__ == '__main__':
sys.exit(main())
#改爲以下三行
from pip import __main__
if __name__ == '__main__':
sys.exit(__main__._main())
3、安裝過程中會出現有些包安裝不上,乾脆直接下載,相關軟件包可以去python官網下:https://pypi.org/ 然後執行
sudo pip install *.whl
4、安裝python相關軟件包時會有相關版本不滿足,不知道爲啥,然後發現命令行確實找的包不對,已經電腦滿足了,就是pyyaml!!!參考:Ubuntu安裝yaml
或者可以進入python環境查看一下你這個包的版本:
import pyyaml
pyyaml.__version__
或者help,翻到最後就是軟件包版本信息
help(pyyaml)
5、python程序運行時檢查空格 python -tt file_name.py
在終端窗口執行某個腳本時,腳本中的當前目錄" ./ "或 “ os.getpwd() ”爲終端的路徑,而非腳本路徑,這時如果腳本中有讀取腳本所在目錄文件操作時就會找不到文件,此時路徑應該爲“ sys.path[0] ”纔對!
6、當你訓練caffe網絡時,你可能會好起服務器是什麼配置,那麼在Linux查看系統cpu個數、核心書、線程數
文章連接:https://jingyan.baidu.com/article/63acb44a81001361fcc17e21.html
7、出現Command “python setup.py egg_info” failed with error code 1
sudo easy_install -U setuptools
8、重新安裝pip
sudo apt-get remove python-pip
#重新安裝
sudo apt-get install python-pip python-dev build-essential
9、NVIDIA顯卡算力表
NVIDA CUDA顯卡計算能力對應表
10、查看opencv版本
pkg-config --modversion opencv
11、protocbuf 問題,caffe2.6.1支持沒問題,之前安過一個libprotoc 3.6.1 導致錯誤,刪除/usr/local/bin 下的protoc以及 /usr/local/include 下的google文件夾和/usr/local/lib 下的libprot* 庫文件就ok了
robot@robot:~$ which protoc
/usr/bin/protoc
robot@robot:~$ protoc --version
libprotoc 2.6.1
robot@robot:~$ whereis protoc
protoc: /usr/bin/protoc /usr/share/man/man1/protoc.1.gz
12、make pycaffe時候報錯:Makefile:501: recipe for target 'python/caffe/_caffe.so' failed