Swin-Transformer-Object-Detection环境搭建(最简单的安装版本)

Swin-Transformer-Object-Detection环境搭建(最简单版本)

前言

史上最简单的Swin-Transformer-Object-Detection环境搭建
包含了vs2019,mmdetection,mmcv,apex的windows版本的安装,没接触过Swin-Transformer的读者也可根据流程单独安装mmdetection,mmcv,apex。
论文地址:论文
项目地址:Swin-Transformer-Object-Detection
论文讲解参考b站沐哥:讲解视频

1 Swin-Transformer环境配置需求

环境搭建配置:

  1. vs2019(只需要装里面的c++编辑工具和SDK即可)。vs2019下载地址
  2. pytorch
  3. torchvision
  4. python
  5. cuda
  6. mmcv
  7. mmdetection
  8. apex
    官网发布的配置需求仅供参考:Python 3.6+, CUDA 9.2+ and PyTorch 1.5+。

2 详细流程(傻瓜式)

  1. 打开anaconda power shell(最好以管理员身份运行,免得到后面相关文件权限进不去)
  2. 创建环境:conda create -n swinmm python=3.8
  3. 激活环境:conda activate swinmm
  4. 下载pytorch等(最简便的方式了): pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
  5. 下载swin-transformer到本地项目地址
  6. cd 到项目目录下(具体看你创建环境的目录)比如我的:cd C:ProgramDataAnaconda3envsswinmmSwin-Transformer-Object-Detection
  7. 下载mmcv(指定版本并和pytorch匹配): pip install mmcv-full==1.3.9 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html
  8. 安装mmdet,在项目目录下执行:
    1.pip install -r requirements.txt
    2.pip install -r requirements/docs.txt
    3.python setup.py develop
    等待即可
  9. 从网站克隆apex下载地址(或者下载zip)apex:cd到apex文件下并运行:python setup.py install
  10. 至此所有的配置文件安装完毕。可以用conda list查看自己是否安装正确。最重要的就是mmcv和mmdet是否安装正确。mmcv和mmdet版本

3 编译

3. 1 从官网下载训练模型

选择cascade_mask_rcnn_swin_tiny_patch4_window7.pth把下载好的文件放在项目下就可,具体如图模型选择

3.2.在anaconda power shell中运行

项目文件下直接输入
python tools/train.py configs/swin/cascade_mask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_giou_4conv1f_adamw_3x_coco.py

3.3.在pycharm中运行

在项目下新建test.py文件,其中config_file和,checkpoint_file和image我采用了绝对路径自己根据实际情况而定。

from mmdet.apis import init_detector, inference_detector, show_result_pyplot

# configs路径(根据自己路径设置)
config_file = r'C:ProgramDataAnaconda3envsswinmmSwin-Transformer-Object-Detectionconfigsswinmask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_adamw_1x_coco.py'

# 这个就是权重文件,可自行到官方github上下载(根据自己路径设置)
checkpoint_file =r'C:ProgramDataAnaconda3envsswinmmSwin-Transformer-Object-Detectionmask_rcnn_swin_tiny_patch4_window7.pth'
device = 'cuda:0'
# init a detector
model = init_detector(config_file, checkpoint_file, device=device)
# inference the demo image

# 测试图片(根据自己路径设置)
image = r'C:ProgramDataAnaconda3envsswinmmSwin-Transformer-Object-Detectiondemodemo.jpg'

result = inference_detector(model, image)

show_result_pyplot(model, image, result, score_thr=0.3)

在这里插入图片描述
测试了一下手机相册的图片。
原图
result

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇

)">
下一篇>>