如何在ubuntu下安装detectron2_ubuntu16.04安装detectron教程
ubuntu16.04安裝detectron教程
系統環境要求:NVIDIA GPU, Linux, Python2
Caffe2, 部分Python包, COCO API
1. python2.7
Detectron必須在python2環境,python3不支持, 推薦使用conda 創建一個新的環境python27,并且切換到新環境
conda create -n python27 python=2.7
conda activate python27
以下所有操作都在python2.7下執行
2. 安裝 CUDA 8 + CuDNN 7 + NCCL
2.1 CUDA8安裝
安裝過程略
驗證安裝:nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61
2.2 從Debian文件安裝CuDNN 7
# 1.Install the runtime library, for example:
sudo dpkg -i libcudnn7_7.0.3.11-1+cuda9.0_amd64.deb
# 2.Install the developer library, for example:
sudo dpkg -i libcudnn7-devel_7.0.3.11-1+cuda9.0_amd64.deb
# 3.Install the code samples and the cuDNN Library User Guide, for example:
sudo dpkg -i libcudnn7-doc_7.0.3.11-1+cuda9.0_amd64.deb
2.3 測試CuDNN 7
樣例在/usr/src/cudnn_samples_v7路徑下
1.Copy the cuDNN sample to a writable path.
$cp -r /usr/src/cudnn_samples_v7/ $HOME
2.Go to the writable path.
$ cd $HOME/cudnn_samples_v7/mnistCUDNN
3.Compile the mnistCUDNN sample.
$make clean && make
4.Run the mnistCUDNN sample.
$ ./mnistCUDNN
顯示如下,表示安裝成功: Test passed!
2.4 cuDNN從v6升級到v7
cuDNN v7可以與之前版本的cuDNN共存,例如v5或v6。 cuDNN v7 can coexist with previous versions of cuDNN, such as v5 or v6.
2.5 NCCL安裝
下載安裝包并安裝
sudo dpkg -i nccl-repo-ubuntu1604-2.2.13-ga-cuda8.0_1-1_amd64.deb
3. 安裝Caffe2
3.1 conda安裝Caffe2
使用Anaconda在GPU + CUDA8 + CuDNN7環境下
conda install pytorch-nightly cuda80 -c pytorch
3.2 驗證Caffe2
檢查Caffe2的GPU依賴是否正確,下面命令輸出的GPU卡的數量必須要大于0 ,否則不能使用Detectron
# To check if Caffe2 build was successful
python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
# To check if Caffe2 GPU build was successful
# This must print a number > 0 in order to use Detectron
python -c 'from caffe2.python import workspace; print(workspace.NumCudaDevices())'
驗證過程顯示Failure,terminal重新輸入 python -c 'from caffe2.python import core',可以顯示錯誤信息
錯誤1: No module named google.protobuf.internal 解決方法:pip install protobuf
錯誤2: no moudle named past.builtins 解決方法:pip install future
4. 安裝COCO API
# COCOAPI=/path/to/clone/cocoapi
git clone https://github.com/cocodataset/cocoapi.git $COCOAPI
cd $COCOAPI/PythonAPI
# Install into global site-packages
make install
# Alternatively, if you do not have permissions or prefer
# not to install the COCO API into global site-packages
python setup.py install --user
在make install 如出現錯誤error: pycocotools/_mask.c: No such file or directory:
解決方法:pip install cython
5. 安裝Detectron
5.1 安裝
Clone the Detectron repository:
# DETECTRON=/path/to/clone/detectron
git clone https://github.com/facebookresearch/detectron $DETECTRON
Install Python dependencies:
pip install -r $DETECTRON/requirements.txt
Set up Python modules:
cd $DETECTRON && make
Check that Detectron tests pass (e.g. for SpatialNarrowAsOp test):
python $DETECTRON/detectron/tests/test_spatial_narrow_as_op.py
5.2 運行Detectron
可以使用tools目錄下內置的infer_simple.py 來使用預訓練的模型來預測實際的照片,infer_simple.py里面調用的是detectron封裝的vis_utils.vis_one_image API。
python 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://dl.fbaipublicfiles.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
最終,檢測結果就以pdf的格式輸出到了/tmp/detectron-visualizations目錄下
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的如何在ubuntu下安装detectron2_ubuntu16.04安装detectron教程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: unity 实现手机振动_Unity 手
- 下一篇: python实现并发http_pytho