1. 程式人生 > >Detectron python2.7安裝

Detectron python2.7安裝

clas path raw tro inux 報錯 cti 創建 x86

---恢復內容開始---

接上一篇重裝系統後。

要和先前的工作接軌,所以還得安裝Detectron(https://github.com/facebookresearch/Detectron/blob/master/INSTALL.md);中間有個小插曲,就是剛巧看見原作者又發布的 maskrcnn-benchmark ,速度較 Detectron 快了一倍,等我屁顛的裝完後,發現只能跑物體檢測和語義分割,不能做關鍵點檢測。所以還是得回到先前的Detectron上。

註意,這裏需要的是Python2.7,而我之前安裝了Anaconda3(Python3.5),怎麽辦呢? 利用conda創建一個虛擬環境,裏面是Python2.7就好了。

>> conda create -n detectron_py27 python=2.7

#激活該環境的意思就是,優先使用該環境下的Python
>> source activate detectron_py27
>> echo $PATH
/home/wang/anaconda3/envs/detectron_py27/bin:/usr/local/cuda-9.0/bin:/home/wang/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
#退出該環境
source deactivate

然後就是安裝caffe2以及cocoapi:

#直接安裝pytorch1.,裏面包含了CAFFE2
>> conda install pytorch-nightly -c pytorch

#接著是cocoapi
>> cd ~/codes
>> git clone https://github.com/cocodataset/cocoapi.git
>> cd cocoapi/PythonAPI
>> make install

最後安裝detectron,由於我的代碼是老一代版本,所以跟現在還是不一樣的。

>> cd ~/codes
>> git clone https://github.com/facebookresearch/detectron >> cd detectron/lib && make

然後就是測試是否安裝成功,這裏需要註意,由於是直接用conda安裝的caffe2,因此其lib文件並不在 /usr/local下,所以測試時,會報錯

(detectron_py27) wang@wang:~/codes/detectron_old$ python tests/test_spatial_narrow_as_op.py 
No handlers could be found for logger "caffe2.python.net_drawer"
net_drawer will not run correctly. Please install the correct dependencies.
[E init_intrinsics_check.cc:43] CPU feature avx is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
[E init_intrinsics_check.cc:43] CPU feature avx2 is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
[E init_intrinsics_check.cc:43] CPU feature fma is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
Traceback (most recent call last):
  File "tests/test_spatial_narrow_as_op.py", line 88, in <module>
    utils.c2.import_detectron_ops()
  File "/home/wang/codes/detectron_old/lib/utils/c2.py", line 41, in import_detectron_ops
    detectron_ops_lib = envu.get_detectron_ops_lib()
  File "/home/wang/codes/detectron_old/lib/utils/env.py", line 71, in get_detectron_ops_lib
    (Detectron ops lib not found; make sure that your Caffe2 
AssertionError: Detectron ops lib not found; make sure that your Caffe2 version includes Detectron module

打印一下變量prefixes中保存的路徑:

[u/usr/local, /home/wang/anaconda3/envs/detectron_py27, 
/home/wang/anaconda3/envs/detectron_py27, /home/wang/codes/detectron_old/tests, 
/home/wang/anaconda3/envs/detectron_py27/lib/python27.zip, 
/home/wang/anaconda3/envs/detectron_py27/lib/python2.7, 
/home/wang/anaconda3/envs/detectron_py27/lib/python2.7/plat-linux2, 
/home/wang/anaconda3/envs/detectron_py27/lib/python2.7/lib-tk, 
/home/wang/anaconda3/envs/detectron_py27/lib/python2.7/lib-old, 
/home/wang/anaconda3/envs/detectron_py27/lib/python2.7/lib-dynload, 
/home/wang/.local/lib/python2.7/site-packages, /home/wang/codes/detectron_old/lib, 
/home/wang/anaconda3/envs/detectron_py27/lib/python2.7/site-packages, 
/home/wang/anaconda3/envs/detectron_py27/lib/python2.7/site-packages/pycocotools-2.0-py2.7-linux-x86_64.egg, 
/home/wang/anaconda3/envs/detectron_py27/lib/python2.7/site-packages]

而libcaffe2_detectron_ops_gpu.so存在的路徑卻是

‘/home/wang/anaconda3/pkgs/pytorch-nightly-1.0.0.dev20181029-py2.7_cuda9.0.176_cudnn7.1.2_0/lib/python2.7/site-packages/torch/lib/libcaffe2_detectron_ops_gpu.so’

所以需要將此路徑添加到 prefixes 中。保存 detectron/lib/utils/env.py 重新測試,就通過了。

(detectron_py27) wang@wang:~/codes/detectron_old$ python tests/test_spatial_narrow_as_op.py 
No handlers could be found for logger "caffe2.python.net_drawer"
net_drawer will not run correctly. Please install the correct dependencies.
[E init_intrinsics_check.cc:43] CPU feature avx is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
[E init_intrinsics_check.cc:43] CPU feature avx2 is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
[E init_intrinsics_check.cc:43] CPU feature fma is present on your machine, but the Caffe2 binary is not compiled with it. It means you may not get the full speed of your CPU.
Found Detectron ops lib: /home/wang/anaconda3/pkgs/pytorch-nightly-1.0.0.dev20181029-py2.7_cuda9.0.176_cudnn7.1.2_0/lib/python2.7/site-packages/torch/lib/libcaffe2_detectron_ops_gpu.so
...
----------------------------------------------------------------------
Ran 3 tests in 3.125s

OK

Detectron python2.7安裝