ReDet
1 推理
配置
-
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_CHECK
为 TORCH_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 推理
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