参考博文:
官方教程地址:https://mmdetection.readthedocs.io/en/latest/get_started.html
安装配置mmdetection 使用vs 可考虑
本文人win10系统 无gpu 没有独显 也就是连cuda都没有。
1、Create a conda virtual environment and activate it.
conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab
2、Install PyTorch and torchvision following the official instructions, e.g.,
conda install pytorch torchvision -c pytorch
#我的没有cuda 和gpu 又安装了 CPU版的
conda install pytorch torchvision cpuonly -c pytorch
3、 MMCV | MMCV-full 的安装
参考官方博文:WINDOWS 下 MMCV | MMCV-full 的安装
我是没有新建虚拟环境,也没有Visual Studio Community 2019 直接在当前环境下安装,过程中有个环境变量“HOME”的问题,我设置环境变量HOME为当前用户目录“C:\Users\0”
git clone https://github.com/open-mmlab/mmcv.git
#git checkout v1.2.0 # based on target version 我这没有check
cd mmcv
pip install -r requirements.txt
#python setup.py build_ext # 如果成功, cl 将会自动弹出来编译 flow_warp
#python setup.py develop # 安装
#我直接这样
pip install -e .
pip list # 检查是否安装成功
4、安装mmdetection:
回到家目录
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -r requirements.txt
修改setup.py文件中extra_compile_args 相关代码,增加cxx的:"-DMS_WIN64","-MD"
def make_cuda_ext(name, module, sources, sources_cuda=[]):
define_macros = []
extra_compile_args = {'cxx': []}
if torch.cuda.is_available() or os.getenv('FORCE_CUDA', '0') == '1':
define_macros += [('WITH_CUDA', None)]
extension = CUDAExtension
extra_compile_args['nvcc'] = [
'-D__CUDA_NO_HALF_OPERATORS__',
'-D__CUDA_NO_HALF_CONVERSIONS__',
'-D__CUDA_NO_HALF2_OPERATORS__',
]
extra_compile_args['cxx']=["-DMS_WIN64","-MD"]#add
sources += sources_cuda
else:
print(f'Compiling {name} without CUDA')
extension = CppExtension
return extension(
name=f'{module}.{name}',
sources=[os.path.join(*module.split('.'), p) for p in sources],
define_macros=define_macros,
extra_compile_args=extra_compile_args)
注意拷贝时的空格和tab一致问题。
当前文件夹运行
python setup.py build_ext --inplace #进行编译
python setup.py install develop #完成安装
pip list #查看是否安装成功,成功的话会有mmdet包以及对应版本
5、运行以下代码查看库是否安装正确 #尚未验证 也没有cuda +﹏+
from mmdet.apis import init_detector, inference_detector
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
# url: http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
device = 'cuda:0'
# init a detector
model = init_detector(config_file, checkpoint_file, device=device)
# inference the demo image
inference_detector(model, 'demo/demo.jpg')