faster-rcnn.pytorch项目环境配置(从0到1)
其实pytorch版本和CUDA版本高,都没有关系!!!都可以适配,显卡30系、20系都没关系,都可以用!
下面我将在AutoDL平台上,从0到1安装配置一遍!!!
- conda create -n DA python=3.8
- conda activate DA
- 克隆代码
git clone https://github.com/jwyang/faster-rcnn.pytorch.git
cd faster-rcnn.pytorch
git checkout pytorch-1.0
- pip install -r requirements.txt
若安装opencv时卡死,请单独安装opencv-python,并附带版本:
pip install opencv-python==3.4.9.31
- 安装pytorch
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch
- 编译coco api
cd lib/pycocotools #进入coco文件夹
新建 setup.py 文件,并将以下内容复制
# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
import os
from setuptools import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy as np
# Obtain the numpy include directory. This logic works across numpy versions.
try:
numpy_include = np.get_include()
except AttributeError:
numpy_include = np.get_numpy_include()
ext_modules = [
Extension(
'_mask',
sources=['maskApi.c', '_mask.pyx'],
include_dirs = [numpy_include, '.'],
extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'],
)
]
setup(
name='faster_rcnn',
ext_modules=ext_modules,
# inject our custom trigger
cmdclass={'build_ext': build_ext},
)
随后python setup.py build_ext --inplace
- 编译cuda依赖
cd …
python setup.py build develop # 编译cuda 依赖项
若发生以下错误:
pytorch版本问题:pytorch在最新的版(1.11)本中将THC/THC.h文件删除了。降低pytorch版本即可 conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forge
- 在根目录下创建data,下载数据集/预训练权重
mkdir data
cd data
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCdevkit_08-Jun-2007.tar
tar xvf VOCtrainval_06-Nov-2007.tar
tar xvf VOCtest_06-Nov-2007.tar
tar xvf VOCdevkit_08-Jun-2007.tar
# 在xxx/data路径下
ln -s /root/autodl-tmp/faster-rcnn.pytorch/data/VOCdevkit VOCdevkit2007
mkdir pretrained_model
cd pretrained_model
wget https://filebox.ece.vt.edu/~jw2yang/faster-rcnn/pretrained-base-models/resnet101_caffe.pth
wget https://filebox.ece.vt.edu/~jw2yang/faster-rcnn/pretrained-base-models/vgg16_caffe.pth
- 更改代码:
autodl-tmp/faster-rcnn.pytorch/lib/roi_data_layer/minibatch.py
第15行: from scipy.misc import imread
改为: from imageio import imread
pip install imageio
autodl-tmp/faster-rcnn.pytorch/lib/model/utils/config.py
第374行:yaml_cfg = edict(yaml.load(f))
改为:yaml_cfg = edict(yaml.safe_load(f))
随后
CUDA_VISIBLE_DEVICES=0 python trainval_net.py --dataset pascal_voc --net vgg16 --epochs 20 --bs 1 --nw 2 --lr 1e-2 --lr_decay_step 8 --use_tfb --cuda
参考:
1
2
[3](