ReDet 运行推理

ReDet

github

arXiv

1 推理

official instructions

配置

  • Ubuntu18

  • Python 3.7

  • PyTorch 1.8.2

  • CUDA 11.1

  • 30系显卡

1.1 安装

a. 创建conda环境并激活,然后安装Cython

 $ conda create -n redet python=3.7 -y
 $ conda activate redet
 $ conda install cython # not pip

b. 安装pytorch,official instructions

 $ pip install torch==1.8.2+cu111 torchvision==0.9.2+cu111 torchaudio==0.8.2 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html

c. clone代码

 $ git clone https://github.com/csuhan/ReDet.git
 $ cd ReDet

d. 编译cuda extensions

修改mmdet/ops下所有.cpp.cu源代码文件中的 AT_CHECKTORCH_CHECK

 $ bash compile.sh

e. 安装ReDet(其他依赖将被自动安装)

 $ pip install -e .

安装 DOTA_devkit

 $ sudo apt-get install swig
 $ cd DOTA_devkit
 $ swig -c++ -python polyiou.i
 $ python setup.py build_ext --inplace

1.2 推理

DOTA数据集官网

DOTA数据集介绍

ReDet模型权重

a. 准备文件夹和文件

 $ cd demo
 $ mkdir checkpoints
 $ mkdir infer_imgs
 $ mkdir infer_out

下载测试图片放到infer_imgs

下载模型权重放到checkpoints

b. 修改demo_inference.py文件

注释原有classnames及关联代码

     # cfg = Config.fromfile(config_file)
     # data_test = cfg.data.test
     # dataset = get_dataset(data_test)
     # classnames = [dataset.CLASSES]
     # # use checkpoint path in cfg
     # if not checkpoint_file:
     #     checkpoint_file = osp.join(cfg.work_dir, 'latest.pth')
     # # use testset in cfg
     # if not img_dir:
     #     img_dir = data_test.img_prefix

在注释下一行,添加与下载的推理权重相对应的classnames,以下为DOTA1.5对应的16类

classnames = ['plane', 'ship', 'storage tank', 'baseball diamond', 'tennis court',
              'basketball court', 'ground track field', 'harbor', 'bridge', 'large vehicle',
              'small vehicle', 'helicopter', 'roundabout', 'soccer ball field', 'swimming pool',
              'container crane']

修改原在第49行的listdota_colormap,将其调整为与classnames的长度相同

更改save_det_result函数的签名,添加参数colormap,修改原在第37行的colormap

                                    colormap=colormap)

修改位于最后的save_det_result函数的传参

                     checkpoint_file='checkpoints/ReResNet_pretrain/ReDet_re50_refpn_1x_dota15_ms-9d1a523c.pth',
                     img_dir=args.img_dir, score_thr=0.5, colormap=dota_colormap)

c. 运行推理

 $ python demo_inference.py ../configs/ReDet/ReDet_re50_refpn_1x_dota15_ms.py ./infer_out ./infer_imgs/DOTA1.5_val/ori

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值