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环境配置需求
环境搭建配置:
- vs2019(只需要装里面的c++编辑工具和SDK即可)。vs2019下载地址
- pytorch
- torchvision
- python
- cuda
- mmcv
- mmdetection
- apex
官网发布的配置需求仅供参考:Python 3.6+, CUDA 9.2+ and PyTorch 1.5+。
2 详细流程(傻瓜式)
- 打开anaconda power shell(最好以管理员身份运行,免得到后面相关文件权限进不去)
- 创建环境:
conda create -n swinmm python=3.8
- 激活环境:
conda activate swinmm
- 下载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
- 下载swin-transformer到本地项目地址
- cd 到项目目录下(具体看你创建环境的目录)比如我的:
cd C:ProgramDataAnaconda3envsswinmmSwin-Transformer-Object-Detection
- 下载mmcv(指定版本并和pytorch匹配):
pip install mmcv-full==1.3.9 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html
- 安装mmdet,在项目目录下执行:
1.pip install -r requirements.txt
2.pip install -r requirements/docs.txt
3.python setup.py develop
等待即可 - 从网站克隆apex下载地址(或者下载zip)apex:cd到apex文件下并运行:
python setup.py install
- 至此所有的配置文件安装完毕。可以用conda list查看自己是否安装正确。最重要的就是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)
测试了一下手机相册的图片。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
二维码