搭建Swin-Transformer-Detection

前提条件

  1. CUDA10.1
  2. Pytorch1.7.0
  3. python3.8

下载Swin-Transformer-Detection源码

git clone https://github.com.cnpmjs.org/SwinTransformer/Swin-Transformer-Object-Detection.git?

安装mmdetection

官方教程

#安装mmdet
pip install mmdet
#安装mmcv-full
#这里对mmcv-full pytorch cuda 的版本都有要求,在官方网站按照自己的配置选择对应安装命令即可
pip install mmcv-full==1.3.3 -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.7.0/index.html
#下载mmdetection源码
git clone https://github.com.cnpmjs.org/open-mmlab/mmdetection.git
cd mmdetection
#编译下载好的源码
pip install -r requirements/build.txt
pip install -v -e .  # or "python setup.py develop"

测试mmdetection是否安装成功

#先在mmdetection目录下创建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
#从上述URL中下载模型到创建好的checkpoints目录


from mmdet.apis import init_detector, inference_detector

config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'

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')

编译Swin-Transformer-Detection

mmdetection安装完成后,转到Swin-Transformer文件夹进行编译

cd ../Swin-Transformer-Object-Detection
python setup.py develop		#编译源码

测试

#类似mmdetection测试
#从Swin-Transformer下载对应模型放在Swin主目录即可
python demo/image_demo.py demo/demo.jpg configs/swin/mask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_adamw_3x_coco.py checkpoints/mask_rcnn_swin_tiny_patch4_window7.pth

从测试命令可以看出:网络配置和模型是一一对应的关系,Swin-Transformer文件夹中已经有了官网对应的七种预训练的配置参数,而对应的七种模型需要在官网自行下载。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值