上個月Install Detectron后,
檢查caffe2是否安裝成功:
# To check if Caffe2 GPU build was successful # This must print a number > 0 in order to use Detectron python2 -c 'from caffe2.python import workspace; print(workspace.NumCudaDevices())'
輸出1 ,沒問題
檢查Detectron是否編譯成功:
python2 $DETECTRON/tests/test_spatial_narrow_as_op.py
依舊通過。執行nference tutorial時也一切正常。
但是今天在執行inference tutorial時,卻報錯了:
python2 tools/infer_simple.py \ --cfg configs/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml \ --output-dir /tmp/detectron-visualizations \ --image-ext jpg \ --wts https://s3-us-west-2.amazonaws.com/detectron/35861858/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml.02_32_51.SgT4y1cO/output/train/coco_2014_train:coco_2014_valminusminival/generalized_rcnn/model_final.pkl \ demo
提示:
ImportError: /home/cc/Detectron-master/lib/utils/cython_nms.so: undefined symbol: PyFPE_jbuf
於是我google了一下,很多提到出現這個問題的原因是系統上存在多個python環境導致的。我想起來,一開始由於重裝系統,所以在安裝Detectron時,使用的是系統自帶的python2.7;而后來我因為要用tensorflow,就又重新裝了anaconda2,並默認使用anaconda中的python了,我想這可能就是導致我失敗的最終原因,在網上找了幾種解決方法,都是坑!
第一個坑:
>>> pip uninstall numpy
把numpy給卸載了,然后就出現 “ no module named numpy” ,我想重新給它裝回去,pip install numpy卻提示我系統已經安裝了numpy ,可是我卻無法import !!??
后來還是通過 pip installl --ignore-installed numpy 重新給裝回去了。
第二個坑:
>>> conda remove numpy
我也沒注意,出提示時直接輸入了yes ,結果...把裝好的tensorflow和其他一些相關的包都給卸載了!!??? WTF
好吧,沒了就沒 了,一會給它重新裝回去就是了。但是執行inference tutorial時依舊報相同的錯誤!!於是就進入了下面的一個坑。
第三個坑:
1.刪除Detecron、caffe2文件夾
2.
>>> conda install -c caffe2 caffe2-cuda9.0-cudnn7-gcc4.8
這個更改完犢子,安裝某個包時,出現一個和Permision Denied有關的Error,然后安裝結束了。我進入python可以import caffe2 但是,執行inference tutorial時,出現其他的錯誤。
然后我就想刪了,conda remove caffe2 caffe2-cuda9.0-cudnn7-gcc4.8 居然刪不了,每次運行完指令,還是可以import caffe2,而且錯誤依舊存在。
無奈,最后我使出了殺手鐧:刪除Anaconda2 一切重新來過。。。
后續。。
Step1:安裝Anaconda2,我事先下載了安裝包,所以直接安裝就行
bash ./Anaconda2-4.4.0-Linux-x86_64.sh
這里沒什么好說的,正常裝完后檢查 python -V 顯示是Anaconda2的。
Step 2: 從源碼編譯caffe2
有一點要注意的時,這次在編譯caffe2的時候,提示cmake版本最低要求 3.2,而本機自帶的是2.8,所以需要升級:
>>> cd ~ >>> wget https://cmake.org/files/v3.2/cmake-3.2.2.tar.gz >>> tar xvf cmake-3.2.2.tar.gz >>> cd cmake-3.2.2 >>> ./bootstrap --prefix=/usr #這一步很關鍵,如果沒有指定prefix,后面使用時會報錯Could not find CMAKE_ROOT >>> make >>> sudo make install #check: >>> cmake --version cmake version 3.2.2
然后執行 再下載和編譯caffe2
Step2: 安裝Caffe2,要小心了。
>>> conda install -c caffe2 caffe2-cuda9.0-cudnn7-gcc4.8
下面是Terminal里的輸出:
Fetching package metadata ........... Solving package specifications: . Package plan for installation in environment /home/cc/anaconda2: The following NEW packages will be INSTALLED: caffe2-cuda9.0-cudnn7-gcc4.8: 0.8.dev-py27h67f0068_0 caffe2 future: 0.16.0-py27_1 gflags: 2.2.0-1 glog: 0.3.5-0 leveldb: 1.20-0 libprotobuf: 3.4.0-0 lmdb: 0.9.21-0 opencv: 3.1.0-np112py27_1 protobuf: 3.4.0-py27_0 snappy: 1.1.6-0 The following packages will be UPDATED: anaconda: 4.4.0-np112py27_0 --> custom-py27_0 conda: 4.3.21-py27_0 --> 4.3.30-py27h6ae6dc7_0 The following packages will be DOWNGRADED: jpeg: 9b-0 --> 8d-2 libtiff: 4.0.6-3 --> 4.0.6-2 pillow: 4.1.1-py27_0 --> 3.4.2-py27_0 qt: 5.6.2-4 --> 5.6.2-2 Proceed ([y]/n)?
沒的說,我這里只能選y吧 ,等了幾個小時后,都下載好了。
Proceed ([y]/n)? y gflags-2.2.0-1 100% |################################| Time: 0:00:01 99.19 kB/s glog-0.3.5-0.t 100% |################################| Time: 0:00:35 18.59 kB/s jpeg-8d-2.tar. 100% |################################| Time: 0:00:47 17.43 kB/s lmdb-0.9.21-0. 100% |################################| Time: 0:00:34 17.11 kB/s snappy-1.1.6-0 100% |################################| Time: 0:00:02 19.58 kB/s leveldb-1.20-0 100% |################################| Time: 0:00:22 15.62 kB/s libprotobuf-3. 100% |################################| Time: 0:04:55 15.33 kB/s libtiff-4.0.6- 100% |################################| Time: 0:01:38 15.48 kB/s anaconda-custo 100% |################################| Time: 0:00:00 20.59 kB/s future-0.16.0- 100% |################################| Time: 0:00:40 16.27 kB/s opencv-3.1.0-n 100% |################################| Time: 0:38:52 16.46 kB/s pillow-3.4.2-p 100% |################################| Time: 0:00:59 14.74 kB/s protobuf-3.4.0 100% |################################| Time: 0:00:24 19.81 kB/s caffe2-cuda9.0 100% |################################| Time: 0:22:54 20.96 kB/s qt-5.6.2-2.tar 100% |################################| Time: 0:26:06 29.61 kB/s qt-5.6.2-2.tar 100% |################################| Time: 0:40:15 19.21 kB/s conda-4.3.30-p 100% |################################| Time: 0:00:26 19.93 kB/s
裝完后,測試下看:
>>> python2 -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure" Segmentation fault (core dumped) Failure >>> python2 -c 'from caffe2.python import workspace; print(workspace.NumCudaDevices())' WARNING:root:This caffe2 python run does not have GPU support. Will run in CPU only mode. WARNING:root:Debug message: libnccl.so.2: cannot open shared object file: No such file or directory Segmentation fault (core dumped)
重新打開安裝頁面,有如下兩段話:
This does NOT include libraries that are necessary to run the tutorials, such as jupyter. See the tutorials page for the list of required packages needed to run the tutorials.
NOTE: This will install Caffe2 and all of its required dependencies into the current conda environment.
We strongly suggest that you create a new conda environment and install Caffe2 into that.
A conda environment is like a separate python installation and so won’t have problems with your other conda environments. You can learn more about conda environments here.
我決定進一步嘗試 tutorials page里的 list of required packages needed to run the tutorials.
First download the tutorials source.
>>> git clone --recursive https://github.com/caffe2/tutorials caffe2_tutorials
Cloning into 'caffe2_tutorials'...
remote: Counting objects: 280, done.
remote: Total 280 (delta 0), reused 0 (delta 0), pack-reused 280
Receiving objects: 100% (280/280), 38.42 MiB | 71.00 KiB/s, done.
Resolving deltas: 100% (113/113), done.
Checking connectivity... done.
To run the tutorials you will need some third-party libraries, including ipython-notebooks and matplotlib. You can install everything you’ll need with the following command.
(Anaconda users: If you’re using Anaconda, use conda install instead of pip install.) Anaconda user?好家伙,那不就是我嗎 ?
原本是這樣的:
pip install -U pip setuptools pip install \ graphviz \ hypothesis \ ipython \ jupyter \ matplotlib \ notebook \ pydot \ python-nvd3 \ pyyaml \ requests \ scikit-image \ scipy
我應該輸入成:
>>> conda install setuptools Fetching package metadata ........... Solving package specifications: . Package plan for installation in environment /home/cc/anaconda2: The following NEW packages will be INSTALLED: certifi: 2018.1.18-py27_0 libgcc-ng: 7.2.0-hdf63c60_3 The following packages will be UPDATED: conda: 4.3.30-py27h6ae6dc7_0 --> 4.5.0-py27_0 conda-env: 2.6.0-0 --> 2.6.0-h36134e3_1 pycosat: 0.6.2-py27_0 --> 0.6.3-py27ha4109ae_0 setuptools: 27.2.0-py27_0 --> 39.0.1-py27_0 Proceed ([y]/n)? conda-env-2.6. 100% |################################| Time: 0:00:00 8.48 kB/s libgcc-ng-7.2. 100% |################################| Time: 0:07:00 15.20 kB/s certifi-2018.1 100% |################################| Time: 0:00:06 21.14 kB/s pycosat-0.6.3- 100% |################################| Time: 0:00:05 19.45 kB/s setuptools-39. 100% |################################| Time: 0:00:40 14.60 kB/s conda-4.5.0-py 100% |################################| Time: 0:01:12 14.74 kB/s
>>> conda install graphviz hypothesis ipython jupyter matplotlib notebook pydot python-nvd3 pyyaml requests scikit-image scipy
Solving environment: failed
PackagesNotFoundError: The following packages are not available from current channels:
- python-nvd3
Current channels:
- https://repo.anaconda.com/pkgs/main/linux-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/free/linux-64
- https://repo.anaconda.com/pkgs/free/noarch
- https://repo.anaconda.com/pkgs/r/linux-64
- https://repo.anaconda.com/pkgs/r/noarch
- https://repo.anaconda.com/pkgs/pro/linux-64
- https://repo.anaconda.com/pkgs/pro/noarch
我就把python-nvd3從安裝里去掉了,接着搞:
>>> conda install graphviz hypothesis ipython jupyter matplotlib notebook pydot pyyaml requests scikit-image scipy Solving environment: done ## Package Plan ## environment location: /home/cc/anaconda2 added / updated specs: - graphviz - hypothesis - ipython - jupyter - matplotlib - notebook - pydot - pyyaml - requests - scikit-image - scipy The following packages will be downloaded: package | build ---------------------------|----------------- numpy-1.12.1 | py27h9378851_1 3.7 MB terminado-0.8.1 | py27_1 20 KB ca-certificates-2018.03.07 | 0 124 KB pyyaml-3.12 | py27h2d70dd7_1 159 KB pydot-1.2.4 | py27_0 37 KB attrs-17.4.0 | py27_0 40 KB graphviz-2.38.0 | 2 12.0 MB hypothesis-3.53.0 | py27_0 251 KB requests-2.18.4 | py27hc5b0589_1 90 KB scikit-image-0.13.1 | py27h14c3975_1 23.2 MB urllib3-1.22 | py27ha55213b_0 153 KB backports.shutil_get_terminal_size-1.0.0| py27h5bc021e_2 8 KB notebook-5.4.1 | py27_0 6.6 MB libgfortran-ng-7.2.0 | hdf63c60_3 1.2 MB jupyter-1.0.0 | py27_4 5 KB intel-openmp-2018.0.0 | 8 620 KB ipython-5.6.0 | py27_0 1020 KB jupyter_core-4.4.0 | py27h345911c_0 60 KB send2trash-1.5.0 | py27_0 16 KB openssl-1.0.2o | h20670df_0 3.4 MB scikit-learn-0.19.1 | py27h445a80a_0 5.3 MB pysocks-1.6.8 | py27_0 22 KB libstdcxx-ng-7.2.0 | hdf63c60_3 2.5 MB scipy-1.0.1 | py27hfc37229_0 17.7 MB numexpr-2.6.4 | py27hd318778_0 180 KB jupyter_client-5.2.3 | py27_0 122 KB mkl-2018.0.2 | 1 205.2 MB coverage-4.5.1 | py27h14c3975_0 208 KB imageio-2.3.0 | py27_0 3.3 MB ------------------------------------------------------------ Total: 287.4 MB The following NEW packages will be INSTALLED: attrs: 17.4.0-py27_0 backports.shutil_get_terminal_size: 1.0.0-py27h5bc021e_2 ca-certificates: 2018.03.07-0 coverage: 4.5.1-py27h14c3975_0 graphviz: 2.38.0-2 hypothesis: 3.53.0-py27_0 imageio: 2.3.0-py27_0 intel-openmp: 2018.0.0-8 libgfortran-ng: 7.2.0-hdf63c60_3 libstdcxx-ng: 7.2.0-hdf63c60_3 pydot: 1.2.4-py27_0 pysocks: 1.6.8-py27_0 send2trash: 1.5.0-py27_0 urllib3: 1.22-py27ha55213b_0 The following packages will be UPDATED: ipython: 5.3.0-py27_0 --> 5.6.0-py27_0 jupyter: 1.0.0-py27_3 --> 1.0.0-py27_4 jupyter_client: 5.0.1-py27_0 --> 5.2.3-py27_0 jupyter_core: 4.3.0-py27_0 --> 4.4.0-py27h345911c_0 mkl: 2017.0.1-0 --> 2018.0.2-1 notebook: 5.0.0-py27_0 --> 5.4.1-py27_0 numexpr: 2.6.2-np112py27_0 --> 2.6.4-py27hd318778_0 numpy: 1.12.1-py27_0 --> 1.12.1-py27h9378851_1 openssl: 1.0.2l-0 --> 1.0.2o-h20670df_0 pyyaml: 3.12-py27_0 --> 3.12-py27h2d70dd7_1 requests: 2.14.2-py27_0 --> 2.18.4-py27hc5b0589_1 scikit-image: 0.13.0-np112py27_0 --> 0.13.1-py27h14c3975_1 scikit-learn: 0.18.1-np112py27_1 --> 0.19.1-py27h445a80a_0 scipy: 0.19.0-np112py27_0 --> 1.0.1-py27hfc37229_0 terminado: 0.6-py27_0 --> 0.8.1-py27_1 Proceed ([y]/n)?
