已合并
[中国海洋大学][高校贡献][Pytorch迁移1.8][SOLOv2]-初次提交 #732
AtomGit-Bot创建于 2022年6月11日
[中国海洋大学][高校贡献][Pytorch迁移1.8][SOLOv2]-初次提交 #732
已合并
AtomGit-Bot创建于 2022年6月11日
refs/pull/732/head合入到master
164 个文件变更+1000-827
MPyTorch/contrib/cv/detection/SOLOv2/README.md+30-7
@@ -1,19 +1,21 @@
1# SOLOv21# SOLOv2
2 2 
3-This implements training of SOLOv2 on the Coco dataset, mainly modified from [pytorch/examples](https://github.com/WXinlong/SOLO).3+This implements training of SOLOv2 on the Coco dataset, mainly modified
4+from [pytorch/examples](https://github.com/WXinlong/SOLO).
4 5 
5## SOLOv2 Detail6## SOLOv2 Detail
6 7 
7-As of the current date, Ascend-Pytorch is still inefficient for contiguous operations.8+As of the current date, Ascend-Pytorch is still inefficient for contiguous operations. Therefore, SOLOv2 model need to
8-Therefore, SOLOv2 model need to be modified in the following aspects:9+be modified in the following aspects:
9 10 
101. Converting tensors with the dynamic shapes into tensors with fixed shapes. (This is the hardest one)111. Converting tensors with the dynamic shapes into tensors with fixed shapes. (This is the hardest one)
11-2. Several operations, like the sum of `INT64`, are not supported on the NPU, so we modified tensors' `dtype` when needed12+2. Several operations, like the sum of `INT64`, are not supported on the NPU, so we modified tensors' `dtype` when
12-3. Framework bottlenecks lead to poor performance, so we improve the original code to improve the performance of the model13+ needed
14+3. Framework bottlenecks lead to poor performance, so we improve the original code to improve the performance of the
15+ model
134. We used Apex for mmdtection due to the hardware defects of the NPU164. We used Apex for mmdtection due to the hardware defects of the NPU
145. ...175. ...
15 18 
16- 
17## Requirements19## Requirements
18 20 
19- NPU配套的run包安装21- NPU配套的run包安装
@@ -21,11 +23,14 @@ Therefore, SOLOv2 model need to be modified in the following aspects:
21- PyTorch(NPU版本)23- PyTorch(NPU版本)
22- apex(NPU版本)24- apex(NPU版本)
23- MMCV v0.2.1625- MMCV v0.2.16
26+ 
24### Document and data preparation27### Document and data preparation
28+ 
251. 下载压缩modelzoo\contrib\PyTorch\cv\instance_segmentation\SOLOv2 文件夹291. 下载压缩modelzoo\contrib\PyTorch\cv\instance_segmentation\SOLOv2 文件夹
262. 于npu服务器解压SOLOv2压缩包302. 于npu服务器解压SOLOv2压缩包
273. 下载coco2017数据集313. 下载coco2017数据集
284. 将coco数据集放于SOLOv2/data目录下,目录结构如下:324. 将coco数据集放于SOLOv2/data目录下,目录结构如下:
33+ 
29```34```
30GFocalV235GFocalV2
31├── configs36├── configs
@@ -35,13 +40,17 @@ GFocalV2
35│ ├── train2017 19G40│ ├── train2017 19G
36│ ├── val2017 788M41│ ├── val2017 788M
37```42```
43+ 
38### Configure the environment44### Configure the environment
45+ 
39```46```
40进入SOLOv2目录,source环境变量47进入SOLOv2目录,source环境变量
41cd SOLOv248cd SOLOv2
42source test/env_npu.sh 49source test/env_npu.sh
43```50```
51+ 
441. 配置安装mmcv521. 配置安装mmcv
53+ 
45```54```
46cd mmcv55cd mmcv
47python3.7 setup.py build_ext56python3.7 setup.py build_ext
@@ -49,42 +58,56 @@ python3.7 setup.py develop
49cd ..58cd ..
50pip list | grep mmcv # 查看版本和路径59pip list | grep mmcv # 查看版本和路径
51``` 60```
61+ 
522. 配置安装mmdet622. 配置安装mmdet
63+ 
53```64```
54pip install -r requirements/build.txt65pip install -r requirements/build.txt
55pip install "git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI"66pip install "git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI"
56pip install -v -e .67pip install -v -e .
57```68```
69+ 
58## Train MODEL70## Train MODEL
71+ 
59进入SOLOv2目录下72进入SOLOv2目录下
73+ 
60### 1p74### 1p
75+ 
61导入环境变量,修改train_full_1p.sh权限并运行76导入环境变量,修改train_full_1p.sh权限并运行
77+ 
62```78```
63chmod +x ./test/train_full_1p.sh79chmod +x ./test/train_full_1p.sh
64bash ./test/train_full_1p.sh --data_path=./data/coco80bash ./test/train_full_1p.sh --data_path=./data/coco
65```81```
66 82 
67### 8p83### 8p
84+ 
68导入环境变量,修改train_full_8p.sh权限并运行85导入环境变量,修改train_full_8p.sh权限并运行
86+ 
69```87```
70chmod +x ./test/train_full_8p.sh88chmod +x ./test/train_full_8p.sh
71bash ./test/train_full_8p.sh --data_path=./data/coco89bash ./test/train_full_8p.sh --data_path=./data/coco
72```90```
73 91 
74### Eval92### Eval
93+ 
75修改train_eval_1p.sh权限并运行94修改train_eval_1p.sh权限并运行
95+ 
76```96```
77chmod +x ./test/train_eval_1p.sh97chmod +x ./test/train_eval_1p.sh
78bash ./test/train_eval_1p.sh --data_path=./data/coco98bash ./test/train_eval_1p.sh --data_path=./data/coco
79```99```
100+ 
80### finetuning101### finetuning
102+ 
81修改train_finetune_1p.sh权限并运行103修改train_finetune_1p.sh权限并运行
104+ 
82```105```
83chmod +x ./test/train_eval_1p.sh106chmod +x ./test/train_eval_1p.sh
84bash ./test/train_finetune_1p.sh --data_path=./data/coco107bash ./test/train_finetune_1p.sh --data_path=./data/coco
85```108```
86 109 
87-## SOLOv2 training result 110+## SOLOv2 training result
88 111 
89| Acc@1 | FPS | Npu/Gpu_nums | Epochs | AMP_Type | Loss_Scale |112| Acc@1 | FPS | Npu/Gpu_nums | Epochs | AMP_Type | Loss_Scale |
90| :------: | :------: | :------: | :------: | :------: | :------: |113| :------: | :------: | :------: | :------: | :------: | :------: |
MPyTorch/contrib/cv/detection/SOLOv2/configs/cascade_mask_rcnn_r50_caffe_c4_1x.py+1-1
@@ -24,7 +24,7 @@ model = dict(
24 num_stages=3,24 num_stages=3,
25 strides=(1, 2, 2),25 strides=(1, 2, 2),
26 dilations=(1, 1, 1),26 dilations=(1, 1, 1),
27- out_indices=(2, ),27+ out_indices=(2,),
28 frozen_stages=1,28 frozen_stages=1,
29 norm_cfg=norm_cfg,29 norm_cfg=norm_cfg,
30 norm_eval=True,30 norm_eval=True,
MPyTorch/contrib/cv/detection/SOLOv2/configs/cascade_rcnn_r50_caffe_c4_1x.py+1-1
@@ -24,7 +24,7 @@ model = dict(
24 num_stages=3,24 num_stages=3,
25 strides=(1, 2, 2),25 strides=(1, 2, 2),
26 dilations=(1, 1, 1),26 dilations=(1, 1, 1),
27- out_indices=(2, ),27+ out_indices=(2,),
28 frozen_stages=1,28 frozen_stages=1,
29 norm_cfg=norm_cfg,29 norm_cfg=norm_cfg,
30 norm_eval=True,30 norm_eval=True,
MPyTorch/contrib/cv/detection/SOLOv2/configs/cityscapes/faster_rcnn_r50_fpn_1x_cityscapes.py+3-3
@@ -151,19 +151,19 @@ data = dict(
151 dataset=dict(151 dataset=dict(
152 type=dataset_type,152 type=dataset_type,
153 ann_file=data_root +153 ann_file=data_root +
154- 'annotations/instancesonly_filtered_gtFine_train.json',154+ 'annotations/instancesonly_filtered_gtFine_train.json',
155 img_prefix=data_root + 'train/',155 img_prefix=data_root + 'train/',
156 pipeline=train_pipeline)),156 pipeline=train_pipeline)),
157 val=dict(157 val=dict(
158 type=dataset_type,158 type=dataset_type,
159 ann_file=data_root +159 ann_file=data_root +
160- 'annotations/instancesonly_filtered_gtFine_val.json',160+ 'annotations/instancesonly_filtered_gtFine_val.json',
161 img_prefix=data_root + 'val/',161 img_prefix=data_root + 'val/',
162 pipeline=test_pipeline),162 pipeline=test_pipeline),
163 test=dict(163 test=dict(
164 type=dataset_type,164 type=dataset_type,
165 ann_file=data_root +165 ann_file=data_root +
166- 'annotations/instancesonly_filtered_gtFine_val.json',166+ 'annotations/instancesonly_filtered_gtFine_val.json',
167 img_prefix=data_root + 'val/',167 img_prefix=data_root + 'val/',
168 pipeline=test_pipeline))168 pipeline=test_pipeline))
169# optimizer169# optimizer
MPyTorch/contrib/cv/detection/SOLOv2/configs/cityscapes/mask_rcnn_r50_fpn_1x_cityscapes.py+3-3
@@ -165,19 +165,19 @@ data = dict(
165 dataset=dict(165 dataset=dict(
166 type=dataset_type,166 type=dataset_type,
167 ann_file=data_root +167 ann_file=data_root +
168- 'annotations/instancesonly_filtered_gtFine_train.json',168+ 'annotations/instancesonly_filtered_gtFine_train.json',
169 img_prefix=data_root + 'train/',169 img_prefix=data_root + 'train/',
170 pipeline=train_pipeline)),170 pipeline=train_pipeline)),
171 val=dict(171 val=dict(
172 type=dataset_type,172 type=dataset_type,
173 ann_file=data_root +173 ann_file=data_root +
174- 'annotations/instancesonly_filtered_gtFine_val.json',174+ 'annotations/instancesonly_filtered_gtFine_val.json',
175 img_prefix=data_root + 'val/',175 img_prefix=data_root + 'val/',
176 pipeline=test_pipeline),176 pipeline=test_pipeline),
177 test=dict(177 test=dict(
178 type=dataset_type,178 type=dataset_type,
179 ann_file=data_root +179 ann_file=data_root +
180- 'annotations/instancesonly_filtered_gtFine_val.json',180+ 'annotations/instancesonly_filtered_gtFine_val.json',
181 img_prefix=data_root + 'val/',181 img_prefix=data_root + 'val/',
182 pipeline=test_pipeline))182 pipeline=test_pipeline))
183# optimizer183# optimizer
MPyTorch/contrib/cv/detection/SOLOv2/configs/fast_mask_rcnn_r50_caffe_c4_1x.py+1-1
@@ -23,7 +23,7 @@ model = dict(
23 num_stages=3,23 num_stages=3,
24 strides=(1, 2, 2),24 strides=(1, 2, 2),
25 dilations=(1, 1, 1),25 dilations=(1, 1, 1),
26- out_indices=(2, ),26+ out_indices=(2,),
27 frozen_stages=1,27 frozen_stages=1,
28 norm_cfg=norm_cfg,28 norm_cfg=norm_cfg,
29 norm_eval=True,29 norm_eval=True,
MPyTorch/contrib/cv/detection/SOLOv2/configs/fast_rcnn_r50_caffe_c4_1x.py+1-1
@@ -23,7 +23,7 @@ model = dict(
23 num_stages=3,23 num_stages=3,
24 strides=(1, 2, 2),24 strides=(1, 2, 2),
25 dilations=(1, 1, 1),25 dilations=(1, 1, 1),
26- out_indices=(2, ),26+ out_indices=(2,),
27 frozen_stages=1,27 frozen_stages=1,
28 norm_cfg=norm_cfg,28 norm_cfg=norm_cfg,
29 norm_eval=True,29 norm_eval=True,
MPyTorch/contrib/cv/detection/SOLOv2/configs/faster_rcnn_r50_caffe_c4_1x.py+1-1
@@ -23,7 +23,7 @@ model = dict(
23 num_stages=3,23 num_stages=3,
24 strides=(1, 2, 2),24 strides=(1, 2, 2),
25 dilations=(1, 1, 1),25 dilations=(1, 1, 1),
26- out_indices=(2, ),26+ out_indices=(2,),
27 frozen_stages=1,27 frozen_stages=1,
28 norm_cfg=norm_cfg,28 norm_cfg=norm_cfg,
29 norm_eval=True,29 norm_eval=True,
MPyTorch/contrib/cv/detection/SOLOv2/configs/hrnet/cascade_mask_rcnn_hrnetv2p_w32_20e.py+2-2
@@ -24,8 +24,8 @@ model = dict(
24 num_modules=1,24 num_modules=1,
25 num_branches=1,25 num_branches=1,
26 block='BOTTLENECK',26 block='BOTTLENECK',
27- num_blocks=(4, ),27+ num_blocks=(4,),
28- num_channels=(64, )),28+ num_channels=(64,)),
29 stage2=dict(29 stage2=dict(
30 num_modules=1,30 num_modules=1,
31 num_branches=2,31 num_branches=2,
MPyTorch/contrib/cv/detection/SOLOv2/configs/hrnet/cascade_rcnn_hrnetv2p_w32_20e.py+2-2
@@ -24,8 +24,8 @@ model = dict(
24 num_modules=1,24 num_modules=1,
25 num_branches=1,25 num_branches=1,
26 block='BOTTLENECK',26 block='BOTTLENECK',
27- num_blocks=(4, ),27+ num_blocks=(4,),
28- num_channels=(64, )),28+ num_channels=(64,)),
29 stage2=dict(29 stage2=dict(
30 num_modules=1,30 num_modules=1,
31 num_branches=2,31 num_branches=2,
MPyTorch/contrib/cv/detection/SOLOv2/configs/hrnet/faster_rcnn_hrnetv2p_w18_1x.py+2-2
@@ -23,8 +23,8 @@ model = dict(
23 num_modules=1,23 num_modules=1,
24 num_branches=1,24 num_branches=1,
25 block='BOTTLENECK',25 block='BOTTLENECK',
26- num_blocks=(4, ),26+ num_blocks=(4,),
27- num_channels=(64, )),27+ num_channels=(64,)),
28 stage2=dict(28 stage2=dict(
29 num_modules=1,29 num_modules=1,
30 num_branches=2,30 num_branches=2,
MPyTorch/contrib/cv/detection/SOLOv2/configs/hrnet/faster_rcnn_hrnetv2p_w32_1x.py+2-2
@@ -23,8 +23,8 @@ model = dict(
23 num_modules=1,23 num_modules=1,
24 num_branches=1,24 num_branches=1,
25 block='BOTTLENECK',25 block='BOTTLENECK',
26- num_blocks=(4, ),26+ num_blocks=(4,),
27- num_channels=(64, )),27+ num_channels=(64,)),
28 stage2=dict(28 stage2=dict(
29 num_modules=1,29 num_modules=1,
30 num_branches=2,30 num_branches=2,
MPyTorch/contrib/cv/detection/SOLOv2/configs/hrnet/faster_rcnn_hrnetv2p_w40_1x.py+2-2
@@ -23,8 +23,8 @@ model = dict(
23 num_modules=1,23 num_modules=1,
24 num_branches=1,24 num_branches=1,
25 block='BOTTLENECK',25 block='BOTTLENECK',
26- num_blocks=(4, ),26+ num_blocks=(4,),
27- num_channels=(64, )),27+ num_channels=(64,)),
28 stage2=dict(28 stage2=dict(
29 num_modules=1,29 num_modules=1,
30 num_branches=2,30 num_branches=2,
MPyTorch/contrib/cv/detection/SOLOv2/configs/hrnet/fcos_hrnetv2p_w32_gn_1x_4gpu.py+2-2
@@ -23,8 +23,8 @@ model = dict(
23 num_modules=1,23 num_modules=1,
24 num_branches=1,24 num_branches=1,
25 block='BOTTLENECK',25 block='BOTTLENECK',
26- num_blocks=(4, ),26+ num_blocks=(4,),
27- num_channels=(64, )),27+ num_channels=(64,)),
28 stage2=dict(28 stage2=dict(
29 num_modules=1,29 num_modules=1,
30 num_branches=2,30 num_branches=2,
MPyTorch/contrib/cv/detection/SOLOv2/configs/hrnet/htc_hrnetv2p_w32_20e.py+2-2
@@ -26,8 +26,8 @@ model = dict(
26 num_modules=1,26 num_modules=1,
27 num_branches=1,27 num_branches=1,
28 block='BOTTLENECK',28 block='BOTTLENECK',
29- num_blocks=(4, ),29+ num_blocks=(4,),
30- num_channels=(64, )),30+ num_channels=(64,)),
31 stage2=dict(31 stage2=dict(
32 num_modules=1,32 num_modules=1,
33 num_branches=2,33 num_branches=2,
MPyTorch/contrib/cv/detection/SOLOv2/configs/hrnet/mask_rcnn_hrnetv2p_w18_1x.py+2-2
@@ -23,8 +23,8 @@ model = dict(
23 num_modules=1,23 num_modules=1,
24 num_branches=1,24 num_branches=1,
25 block='BOTTLENECK',25 block='BOTTLENECK',
26- num_blocks=(4, ),26+ num_blocks=(4,),
27- num_channels=(64, )),27+ num_channels=(64,)),
28 stage2=dict(28 stage2=dict(
29 num_modules=1,29 num_modules=1,
30 num_branches=2,30 num_branches=2,
MPyTorch/contrib/cv/detection/SOLOv2/configs/hrnet/mask_rcnn_hrnetv2p_w32_1x.py+2-2
@@ -23,8 +23,8 @@ model = dict(
23 num_modules=1,23 num_modules=1,
24 num_branches=1,24 num_branches=1,
25 block='BOTTLENECK',25 block='BOTTLENECK',
26- num_blocks=(4, ),26+ num_blocks=(4,),
27- num_channels=(64, )),27+ num_channels=(64,)),
28 stage2=dict(28 stage2=dict(
29 num_modules=1,29 num_modules=1,
30 num_branches=2,30 num_branches=2,
MPyTorch/contrib/cv/detection/SOLOv2/configs/libra_rcnn/libra_fast_rcnn_r50_fpn_1x.py+1-1
@@ -123,7 +123,7 @@ data = dict(
123 type=dataset_type,123 type=dataset_type,
124 ann_file=data_root + 'annotations/instances_train2017.json',124 ann_file=data_root + 'annotations/instances_train2017.json',
125 proposal_file=data_root +125 proposal_file=data_root +
126- 'libra_proposals/rpn_r50_fpn_1x_train2017.pkl',126+ 'libra_proposals/rpn_r50_fpn_1x_train2017.pkl',
127 img_prefix=data_root + 'train2017/',127 img_prefix=data_root + 'train2017/',
128 pipeline=train_pipeline),128 pipeline=train_pipeline),
129 val=dict(129 val=dict(
MPyTorch/contrib/cv/detection/SOLOv2/configs/mask_rcnn_r50_caffe_c4_1x.py+1-1
@@ -23,7 +23,7 @@ model = dict(
23 num_stages=3,23 num_stages=3,
24 strides=(1, 2, 2),24 strides=(1, 2, 2),
25 dilations=(1, 1, 1),25 dilations=(1, 1, 1),
26- out_indices=(2, ),26+ out_indices=(2,),
27 frozen_stages=1,27 frozen_stages=1,
28 norm_cfg=norm_cfg,28 norm_cfg=norm_cfg,
29 norm_eval=True,29 norm_eval=True,
MPyTorch/contrib/cv/detection/SOLOv2/configs/rpn_r50_caffe_c4_1x.py+1-1
@@ -22,7 +22,7 @@ model = dict(
22 num_stages=3,22 num_stages=3,
23 strides=(1, 2, 2),23 strides=(1, 2, 2),
24 dilations=(1, 1, 1),24 dilations=(1, 1, 1),
25- out_indices=(2, ),25+ out_indices=(2,),
26 frozen_stages=1,26 frozen_stages=1,
27 norm_cfg=dict(type='BN', requires_grad=False),27 norm_cfg=dict(type='BN', requires_grad=False),
28 norm_eval=True,28 norm_eval=True,
MPyTorch/contrib/cv/detection/SOLOv2/configs/solo/decoupled_solo_light_dcn_r50_fpn_8gpu_3x.py+1-1
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=50,21 depth=50,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch',25 style='pytorch',
26 dcn=dict(26 dcn=dict(
MPyTorch/contrib/cv/detection/SOLOv2/configs/solo/decoupled_solo_light_r50_fpn_8gpu_3x.py+1-1
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=50,21 depth=50,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch'),25 style='pytorch'),
26 neck=dict(26 neck=dict(
MPyTorch/contrib/cv/detection/SOLOv2/configs/solo/decoupled_solo_r101_fpn_8gpu_3x.py+1-1
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=101,21 depth=101,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch'),25 style='pytorch'),
26 neck=dict(26 neck=dict(
MPyTorch/contrib/cv/detection/SOLOv2/configs/solo/decoupled_solo_r50_fpn_8gpu_1x.py+1-1
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=50,21 depth=50,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch'),25 style='pytorch'),
26 neck=dict(26 neck=dict(
MPyTorch/contrib/cv/detection/SOLOv2/configs/solo/decoupled_solo_r50_fpn_8gpu_3x.py+1-1
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=50,21 depth=50,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch'),25 style='pytorch'),
26 neck=dict(26 neck=dict(
MPyTorch/contrib/cv/detection/SOLOv2/configs/solo/solo_r101_fpn_8gpu_3x.py+1-1
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=101,21 depth=101,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch'),25 style='pytorch'),
26 neck=dict(26 neck=dict(
MPyTorch/contrib/cv/detection/SOLOv2/configs/solo/solo_r50_fpn_8gpu_3x.py+1-1
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=50,21 depth=50,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch'),25 style='pytorch'),
26 neck=dict(26 neck=dict(
MPyTorch/contrib/cv/detection/SOLOv2/configs/solov2/solov2_light_448_r18_fpn_8gpu_3x.py+10-10
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=18,21 depth=18,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch'),25 style='pytorch'),
26 neck=dict(26 neck=dict(
@@ -51,14 +51,14 @@ model = dict(
51 alpha=0.25,51 alpha=0.25,
52 loss_weight=1.0)),52 loss_weight=1.0)),
53 mask_feat_head=dict(53 mask_feat_head=dict(
54- type='MaskFeatHead',54+ type='MaskFeatHead',
55- in_channels=256,55+ in_channels=256,
56- out_channels=128,56+ out_channels=128,
57- start_level=0,57+ start_level=0,
58- end_level=3,58+ end_level=3,
59- num_classes=128,59+ num_classes=128,
60- norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),60+ norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),
61- )61+)
62# training and testing settings62# training and testing settings
63train_cfg = dict()63train_cfg = dict()
64test_cfg = dict(64test_cfg = dict(
@@ -79,7 +79,7 @@ train_pipeline = [
79 dict(type='LoadAnnotations', with_bbox=True, with_mask=True),79 dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
80 dict(type='Resize',80 dict(type='Resize',
81 img_scale=[(768, 512), (768, 480), (768, 448),81 img_scale=[(768, 512), (768, 480), (768, 448),
82- (768, 416), (768, 384), (768, 352)],82+ (768, 416), (768, 384), (768, 352)],
83 multiscale_mode='value',83 multiscale_mode='value',
84 keep_ratio=True),84 keep_ratio=True),
85 dict(type='RandomFlip', flip_ratio=0.5),85 dict(type='RandomFlip', flip_ratio=0.5),
MPyTorch/contrib/cv/detection/SOLOv2/configs/solov2/solov2_light_448_r34_fpn_8gpu_3x.py+10-10
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=34,21 depth=34,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch'),25 style='pytorch'),
26 neck=dict(26 neck=dict(
@@ -51,14 +51,14 @@ model = dict(
51 alpha=0.25,51 alpha=0.25,
52 loss_weight=1.0)),52 loss_weight=1.0)),
53 mask_feat_head=dict(53 mask_feat_head=dict(
54- type='MaskFeatHead',54+ type='MaskFeatHead',
55- in_channels=256,55+ in_channels=256,
56- out_channels=128,56+ out_channels=128,
57- start_level=0,57+ start_level=0,
58- end_level=3,58+ end_level=3,
59- num_classes=128,59+ num_classes=128,
60- norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),60+ norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),
61- )61+)
62# training and testing settings62# training and testing settings
63train_cfg = dict()63train_cfg = dict()
64test_cfg = dict(64test_cfg = dict(
@@ -79,7 +79,7 @@ train_pipeline = [
79 dict(type='LoadAnnotations', with_bbox=True, with_mask=True),79 dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
80 dict(type='Resize',80 dict(type='Resize',
81 img_scale=[(768, 512), (768, 480), (768, 448),81 img_scale=[(768, 512), (768, 480), (768, 448),
82- (768, 416), (768, 384), (768, 352)],82+ (768, 416), (768, 384), (768, 352)],
83 multiscale_mode='value',83 multiscale_mode='value',
84 keep_ratio=True),84 keep_ratio=True),
85 dict(type='RandomFlip', flip_ratio=0.5),85 dict(type='RandomFlip', flip_ratio=0.5),
MPyTorch/contrib/cv/detection/SOLOv2/configs/solov2/solov2_light_448_r50_fpn_8gpu_3x.py+10-10
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=50,21 depth=50,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch'),25 style='pytorch'),
26 neck=dict(26 neck=dict(
@@ -51,14 +51,14 @@ model = dict(
51 alpha=0.25,51 alpha=0.25,
52 loss_weight=1.0)),52 loss_weight=1.0)),
53 mask_feat_head=dict(53 mask_feat_head=dict(
54- type='MaskFeatHead',54+ type='MaskFeatHead',
55- in_channels=256,55+ in_channels=256,
56- out_channels=128,56+ out_channels=128,
57- start_level=0,57+ start_level=0,
58- end_level=3,58+ end_level=3,
59- num_classes=128,59+ num_classes=128,
60- norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),60+ norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),
61- )61+)
62# training and testing settings62# training and testing settings
63train_cfg = dict()63train_cfg = dict()
64test_cfg = dict(64test_cfg = dict(
@@ -79,7 +79,7 @@ train_pipeline = [
79 dict(type='LoadAnnotations', with_bbox=True, with_mask=True),79 dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
80 dict(type='Resize',80 dict(type='Resize',
81 img_scale=[(768, 512), (768, 480), (768, 448),81 img_scale=[(768, 512), (768, 480), (768, 448),
82- (768, 416), (768, 384), (768, 352)],82+ (768, 416), (768, 384), (768, 352)],
83 multiscale_mode='value',83 multiscale_mode='value',
84 keep_ratio=True),84 keep_ratio=True),
85 dict(type='RandomFlip', flip_ratio=0.5),85 dict(type='RandomFlip', flip_ratio=0.5),
MPyTorch/contrib/cv/detection/SOLOv2/configs/solov2/solov2_light_512_dcn_r50_fpn_8gpu_3x.py+10-10
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=50,21 depth=50,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch',25 style='pytorch',
26 dcn=dict(26 dcn=dict(
@@ -58,14 +58,14 @@ model = dict(
58 alpha=0.25,58 alpha=0.25,
59 loss_weight=1.0)),59 loss_weight=1.0)),
60 mask_feat_head=dict(60 mask_feat_head=dict(
61- type='MaskFeatHead',61+ type='MaskFeatHead',
62- in_channels=256,62+ in_channels=256,
63- out_channels=128,63+ out_channels=128,
64- start_level=0,64+ start_level=0,
65- end_level=3,65+ end_level=3,
66- num_classes=128,66+ num_classes=128,
67- norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),67+ norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),
68- )68+)
69# training and testing settings69# training and testing settings
70train_cfg = dict()70train_cfg = dict()
71test_cfg = dict(71test_cfg = dict(
@@ -86,7 +86,7 @@ train_pipeline = [
86 dict(type='LoadAnnotations', with_bbox=True, with_mask=True),86 dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
87 dict(type='Resize',87 dict(type='Resize',
88 img_scale=[(852, 512), (852, 480), (852, 448),88 img_scale=[(852, 512), (852, 480), (852, 448),
89- (852, 416), (852, 384), (852, 352)],89+ (852, 416), (852, 384), (852, 352)],
90 multiscale_mode='value',90 multiscale_mode='value',
91 keep_ratio=True),91 keep_ratio=True),
92 dict(type='RandomFlip', flip_ratio=0.5),92 dict(type='RandomFlip', flip_ratio=0.5),
MPyTorch/contrib/cv/detection/SOLOv2/configs/solov2/solov2_r101_dcn_fpn_8gpu_3x.py+10-10
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=101,21 depth=101,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch',25 style='pytorch',
26 dcn=dict(26 dcn=dict(
@@ -58,15 +58,15 @@ model = dict(
58 alpha=0.25,58 alpha=0.25,
59 loss_weight=1.0)),59 loss_weight=1.0)),
60 mask_feat_head=dict(60 mask_feat_head=dict(
61- type='MaskFeatHead',61+ type='MaskFeatHead',
62- in_channels=256,62+ in_channels=256,
63- out_channels=128,63+ out_channels=128,
64- start_level=0,64+ start_level=0,
65- end_level=3,65+ end_level=3,
66- num_classes=256,66+ num_classes=256,
67- conv_cfg=dict(type='DCNv2'),67+ conv_cfg=dict(type='DCNv2'),
68- norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),68+ norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),
69- )69+)
70# training and testing settings70# training and testing settings
71train_cfg = dict()71train_cfg = dict()
72test_cfg = dict(72test_cfg = dict(
MPyTorch/contrib/cv/detection/SOLOv2/configs/solov2/solov2_r101_fpn_8gpu_3x.py+9-9
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=101,21 depth=101,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch'),25 style='pytorch'),
26 neck=dict(26 neck=dict(
@@ -51,14 +51,14 @@ model = dict(
51 alpha=0.25,51 alpha=0.25,
52 loss_weight=1.0)),52 loss_weight=1.0)),
53 mask_feat_head=dict(53 mask_feat_head=dict(
54- type='MaskFeatHead',54+ type='MaskFeatHead',
55- in_channels=256,55+ in_channels=256,
56- out_channels=128,56+ out_channels=128,
57- start_level=0,57+ start_level=0,
58- end_level=3,58+ end_level=3,
59- num_classes=256,59+ num_classes=256,
60- norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),60+ norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),
61- )61+)
62# training and testing settings62# training and testing settings
63train_cfg = dict()63train_cfg = dict()
64test_cfg = dict(64test_cfg = dict(
MPyTorch/contrib/cv/detection/SOLOv2/configs/solov2/solov2_r50_fpn_8gpu_1x.py+10-10
@@ -23,7 +23,7 @@ model = dict(
23 type='ResNet',23 type='ResNet',
24 depth=50,24 depth=50,
25 num_stages=4,25 num_stages=4,
26- out_indices=(0, 1, 2, 3), # C2, C3, C4, C526+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
27 frozen_stages=1,27 frozen_stages=1,
28 style='pytorch'),28 style='pytorch'),
29 neck=dict(29 neck=dict(
@@ -54,14 +54,14 @@ model = dict(
54 alpha=0.25,54 alpha=0.25,
55 loss_weight=1.0)),55 loss_weight=1.0)),
56 mask_feat_head=dict(56 mask_feat_head=dict(
57- type='MaskFeatHead',57+ type='MaskFeatHead',
58- in_channels=256,58+ in_channels=256,
59- out_channels=128,59+ out_channels=128,
60- start_level=0,60+ start_level=0,
61- end_level=3,61+ end_level=3,
62- num_classes=256,62+ num_classes=256,
63- norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),63+ norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),
64- )64+)
65# training and testing settings65# training and testing settings
66train_cfg = dict()66train_cfg = dict()
67test_cfg = dict(67test_cfg = dict(
@@ -83,7 +83,7 @@ train_pipeline = [
83 dict(type='Resize', img_scale=(1333, 800), keep_ratio=True),83 dict(type='Resize', img_scale=(1333, 800), keep_ratio=True),
84 dict(type='RandomFlip', flip_ratio=0.5),84 dict(type='RandomFlip', flip_ratio=0.5),
85 dict(type='Normalize', **img_norm_cfg),85 dict(type='Normalize', **img_norm_cfg),
86- dict(type='Pad', size_divisor=1344), # diff86+ dict(type='Pad', size_divisor=1344), # diff
87 dict(type='DefaultFormatBundle'),87 dict(type='DefaultFormatBundle'),
88 dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels', 'gt_masks']),88 dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels', 'gt_masks']),
89]89]
MPyTorch/contrib/cv/detection/SOLOv2/configs/solov2/solov2_r50_fpn_8gpu_3x.py+9-9
@@ -20,7 +20,7 @@ model = dict(
20 type='ResNet',20 type='ResNet',
21 depth=50,21 depth=50,
22 num_stages=4,22 num_stages=4,
23- out_indices=(0, 1, 2, 3), # C2, C3, C4, C523+ out_indices=(0, 1, 2, 3), # C2, C3, C4, C5
24 frozen_stages=1,24 frozen_stages=1,
25 style='pytorch'),25 style='pytorch'),
26 neck=dict(26 neck=dict(
@@ -51,14 +51,14 @@ model = dict(
51 alpha=0.25,51 alpha=0.25,
52 loss_weight=1.0)),52 loss_weight=1.0)),
53 mask_feat_head=dict(53 mask_feat_head=dict(
54- type='MaskFeatHead',54+ type='MaskFeatHead',
55- in_channels=256,55+ in_channels=256,
56- out_channels=128,56+ out_channels=128,
57- start_level=0,57+ start_level=0,
58- end_level=3,58+ end_level=3,
59- num_classes=256,59+ num_classes=256,
60- norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),60+ norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),
61- )61+)
62# training and testing settings62# training and testing settings
63train_cfg = dict()63train_cfg = dict()
64test_cfg = dict(64test_cfg = dict(
MPyTorch/contrib/cv/detection/SOLOv2/configs/solov2/solov2_x101_dcn_fpn_8gpu_3x.py+9-9
@@ -60,15 +60,15 @@ model = dict(
60 alpha=0.25,60 alpha=0.25,
61 loss_weight=1.0)),61 loss_weight=1.0)),
62 mask_feat_head=dict(62 mask_feat_head=dict(
63- type='MaskFeatHead',63+ type='MaskFeatHead',
64- in_channels=256,64+ in_channels=256,
65- out_channels=128,65+ out_channels=128,
66- start_level=0,66+ start_level=0,
67- end_level=3,67+ end_level=3,
68- num_classes=256,68+ num_classes=256,
69- conv_cfg=dict(type='DCNv2'),69+ conv_cfg=dict(type='DCNv2'),
70- norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),70+ norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)),
71- )71+)
72# training and testing settings72# training and testing settings
73train_cfg = dict()73train_cfg = dict()
74test_cfg = dict(74test_cfg = dict(
MPyTorch/contrib/cv/detection/SOLOv2/demo/inference_demo.py+0-1
@@ -15,7 +15,6 @@
15from mmdet.apis import init_detector, inference_detector, show_result_pyplot, show_result_ins15from mmdet.apis import init_detector, inference_detector, show_result_pyplot, show_result_ins
16import mmcv16import mmcv
17 17 
18- 
19config_file = '../configs/solo/decoupled_solo_r50_fpn_8gpu_3x.py'18config_file = '../configs/solo/decoupled_solo_r50_fpn_8gpu_3x.py'
20# download the checkpoint from model zoo and put it in `checkpoints/`19# download the checkpoint from model zoo and put it in `checkpoints/`
21checkpoint_file = '../checkpoints/DECOUPLED_SOLO_R50_3x.pth'20checkpoint_file = '../checkpoints/DECOUPLED_SOLO_R50_3x.pth'
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/docs/conf.py+1-0
@@ -28,6 +28,7 @@
28#28#
29import os29import os
30import sys30import sys
31+ 
31sys.path.insert(0, os.path.abspath('..'))32sys.path.insert(0, os.path.abspath('..'))
32 33 
33version_file = '../mmcv/version.py'34version_file = '../mmcv/version.py'
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/examples/train_cifar10.py+1-1
@@ -31,7 +31,7 @@ from mmcv import Config
31from mmcv.runner import DistSamplerSeedHook, Runner31from mmcv.runner import DistSamplerSeedHook, Runner
32 32 
33 33 
34-def accuracy(output, target, topk=(1, )):34+def accuracy(output, target, topk=(1,)):
35 """Computes the precision@k for the specified values of k"""35 """Computes the precision@k for the specified values of k"""
36 with torch.no_grad():36 with torch.no_grad():
37 maxk = max(topk)37 maxk = max(topk)
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/cnn/resnet.py+2-2
@@ -259,7 +259,7 @@ class ResNet(nn.Module):
259 for i, num_blocks in enumerate(stage_blocks):259 for i, num_blocks in enumerate(stage_blocks):
260 stride = strides[i]260 stride = strides[i]
261 dilation = dilations[i]261 dilation = dilations[i]
262- planes = 64 * 2**i262+ planes = 64 * 2 ** i
263 res_layer = make_res_layer(263 res_layer = make_res_layer(
264 block,264 block,
265 self.inplanes,265 self.inplanes,
@@ -274,7 +274,7 @@ class ResNet(nn.Module):
274 self.add_module(layer_name, res_layer)274 self.add_module(layer_name, res_layer)
275 self.res_layers.append(layer_name)275 self.res_layers.append(layer_name)
276 276 
277- self.feat_dim = block.expansion * 64 * 2**(len(stage_blocks) - 1)277+ self.feat_dim = block.expansion * 64 * 2 ** (len(stage_blocks) - 1)
278 278 
279 def init_weights(self, pretrained=None):279 def init_weights(self, pretrained=None):
280 if isinstance(pretrained, str):280 if isinstance(pretrained, str):
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/cnn/vgg.py+1-1
@@ -108,7 +108,7 @@ class VGG(nn.Module):
108 num_modules = num_blocks * (2 + with_bn) + 1108 num_modules = num_blocks * (2 + with_bn) + 1
109 end_idx = start_idx + num_modules109 end_idx = start_idx + num_modules
110 dilation = dilations[i]110 dilation = dilations[i]
111- planes = 64 * 2**i if i < 4 else 512111+ planes = 64 * 2 ** i if i < 4 else 512
112 vgg_layer = make_vgg_layer(112 vgg_layer = make_vgg_layer(
113 self.inplanes,113 self.inplanes,
114 planes,114 planes,
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/fileio/handlers/base.py+0-1
@@ -17,7 +17,6 @@ from abc import ABCMeta, abstractmethod
17 17 
18 18 
19class BaseFileHandler(object):19class BaseFileHandler(object):
20- 
21 __metaclass__ = ABCMeta # python 2 compatibility20 __metaclass__ = ABCMeta # python 2 compatibility
22 21 
23 @abstractmethod22 @abstractmethod
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/fileio/io.py+0-1
@@ -119,7 +119,6 @@ def _register_handler(handler, file_formats):
119 119 
120 120 
121def register_handler(file_formats, **kwargs):121def register_handler(file_formats, **kwargs):
122- 
123 def wrap(cls):122 def wrap(cls):
124 _register_handler(cls(**kwargs), file_formats)123 _register_handler(cls(**kwargs), file_formats)
125 return cls124 return cls
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/image/transforms/colorspace.py+0-1
@@ -120,7 +120,6 @@ def gray2rgb(img):
120 120 
121 121 
122def convert_color_factory(src, dst):122def convert_color_factory(src, dst):
123- 
124 code = getattr(cv2, 'COLOR_{}2{}'.format(src.upper(), dst.upper()))123 code = getattr(cv2, 'COLOR_{}2{}'.format(src.upper(), dst.upper()))
125 124 
126 def convert_color(img):125 def convert_color(img):
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/image/transforms/geometry.py+3-3
@@ -163,13 +163,13 @@ def imcrop(img, bboxes, scale=1.0, pad_fill=None):
163 patch_shape = (_y2 - _y1 + 1, _x2 - _x1 + 1, chn)163 patch_shape = (_y2 - _y1 + 1, _x2 - _x1 + 1, chn)
164 patch = np.array(164 patch = np.array(
165 pad_fill, dtype=img.dtype) * np.ones(165 pad_fill, dtype=img.dtype) * np.ones(
166- patch_shape, dtype=img.dtype)166+ patch_shape, dtype=img.dtype)
167 x_start = 0 if _x1 >= 0 else -_x1167 x_start = 0 if _x1 >= 0 else -_x1
168 y_start = 0 if _y1 >= 0 else -_y1168 y_start = 0 if _y1 >= 0 else -_y1
169 w = x2 - x1 + 1169 w = x2 - x1 + 1
170 h = y2 - y1 + 1170 h = y2 - y1 + 1
171 patch[y_start:y_start + h, x_start:x_start + w,171 patch[y_start:y_start + h, x_start:x_start + w,
172- ...] = img[y1:y1 + h, x1:x1 + w, ...]172+ ...] = img[y1:y1 + h, x1:x1 + w, ...]
173 patches.append(patch)173 patches.append(patch)
174 174 
175 if bboxes.ndim == 1:175 if bboxes.ndim == 1:
@@ -192,7 +192,7 @@ def impad(img, shape, pad_val=0):
192 if not isinstance(pad_val, (int, float)):192 if not isinstance(pad_val, (int, float)):
193 assert len(pad_val) == img.shape[-1]193 assert len(pad_val) == img.shape[-1]
194 if len(shape) < len(img.shape):194 if len(shape) < len(img.shape):
195- shape = shape + (img.shape[-1], )195+ shape = shape + (img.shape[-1],)
196 assert len(shape) == len(img.shape)196 assert len(shape) == len(img.shape)
197 for i in range(len(shape)):197 for i in range(len(shape)):
198 assert shape[i] >= img.shape[i]198 assert shape[i] >= img.shape[i]
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/parallel/data_container.py+0-1
@@ -19,7 +19,6 @@ import torch
19 19 
20 20 
21def assert_tensor_type(func):21def assert_tensor_type(func):
22- 
23 @functools.wraps(func)22 @functools.wraps(func)
24 def wrapper(*args, **kwargs):23 def wrapper(*args, **kwargs):
25 if not isinstance(args[0].data, torch.Tensor):24 if not isinstance(args[0].data, torch.Tensor):
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/parallel/data_parallel.py+0-1
@@ -102,4 +102,3 @@ class MMDataParallel(DataParallel):
102 #102 #
103 # inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids)103 # inputs, kwargs = self.scatter(inputs, kwargs, self.device_ids)
104 # return self.module.val_step(*inputs[0], **kwargs[0])104 # return self.module.val_step(*inputs[0], **kwargs[0])
105- 
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/parallel/distributed.py+1-1
@@ -70,4 +70,4 @@ class MMDistributedDataParallel(nn.Module):
70 70 
71 # npu_diff71 # npu_diff
72 inputs, kwargs = self.scatter(inputs, kwargs, [-1])72 inputs, kwargs = self.scatter(inputs, kwargs, [-1])
73- return self.module(*inputs[0], **kwargs[0])73+ return self.module(*inputs[0], **kwargs[0])
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/runner/checkpoint.py+42-21
@@ -29,27 +29,48 @@ import mmcv
29from .dist_utils import get_dist_info29from .dist_utils import get_dist_info
30 30 
31open_mmlab_model_urls = {31open_mmlab_model_urls = {
32- 'vgg16_caffe': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/vgg16_caffe-292e1171.pth', # noqa: E50132+ 'vgg16_caffe': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/vgg16_caffe-292e1171.pth',
33- 'resnet50_caffe': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet50_caffe-788b5fa3.pth', # noqa: E50133+ # noqa: E501
34- 'resnet101_caffe': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet101_caffe-3ad79236.pth', # noqa: E50134+ 'resnet50_caffe': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet50_caffe-788b5fa3.pth',
35- 'resnext50_32x4d': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext50-32x4d-0ab1a123.pth', # noqa: E50135+ # noqa: E501
36- 'resnext101_32x4d': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext101_32x4d-a5af3160.pth', # noqa: E50136+ 'resnet101_caffe': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet101_caffe-3ad79236.pth',
37- 'resnext101_64x4d': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext101_64x4d-ee2c6f71.pth', # noqa: E50137+ # noqa: E501
38- 'contrib/resnet50_gn': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet50_gn_thangvubk-ad1730dd.pth', # noqa: E50138+ 'resnext50_32x4d': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext50-32x4d-0ab1a123.pth',
39- 'detectron/resnet50_gn': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet50_gn-9186a21c.pth', # noqa: E50139+ # noqa: E501
40- 'detectron/resnet101_gn': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet101_gn-cac0ab98.pth', # noqa: E50140+ 'resnext101_32x4d': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext101_32x4d-a5af3160.pth',
41- 'jhu/resnet50_gn_ws': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet50_gn_ws-15beedd8.pth', # noqa: E50141+ # noqa: E501
42- 'jhu/resnet101_gn_ws': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet101_gn_ws-3e3c308c.pth', # noqa: E50142+ 'resnext101_64x4d': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext101_64x4d-ee2c6f71.pth',
43- 'jhu/resnext50_32x4d_gn_ws': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext50_32x4d_gn_ws-0d87ac85.pth', # noqa: E50143+ # noqa: E501
44- 'jhu/resnext101_32x4d_gn_ws': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext101_32x4d_gn_ws-34ac1a9e.pth', # noqa: E50144+ 'contrib/resnet50_gn': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet50_gn_thangvubk-ad1730dd.pth',
45- 'jhu/resnext50_32x4d_gn': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext50_32x4d_gn-c7e8b754.pth', # noqa: E50145+ # noqa: E501
46- 'jhu/resnext101_32x4d_gn': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext101_32x4d_gn-ac3bb84e.pth', # noqa: E50146+ 'detectron/resnet50_gn': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet50_gn-9186a21c.pth',
47- 'msra/hrnetv2_w18': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/hrnetv2_w18-00eb2006.pth', # noqa: E50147+ # noqa: E501
48- 'msra/hrnetv2_w32': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/hrnetv2_w32-dc9eeb4f.pth', # noqa: E50148+ 'detectron/resnet101_gn': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet101_gn-cac0ab98.pth',
49- 'msra/hrnetv2_w40': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/hrnetv2_w40-ed0b031c.pth', # noqa: E50149+ # noqa: E501
50- 'bninception_caffe': 'https://open-mmlab.s3.ap-northeast-2.amazonaws.com/pretrain/third_party/bn_inception_caffe-ed2e8665.pth', # noqa: E50150+ 'jhu/resnet50_gn_ws': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet50_gn_ws-15beedd8.pth',
51- 'kin400/i3d_r50_f32s2_k400': 'https://open-mmlab.s3.ap-northeast-2.amazonaws.com/pretrain/third_party/i3d_r50_f32s2_k400-2c57e077.pth', # noqa: E50151+ # noqa: E501
52- 'kin400/nl3d_r50_f32s2_k400': 'https://open-mmlab.s3.ap-northeast-2.amazonaws.com/pretrain/third_party/nl3d_r50_f32s2_k400-fa7e7caa.pth', # noqa: E50152+ 'jhu/resnet101_gn_ws': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnet101_gn_ws-3e3c308c.pth',
53+ # noqa: E501
54+ 'jhu/resnext50_32x4d_gn_ws': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext50_32x4d_gn_ws-0d87ac85.pth',
55+ # noqa: E501
56+ 'jhu/resnext101_32x4d_gn_ws': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext101_32x4d_gn_ws-34ac1a9e.pth',
57+ # noqa: E501
58+ 'jhu/resnext50_32x4d_gn': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext50_32x4d_gn-c7e8b754.pth',
59+ # noqa: E501
60+ 'jhu/resnext101_32x4d_gn': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/resnext101_32x4d_gn-ac3bb84e.pth',
61+ # noqa: E501
62+ 'msra/hrnetv2_w18': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/hrnetv2_w18-00eb2006.pth',
63+ # noqa: E501
64+ 'msra/hrnetv2_w32': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/hrnetv2_w32-dc9eeb4f.pth',
65+ # noqa: E501
66+ 'msra/hrnetv2_w40': 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/pretrain/third_party/hrnetv2_w40-ed0b031c.pth',
67+ # noqa: E501
68+ 'bninception_caffe': 'https://open-mmlab.s3.ap-northeast-2.amazonaws.com/pretrain/third_party/bn_inception_caffe-ed2e8665.pth',
69+ # noqa: E501
70+ 'kin400/i3d_r50_f32s2_k400': 'https://open-mmlab.s3.ap-northeast-2.amazonaws.com/pretrain/third_party/i3d_r50_f32s2_k400-2c57e077.pth',
71+ # noqa: E501
72+ 'kin400/nl3d_r50_f32s2_k400': 'https://open-mmlab.s3.ap-northeast-2.amazonaws.com/pretrain/third_party/nl3d_r50_f32s2_k400-fa7e7caa.pth',
73+ # noqa: E501
53} # yapf: disable74} # yapf: disable
54 75 
55 76 
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/runner/dist_utils.py+3-1
@@ -18,6 +18,9 @@ import os
18import subprocess18import subprocess
19 19 
20import torch20import torch
21+ 
22+if torch.__version__ >= '1.8.1':
23+ import torch_npu
21import torch.distributed as dist24import torch.distributed as dist
22import torch.multiprocessing as mp25import torch.multiprocessing as mp
23 26 
@@ -87,7 +90,6 @@ def get_dist_info():
87 90 
88 91 
89def master_only(func):92def master_only(func):
90- 
91 @functools.wraps(func)93 @functools.wraps(func)
92 def wrapper(*args, **kwargs):94 def wrapper(*args, **kwargs):
93 rank, _ = get_dist_info()95 rank, _ = get_dist_info()
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/runner/hooks/iter_timer.py+2-1
@@ -24,12 +24,13 @@ class IterTimerHook(Hook):
24 self.t = time.time()24 self.t = time.time()
25 self.skip_step = 025 self.skip_step = 0
26 self.time_all = 026 self.time_all = 0
27+ 
27 def before_iter(self, runner):28 def before_iter(self, runner):
28 runner.log_buffer.update({'data_time': time.time() - self.t})29 runner.log_buffer.update({'data_time': time.time() - self.t})
29 30 
30 def after_iter(self, runner):31 def after_iter(self, runner):
31 ## npu diff32 ## npu diff
32- #runner.log_buffer.update({'time': time.time() - self.t})33+ # runner.log_buffer.update({'time': time.time() - self.t})
33 cur_time = time.time()34 cur_time = time.time()
34 runner.log_buffer.update({'time': time.time() - self.t})35 runner.log_buffer.update({'time': time.time() - self.t})
35 if self.skip_step >= 5:36 if self.skip_step >= 5:
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/runner/hooks/logger/base.py+1-1
@@ -33,7 +33,7 @@ class LoggerHook(Hook):
33 def __init__(self, interval=10, ignore_last=True, reset_flag=False):33 def __init__(self, interval=10, ignore_last=True, reset_flag=False):
34 self.interval = interval34 self.interval = interval
35 self.ignore_last = ignore_last35 self.ignore_last = ignore_last
36- self.reset_flag = reset_flag36+ self.reset_flag = False # reset_flag
37 37 
38 @abstractmethod38 @abstractmethod
39 def log(self, runner):39 def log(self, runner):
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/runner/hooks/logger/pavi.py+2-2
@@ -47,7 +47,7 @@ class PaviClient(object):
47 if not var:47 if not var:
48 raise ValueError(48 raise ValueError(
49 '"{}" is neither specified nor defined as env variables'.49 '"{}" is neither specified nor defined as env variables'.
50- format(env_var))50+ format(env_var))
51 return var51 return var
52 52 
53 def _print_log(self, msg, level=logging.INFO, *args, **kwargs):53 def _print_log(self, msg, level=logging.INFO, *args, **kwargs):
@@ -129,7 +129,7 @@ class PaviClient(object):
129 else:129 else:
130 self._print_log(130 self._print_log(
131 'unexpected status code: {}, err msg: {}'.131 'unexpected status code: {}, err msg: {}'.
132- format(status_code, response.reason),132+ format(status_code, response.reason),
133 level=logging.ERROR)133 level=logging.ERROR)
134 retry += 1134 retry += 1
135 if retry == max_retry:135 if retry == max_retry:
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/runner/hooks/logger/text.py+3-3
@@ -53,7 +53,7 @@ class TextLoggerHook(LoggerHook):
53 if 'time' in log_dict.keys():53 if 'time' in log_dict.keys():
54 self.time_sec_tot += (log_dict['time'] * self.interval)54 self.time_sec_tot += (log_dict['time'] * self.interval)
55 time_sec_avg = self.time_sec_tot / (55 time_sec_avg = self.time_sec_tot / (
56- runner.iter - self.start_iter + 1)56+ runner.iter - self.start_iter + 1)
57 eta_sec = time_sec_avg * (runner.max_iters - runner.iter - 1)57 eta_sec = time_sec_avg * (runner.max_iters - runner.iter - 1)
58 eta_str = str(datetime.timedelta(seconds=int(eta_sec)))58 eta_str = str(datetime.timedelta(seconds=int(eta_sec)))
59 log_str += 'eta: {}, '.format(eta_str)59 log_str += 'eta: {}, '.format(eta_str)
@@ -71,8 +71,8 @@ class TextLoggerHook(LoggerHook):
71 # TODO: resolve this hack71 # TODO: resolve this hack
72 # these items have been in log_str72 # these items have been in log_str
73 if name in [73 if name in [
74- 'mode', 'Epoch', 'iter', 'lr', 'time', 'data_time',74+ 'mode', 'Epoch', 'iter', 'lr', 'time', 'data_time',
75- 'memory', 'epoch'75+ 'memory', 'epoch'
76 ]:76 ]:
77 continue77 continue
78 if isinstance(val, float):78 if isinstance(val, float):
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/runner/hooks/lr_updater.py+7-7
@@ -64,7 +64,7 @@ class LrUpdaterHook(Hook):
64 k = (1 - cur_iters / self.warmup_iters) * (1 - self.warmup_ratio)64 k = (1 - cur_iters / self.warmup_iters) * (1 - self.warmup_ratio)
65 warmup_lr = [_lr * (1 - k) for _lr in self.regular_lr]65 warmup_lr = [_lr * (1 - k) for _lr in self.regular_lr]
66 elif self.warmup == 'exp':66 elif self.warmup == 'exp':
67- k = self.warmup_ratio**(1 - cur_iters / self.warmup_iters)67+ k = self.warmup_ratio ** (1 - cur_iters / self.warmup_iters)
68 warmup_lr = [_lr * k for _lr in self.regular_lr]68 warmup_lr = [_lr * k for _lr in self.regular_lr]
69 return warmup_lr69 return warmup_lr
70 70 
@@ -130,14 +130,14 @@ class StepLrUpdaterHook(LrUpdaterHook):
130 progress = runner.epoch if self.by_epoch else runner.iter130 progress = runner.epoch if self.by_epoch else runner.iter
131 131 
132 if isinstance(self.step, int):132 if isinstance(self.step, int):
133- return base_lr * (self.gamma**(progress // self.step))133+ return base_lr * (self.gamma ** (progress // self.step))
134 134 
135 exp = len(self.step)135 exp = len(self.step)
136 for i, s in enumerate(self.step):136 for i, s in enumerate(self.step):
137 if progress < s:137 if progress < s:
138 exp = i138 exp = i
139 break139 break
140- return base_lr * self.gamma**exp140+ return base_lr * self.gamma ** exp
141 141 
142 142 
143class ExpLrUpdaterHook(LrUpdaterHook):143class ExpLrUpdaterHook(LrUpdaterHook):
@@ -148,7 +148,7 @@ class ExpLrUpdaterHook(LrUpdaterHook):
148 148 
149 def get_lr(self, runner, base_lr):149 def get_lr(self, runner, base_lr):
150 progress = runner.epoch if self.by_epoch else runner.iter150 progress = runner.epoch if self.by_epoch else runner.iter
151- return base_lr * self.gamma**progress151+ return base_lr * self.gamma ** progress
152 152 
153 153 
154class PolyLrUpdaterHook(LrUpdaterHook):154class PolyLrUpdaterHook(LrUpdaterHook):
@@ -165,7 +165,7 @@ class PolyLrUpdaterHook(LrUpdaterHook):
165 else:165 else:
166 progress = runner.iter166 progress = runner.iter
167 max_progress = runner.max_iters167 max_progress = runner.max_iters
168- coeff = (1 - progress / max_progress)**self.power168+ coeff = (1 - progress / max_progress) ** self.power
169 return (base_lr - self.min_lr) * coeff + self.min_lr169 return (base_lr - self.min_lr) * coeff + self.min_lr
170 170 
171 171 
@@ -178,7 +178,7 @@ class InvLrUpdaterHook(LrUpdaterHook):
178 178 
179 def get_lr(self, runner, base_lr):179 def get_lr(self, runner, base_lr):
180 progress = runner.epoch if self.by_epoch else runner.iter180 progress = runner.epoch if self.by_epoch else runner.iter
181- return base_lr * (1 + self.gamma * progress)**(-self.power)181+ return base_lr * (1 + self.gamma * progress) ** (-self.power)
182 182 
183 183 
184class CosineLrUpdaterHook(LrUpdaterHook):184class CosineLrUpdaterHook(LrUpdaterHook):
@@ -195,4 +195,4 @@ class CosineLrUpdaterHook(LrUpdaterHook):
195 progress = runner.iter195 progress = runner.iter
196 max_progress = runner.max_iters196 max_progress = runner.max_iters
197 return self.target_lr + 0.5 * (base_lr - self.target_lr) * \197 return self.target_lr + 0.5 * (base_lr - self.target_lr) * \
198- (1 + cos(pi * (progress / max_progress)))198+ (1 + cos(pi * (progress / max_progress)))
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/runner/runner.py+16-8
@@ -81,10 +81,10 @@ class Runner(object):
81 81 
82 self._rank, self._world_size = get_dist_info()82 self._rank, self._world_size = get_dist_info()
83 self.timestamp = get_time_str()83 self.timestamp = get_time_str()
84- if logger is None:84+ # if logger is None:
85- self.logger = self.init_logger(work_dir, log_level)85+ self.logger = self.init_logger(work_dir, log_level)
86- else:86+ # else:
87- self.logger = logger87+ # self.logger = logger
88 self.log_buffer = LogBuffer()88 self.log_buffer = LogBuffer()
89 89 
90 self.mode = None90 self.mode = None
@@ -94,9 +94,11 @@ class Runner(object):
94 self._inner_iter = 094 self._inner_iter = 0
95 self._max_epochs = 095 self._max_epochs = 0
96 self._max_iters = 096 self._max_iters = 0
97+ self.train_performance = False
97 self.samples_per_gpu = samples_per_gpu98 self.samples_per_gpu = samples_per_gpu
98 self.num_of_gpus = num_of_gpus99 self.num_of_gpus = num_of_gpus
99 self.iter_time_hook = IterTimerHook()100 self.iter_time_hook = IterTimerHook()
101+ 
100 @property102 @property
101 def model_name(self):103 def model_name(self):
102 """str: Name of the model, usually the module class name."""104 """str: Name of the model, usually the module class name."""
@@ -194,6 +196,9 @@ class Runner(object):
194 logging.basicConfig(196 logging.basicConfig(
195 format='%(asctime)s - %(levelname)s - %(message)s', level=level)197 format='%(asctime)s - %(levelname)s - %(message)s', level=level)
196 logger = logging.getLogger(__name__)198 logger = logging.getLogger(__name__)
199+ if self.rank == 0:
200+ logger.addHandler(logging.StreamHandler())
201+ logger.setLevel(logging.INFO)
197 if log_dir and self.rank == 0:202 if log_dir and self.rank == 0:
198 filename = '{}.log'.format(self.timestamp)203 filename = '{}.log'.format(self.timestamp)
199 log_file = osp.join(log_dir, filename)204 log_file = osp.join(log_dir, filename)
@@ -325,11 +330,14 @@ class Runner(object):
325 self.outputs = outputs330 self.outputs = outputs
326 self.call_hook('after_train_iter')331 self.call_hook('after_train_iter')
327 self._iter += 1332 self._iter += 1
333+ if i >= 500 and self.train_performance:
334+ exit(0)
328 if i % 200 == 0 and i:335 if i % 200 == 0 and i:
329 self.logger.info('FPS: %02f' % (self.samples_per_gpu * self.num_of_gpus * (i - 5) /336 self.logger.info('FPS: %02f' % (self.samples_per_gpu * self.num_of_gpus * (i - 5) /
330- self.iter_time_hook.time_all))337+ self.iter_time_hook.time_all))
331 338 
332- self.logger.info('FPS: ' + str(self.samples_per_gpu * self.num_of_gpus / self.iter_time_hook.time_all * (len(self.data_loader) - 5)))339+ self.logger.info('FPS: ' + str(
340+ self.samples_per_gpu * self.num_of_gpus / self.iter_time_hook.time_all * (len(self.data_loader) - 5)))
333 self.call_hook('after_train_epoch')341 self.call_hook('after_train_epoch')
334 self._epoch += 1342 self._epoch += 1
335 343 
@@ -405,14 +413,14 @@ class Runner(object):
405 if not hasattr(self, mode):413 if not hasattr(self, mode):
406 raise ValueError(414 raise ValueError(
407 'runner has no method named "{}" to run an epoch'.415 'runner has no method named "{}" to run an epoch'.
408- format(mode))416+ format(mode))
409 epoch_runner = getattr(self, mode)417 epoch_runner = getattr(self, mode)
410 elif callable(mode): # custom train()418 elif callable(mode): # custom train()
411 epoch_runner = mode419 epoch_runner = mode
412 else:420 else:
413 raise TypeError('mode in workflow must be a str or '421 raise TypeError('mode in workflow must be a str or '
414 'callable function, not {}'.format(422 'callable function, not {}'.format(
415- type(mode)))423+ type(mode)))
416 for _ in range(epochs):424 for _ in range(epochs):
417 if mode == 'train' and self.epoch >= max_epochs:425 if mode == 'train' and self.epoch >= max_epochs:
418 return426 return
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/utils/misc.py+1-1
@@ -158,7 +158,7 @@ def check_prerequisites(
158 prerequisites,158 prerequisites,
159 checker,159 checker,
160 msg_tmpl='Prerequisites "{}" are required in method "{}" but not '160 msg_tmpl='Prerequisites "{}" are required in method "{}" but not '
161- 'found, please install them first.'): # yapf: disable161+ 'found, please install them first.'): # yapf: disable
162 """A decorator factory to check if prerequisites are satisfied.162 """A decorator factory to check if prerequisites are satisfied.
163 163 
164 Args:164 Args:
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/utils/path.py+1-1
@@ -94,7 +94,7 @@ def scandir(dir_path, suffix=None):
94 return _scandir_py(dir_path, suffix)94 return _scandir_py(dir_path, suffix)
95 95 
96 96 
97-def find_vcs_root(path, markers=('.git', )):97+def find_vcs_root(path, markers=('.git',)):
98 """Finds the root directory (including itself) of specified markers.98 """Finds the root directory (including itself) of specified markers.
99 99 
100 Args:100 Args:
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/video/__init__.py+0-10
@@ -13,13 +13,3 @@
13# limitations under the License.13# limitations under the License.
14 14 
15# Copyright (c) Open-MMLab. All rights reserved.15# Copyright (c) Open-MMLab. All rights reserved.
16-from .io import Cache, VideoReader, frames2video
17-from .optflow import (dequantize_flow, flow_warp, flowread, flowwrite,
18- quantize_flow)
19-from .processing import concat_video, convert_video, cut_video, resize_video
20- 
21-__all__ = [
22- 'Cache', 'VideoReader', 'frames2video', 'convert_video', 'resize_video',
23- 'cut_video', 'concat_video', 'flowread', 'flowwrite', 'quantize_flow',
24- 'dequantize_flow', 'flow_warp'
25-]
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/video/optflow.py+2-2
@@ -54,7 +54,7 @@ def flowread(flow_or_path, quantize=False, concat_axis=0, *args, **kwargs):
54 if header != 'PIEH':54 if header != 'PIEH':
55 raise IOError(55 raise IOError(
56 'Invalid flow file: {}, header does not contain PIEH'.56 'Invalid flow file: {}, header does not contain PIEH'.
57- format(flow_or_path))57+ format(flow_or_path))
58 58 
59 w = np.fromfile(f, np.int32, 1).squeeze()59 w = np.fromfile(f, np.int32, 1).squeeze()
60 h = np.fromfile(f, np.int32, 1).squeeze()60 h = np.fromfile(f, np.int32, 1).squeeze()
@@ -65,7 +65,7 @@ def flowread(flow_or_path, quantize=False, concat_axis=0, *args, **kwargs):
65 if cat_flow.ndim != 2:65 if cat_flow.ndim != 2:
66 raise IOError(66 raise IOError(
67 '{} is not a valid quantized flow file, its dimension is {}.'.67 '{} is not a valid quantized flow file, its dimension is {}.'.
68- format(flow_or_path, cat_flow.ndim))68+ format(flow_or_path, cat_flow.ndim))
69 assert cat_flow.shape[concat_axis] % 2 == 069 assert cat_flow.shape[concat_axis] % 2 == 0
70 dx, dy = np.split(cat_flow, 2, axis=concat_axis)70 dx, dy = np.split(cat_flow, 2, axis=concat_axis)
71 flow = dequantize_flow(dx, dy, *args, **kwargs)71 flow = dequantize_flow(dx, dy, *args, **kwargs)
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/mmcv/visualization/optflow.py+5-5
@@ -18,7 +18,7 @@ from __future__ import division
18import numpy as np18import numpy as np
19 19 
20from mmcv.image import rgb2bgr20from mmcv.image import rgb2bgr
21-from mmcv.video import flowread21+# from mmcv.video import flowread
22from .image import imshow22from .image import imshow
23 23 
24 24 
@@ -58,12 +58,12 @@ def flow2rgb(flow, color_wheel=None, unknown_thr=1e6):
58 dy = flow[:, :, 1].copy()58 dy = flow[:, :, 1].copy()
59 59 
60 ignore_inds = (60 ignore_inds = (
61- np.isnan(dx) | np.isnan(dy) | (np.abs(dx) > unknown_thr) |61+ np.isnan(dx) | np.isnan(dy) | (np.abs(dx) > unknown_thr) |
62- (np.abs(dy) > unknown_thr))62+ (np.abs(dy) > unknown_thr))
63 dx[ignore_inds] = 063 dx[ignore_inds] = 0
64 dy[ignore_inds] = 064 dy[ignore_inds] = 0
65 65 
66- rad = np.sqrt(dx**2 + dy**2)66+ rad = np.sqrt(dx ** 2 + dy ** 2)
67 if np.any(rad > np.finfo(float).eps):67 if np.any(rad > np.finfo(float).eps):
68 max_rad = np.max(rad)68 max_rad = np.max(rad)
69 dx /= max_rad69 dx /= max_rad
@@ -71,7 +71,7 @@ def flow2rgb(flow, color_wheel=None, unknown_thr=1e6):
71 71 
72 [h, w] = dx.shape72 [h, w] = dx.shape
73 73 
74- rad = np.sqrt(dx**2 + dy**2)74+ rad = np.sqrt(dx ** 2 + dy ** 2)
75 angle = np.arctan2(-dy, -dx) / np.pi75 angle = np.arctan2(-dy, -dx) / np.pi
76 76 
77 bin_real = (angle + 1) / 2 * (num_bins - 1)77 bin_real = (angle + 1) / 2 * (num_bins - 1)
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/setup.py+0-11
@@ -79,17 +79,6 @@ else:
79 extra_link_args = []79 extra_link_args = []
80 80 
81EXT_MODULES = [81EXT_MODULES = [
82- Extension(
83- name='mmcv._ext',
84- sources=[
85- './mmcv/video/optflow_warp/flow_warp.cpp',
86- './mmcv/video/optflow_warp/flow_warp_module.pyx'
87- ],
88- include_dirs=[numpy.get_include()],
89- language='c++',
90- extra_compile_args=extra_compile_args,
91- extra_link_args=extra_link_args,
92- ),
93]82]
94 83 
95setup(84setup(
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/tests/data/config/a.b.py+0-1
@@ -11,4 +11,3 @@
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and12# See the License for the specific language governing permissions and
13# limitations under the License.13# limitations under the License.
14- 
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/tests/test_fileio.py+0-4
@@ -59,7 +59,6 @@ obj_for_test = [{'a': 'abc', 'b': 1}, 2, 'c']
59 59 
60 60 
61def test_json():61def test_json():
62- 
63 def json_checker(dump_str):62 def json_checker(dump_str):
64 assert dump_str in [63 assert dump_str in [
65 '[{"a": "abc", "b": 1}, 2, "c"]', '[{"b": 1, "a": "abc"}, 2, "c"]'64 '[{"a": "abc", "b": 1}, 2, "c"]', '[{"b": 1, "a": "abc"}, 2, "c"]'
@@ -69,7 +68,6 @@ def test_json():
69 68 
70 69 
71def test_yaml():70def test_yaml():
72- 
73 def yaml_checker(dump_str):71 def yaml_checker(dump_str):
74 assert dump_str in [72 assert dump_str in [
75 '- {a: abc, b: 1}\n- 2\n- c\n', '- {b: 1, a: abc}\n- 2\n- c\n',73 '- {a: abc, b: 1}\n- 2\n- c\n', '- {b: 1, a: abc}\n- 2\n- c\n',
@@ -80,7 +78,6 @@ def test_yaml():
80 78 
81 79 
82def test_pickle():80def test_pickle():
83- 
84 def pickle_checker(dump_str):81 def pickle_checker(dump_str):
85 import pickle82 import pickle
86 assert pickle.loads(dump_str) == obj_for_test83 assert pickle.loads(dump_str) == obj_for_test
@@ -99,7 +96,6 @@ def test_exception():
99 96 
100 97 
101def test_register_handler():98def test_register_handler():
102- 
103 @mmcv.register_handler('txt')99 @mmcv.register_handler('txt')
104 class TxtHandler1(mmcv.BaseFileHandler):100 class TxtHandler1(mmcv.BaseFileHandler):
105 101 
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/tests/test_image.py+5-5
@@ -74,8 +74,8 @@ class TestImage(object):
74 in_img = np.random.rand(10, 10, 3).astype(np.float32)74 in_img = np.random.rand(10, 10, 3).astype(np.float32)
75 out_img = mmcv.bgr2gray(in_img)75 out_img = mmcv.bgr2gray(in_img)
76 computed_gray = (76 computed_gray = (
77- in_img[:, :, 0] * 0.114 + in_img[:, :, 1] * 0.587 +77+ in_img[:, :, 0] * 0.114 + in_img[:, :, 1] * 0.587 +
78- in_img[:, :, 2] * 0.299)78+ in_img[:, :, 2] * 0.299)
79 assert_array_almost_equal(out_img, computed_gray, decimal=4)79 assert_array_almost_equal(out_img, computed_gray, decimal=4)
80 out_img_3d = mmcv.bgr2gray(in_img, True)80 out_img_3d = mmcv.bgr2gray(in_img, True)
81 assert out_img_3d.shape == (10, 10, 1)81 assert out_img_3d.shape == (10, 10, 1)
@@ -85,8 +85,8 @@ class TestImage(object):
85 in_img = np.random.rand(10, 10, 3).astype(np.float32)85 in_img = np.random.rand(10, 10, 3).astype(np.float32)
86 out_img = mmcv.rgb2gray(in_img)86 out_img = mmcv.rgb2gray(in_img)
87 computed_gray = (87 computed_gray = (
88- in_img[:, :, 0] * 0.299 + in_img[:, :, 1] * 0.587 +88+ in_img[:, :, 0] * 0.299 + in_img[:, :, 1] * 0.587 +
89- in_img[:, :, 2] * 0.114)89+ in_img[:, :, 2] * 0.114)
90 assert_array_almost_equal(out_img, computed_gray, decimal=4)90 assert_array_almost_equal(out_img, computed_gray, decimal=4)
91 out_img_3d = mmcv.rgb2gray(in_img, True)91 out_img_3d = mmcv.rgb2gray(in_img, True)
92 assert out_img_3d.shape == (10, 10, 1)92 assert out_img_3d.shape == (10, 10, 1)
@@ -324,7 +324,7 @@ class TestImage(object):
324 (15, 2, 3), dtype='uint8'), padded_img[:, 10:, :])324 (15, 2, 3), dtype='uint8'), padded_img[:, 10:, :])
325 325 
326 with pytest.raises(AssertionError):326 with pytest.raises(AssertionError):
327- mmcv.impad(img, (15, ), 0)327+ mmcv.impad(img, (15,), 0)
328 with pytest.raises(AssertionError):328 with pytest.raises(AssertionError):
329 mmcv.impad(img, (5, 5), 0)329 mmcv.impad(img, (5, 5), 0)
330 with pytest.raises(AssertionError):330 with pytest.raises(AssertionError):
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/tests/test_misc.py+1-3
@@ -32,7 +32,7 @@ def test_iter_cast():
32 32 
33def test_is_seq_of():33def test_is_seq_of():
34 assert mmcv.is_seq_of([1.0, 2.0, 3.0], float)34 assert mmcv.is_seq_of([1.0, 2.0, 3.0], float)
35- assert mmcv.is_seq_of([(1, ), (2, ), (3, )], tuple)35+ assert mmcv.is_seq_of([(1,), (2,), (3,)], tuple)
36 assert mmcv.is_seq_of((1.0, 2.0, 3.0), float)36 assert mmcv.is_seq_of((1.0, 2.0, 3.0), float)
37 assert mmcv.is_list_of([1.0, 2.0, 3.0], float)37 assert mmcv.is_list_of([1.0, 2.0, 3.0], float)
38 assert not mmcv.is_seq_of((1.0, 2.0, 3.0), float, seq_type=list)38 assert not mmcv.is_seq_of((1.0, 2.0, 3.0), float, seq_type=list)
@@ -57,7 +57,6 @@ def test_concat_list():
57 57 
58 58 
59def test_requires_package(capsys):59def test_requires_package(capsys):
60- 
61 @mmcv.requires_package('nnn')60 @mmcv.requires_package('nnn')
62 def func_a():61 def func_a():
63 pass62 pass
@@ -87,7 +86,6 @@ def test_requires_package(capsys):
87 86 
88 87 
89def test_requires_executable(capsys):88def test_requires_executable(capsys):
90- 
91 @mmcv.requires_executable('nnn')89 @mmcv.requires_executable('nnn')
92 def func_a():90 def func_a():
93 pass91 pass
MPyTorch/contrib/cv/detection/SOLOv2/mmcv/tests/test_optflow.py+68-69
@@ -158,7 +158,6 @@ def test_flow2rgb():
158 158 
159 159 
160def test_flow_warp():160def test_flow_warp():
161- 
162 def np_flow_warp(flow, img):161 def np_flow_warp(flow, img):
163 output = np.zeros_like(img, dtype=img.dtype)162 output = np.zeros_like(img, dtype=img.dtype)
164 height = flow.shape[0]163 height = flow.shape[0]
@@ -172,7 +171,7 @@ def test_flow_warp():
172 valid = (sx >= 0) & (sx < height - 1) & (sy >= 0) & (sy < width - 1)171 valid = (sx >= 0) & (sx < height - 1) & (sy >= 0) & (sy < width - 1)
173 172 
174 output[valid, :] = img[dx[valid].round().astype(int),173 output[valid, :] = img[dx[valid].round().astype(int),
175- dy[valid].round().astype(int), :]174+ dy[valid].round().astype(int), :]
176 175 
177 return output176 return output
178 177 
@@ -202,74 +201,74 @@ def test_make_color_wheel():
202 color_wheel = mmcv.make_color_wheel([2, 2, 2, 2, 2, 2])201 color_wheel = mmcv.make_color_wheel([2, 2, 2, 2, 2, 2])
203 # yapf: disable202 # yapf: disable
204 assert_array_equal(default_color_wheel, np.array(203 assert_array_equal(default_color_wheel, np.array(
205- [[1. , 0. , 0. ],204+ [[1., 0., 0.],
206- [1. , 0.06666667, 0. ],205+ [1., 0.06666667, 0.],
207- [1. , 0.13333334, 0. ],206+ [1., 0.13333334, 0.],
208- [1. , 0.2 , 0. ],207+ [1., 0.2, 0.],
209- [1. , 0.26666668, 0. ],208+ [1., 0.26666668, 0.],
210- [1. , 0.33333334, 0. ],209+ [1., 0.33333334, 0.],
211- [1. , 0.4 , 0. ],210+ [1., 0.4, 0.],
212- [1. , 0.46666667, 0. ],211+ [1., 0.46666667, 0.],
213- [1. , 0.53333336, 0. ],212+ [1., 0.53333336, 0.],
214- [1. , 0.6 , 0. ],213+ [1., 0.6, 0.],
215- [1. , 0.6666667 , 0. ],214+ [1., 0.6666667, 0.],
216- [1. , 0.73333335, 0. ],215+ [1., 0.73333335, 0.],
217- [1. , 0.8 , 0. ],216+ [1., 0.8, 0.],
218- [1. , 0.8666667 , 0. ],217+ [1., 0.8666667, 0.],
219- [1. , 0.93333334, 0. ],218+ [1., 0.93333334, 0.],
220- [1. , 1. , 0. ],219+ [1., 1., 0.],
221- [0.8333333 , 1. , 0. ],220+ [0.8333333, 1., 0.],
222- [0.6666667 , 1. , 0. ],221+ [0.6666667, 1., 0.],
223- [0.5 , 1. , 0. ],222+ [0.5, 1., 0.],
224- [0.33333334, 1. , 0. ],223+ [0.33333334, 1., 0.],
225- [0.16666667, 1. , 0. ],224+ [0.16666667, 1., 0.],
226- [0. , 1. , 0. ],225+ [0., 1., 0.],
227- [0. , 1. , 0.25 ],226+ [0., 1., 0.25],
228- [0. , 1. , 0.5 ],227+ [0., 1., 0.5],
229- [0. , 1. , 0.75 ],228+ [0., 1., 0.75],
230- [0. , 1. , 1. ],229+ [0., 1., 1.],
231- [0. , 0.90909094, 1. ],230+ [0., 0.90909094, 1.],
232- [0. , 0.8181818 , 1. ],231+ [0., 0.8181818, 1.],
233- [0. , 0.72727275, 1. ],232+ [0., 0.72727275, 1.],
234- [0. , 0.6363636 , 1. ],233+ [0., 0.6363636, 1.],
235- [0. , 0.54545456, 1. ],234+ [0., 0.54545456, 1.],
236- [0. , 0.45454547, 1. ],235+ [0., 0.45454547, 1.],
237- [0. , 0.36363637, 1. ],236+ [0., 0.36363637, 1.],
238- [0. , 0.27272728, 1. ],237+ [0., 0.27272728, 1.],
239- [0. , 0.18181819, 1. ],238+ [0., 0.18181819, 1.],
240- [0. , 0.09090909, 1. ],239+ [0., 0.09090909, 1.],
241- [0. , 0. , 1. ],240+ [0., 0., 1.],
242- [0.07692308, 0. , 1. ],241+ [0.07692308, 0., 1.],
243- [0.15384616, 0. , 1. ],242+ [0.15384616, 0., 1.],
244- [0.23076923, 0. , 1. ],243+ [0.23076923, 0., 1.],
245- [0.30769232, 0. , 1. ],244+ [0.30769232, 0., 1.],
246- [0.3846154 , 0. , 1. ],245+ [0.3846154, 0., 1.],
247- [0.46153846, 0. , 1. ],246+ [0.46153846, 0., 1.],
248- [0.53846157, 0. , 1. ],247+ [0.53846157, 0., 1.],
249- [0.61538464, 0. , 1. ],248+ [0.61538464, 0., 1.],
250- [0.6923077 , 0. , 1. ],249+ [0.6923077, 0., 1.],
251- [0.7692308 , 0. , 1. ],250+ [0.7692308, 0., 1.],
252- [0.84615386, 0. , 1. ],251+ [0.84615386, 0., 1.],
253- [0.9230769 , 0. , 1. ],252+ [0.9230769, 0., 1.],
254- [1. , 0. , 1. ],253+ [1., 0., 1.],
255- [1. , 0. , 0.8333333 ],254+ [1., 0., 0.8333333],
256- [1. , 0. , 0.6666667 ],255+ [1., 0., 0.6666667],
257- [1. , 0. , 0.5 ],256+ [1., 0., 0.5],
258- [1. , 0. , 0.33333334],257+ [1., 0., 0.33333334],
259- [1. , 0. , 0.16666667]], dtype=np.float32))258+ [1., 0., 0.16666667]], dtype=np.float32))
260 259 
261 assert_array_equal(260 assert_array_equal(
262 color_wheel,261 color_wheel,
263- np.array([[1., 0. , 0. ],262+ np.array([[1., 0., 0.],
264- [1. , 0.5, 0. ],263+ [1., 0.5, 0.],
265- [1. , 1. , 0. ],264+ [1., 1., 0.],
266- [0.5, 1. , 0. ],265+ [0.5, 1., 0.],
267- [0. , 1. , 0. ],266+ [0., 1., 0.],
268- [0. , 1. , 0.5],267+ [0., 1., 0.5],
269- [0. , 1. , 1. ],268+ [0., 1., 1.],
270- [0. , 0.5, 1. ],269+ [0., 0.5, 1.],
271- [0. , 0. , 1. ],270+ [0., 0., 1.],
272- [0.5, 0. , 1. ],271+ [0.5, 0., 1.],
273- [1. , 0. , 1. ],272+ [1., 0., 1.],
274- [1. , 0. , 0.5]], dtype=np.float32))273+ [1., 0., 0.5]], dtype=np.float32))
275 # yapf: enable274 # yapf: enable
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/apis/inference.py+4-3
@@ -29,6 +29,7 @@ from mmdet.models import build_detector
29import cv229import cv2
30from scipy import ndimage30from scipy import ndimage
31 31 
32+ 
32def init_detector(config, checkpoint=None, device='cuda:0'):33def init_detector(config, checkpoint=None, device='cuda:0'):
33 """Initialize a detector from config file.34 """Initialize a detector from config file.
34 35 
@@ -280,7 +281,7 @@ def show_result_ins(img,
280 for _ in range(num_mask)281 for _ in range(num_mask)
281 ]282 ]
282 for idx in range(num_mask):283 for idx in range(num_mask):
283- idx = -(idx+1)284+ idx = -(idx + 1)
284 cur_mask = seg_label[idx, :, :]285 cur_mask = seg_label[idx, :, :]
285 cur_mask = mmcv.imresize(cur_mask, (w, h))286 cur_mask = mmcv.imresize(cur_mask, (w, h))
286 cur_mask = (cur_mask > 0.5).astype(np.uint8)287 cur_mask = (cur_mask > 0.5).astype(np.uint8)
@@ -293,11 +294,11 @@ def show_result_ins(img,
293 cur_cate = cate_label[idx]294 cur_cate = cate_label[idx]
294 cur_score = cate_score[idx]295 cur_score = cate_score[idx]
295 label_text = class_names[cur_cate]296 label_text = class_names[cur_cate]
296- #label_text += '|{:.02f}'.format(cur_score)297+ # label_text += '|{:.02f}'.format(cur_score)
297 center_y, center_x = ndimage.measurements.center_of_mass(cur_mask)298 center_y, center_x = ndimage.measurements.center_of_mass(cur_mask)
298 vis_pos = (max(int(center_x) - 10, 0), int(center_y))299 vis_pos = (max(int(center_x) - 10, 0), int(center_y))
299 cv2.putText(img_show, label_text, vis_pos,300 cv2.putText(img_show, label_text, vis_pos,
300- cv2.FONT_HERSHEY_COMPLEX, 0.3, (255, 255, 255)) # green301+ cv2.FONT_HERSHEY_COMPLEX, 0.3, (255, 255, 255)) # green
301 if out_file is None:302 if out_file is None:
302 return img_show303 return img_show
303 else:304 else:
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/apis/train.py+20-9
@@ -30,6 +30,8 @@ from mmdet.datasets import DATASETS, build_dataloader
30from mmdet.utils import get_root_logger30from mmdet.utils import get_root_logger
31from apex import amp31from apex import amp
32import apex32import apex
33+ 
34+ 
33def set_random_seed(seed, deterministic=False):35def set_random_seed(seed, deterministic=False):
34 """Set random seed.36 """Set random seed.
35 37 
@@ -103,7 +105,8 @@ def train_detector(model,
103 cfg,105 cfg,
104 distributed=False,106 distributed=False,
105 validate=False,107 validate=False,
106- timestamp=None):108+ timestamp=None,
109+ train_performance=False):
107 logger = get_root_logger(cfg.log_level)110 logger = get_root_logger(cfg.log_level)
108 111 
109 # start training112 # start training
@@ -114,7 +117,8 @@ def train_detector(model,
114 cfg,117 cfg,
115 validate=validate,118 validate=validate,
116 logger=logger,119 logger=logger,
117- timestamp=timestamp)120+ timestamp=timestamp,
121+ train_performance=train_performance)
118 else:122 else:
119 _non_dist_train(123 _non_dist_train(
120 model,124 model,
@@ -122,7 +126,8 @@ def train_detector(model,
122 cfg,126 cfg,
123 validate=validate,127 validate=validate,
124 logger=logger,128 logger=logger,
125- timestamp=timestamp)129+ timestamp=timestamp,
130+ train_performance=train_performance)
126 131 
127 132 
128def build_optimizer(model, optimizer_cfg):133def build_optimizer(model, optimizer_cfg):
@@ -210,7 +215,8 @@ def _dist_train(model,
210 cfg,215 cfg,
211 validate=False,216 validate=False,
212 logger=None,217 logger=None,
213- timestamp=None):218+ timestamp=None,
219+ train_performance=False):
214 # prepare data loaders220 # prepare data loaders
215 dataset = dataset if isinstance(dataset, (list, tuple)) else [dataset]221 dataset = dataset if isinstance(dataset, (list, tuple)) else [dataset]
216 data_loaders = [222 data_loaders = [
@@ -237,7 +243,8 @@ def _dist_train(model,
237 # )243 # )
238 # build runner244 # build runner
239 runner = Runner(245 runner = Runner(
240- model, batch_processor, optimizer, cfg.work_dir, logger=logger, samples_per_gpu=cfg.data.imgs_per_gpu, num_of_gpus = cfg.gpus)246+ model, batch_processor, optimizer, cfg.work_dir, logger=logger, samples_per_gpu=cfg.data.imgs_per_gpu,
247+ num_of_gpus=cfg.gpus)
241 # an ugly walkaround to make the .log and .log.json filenames the same248 # an ugly walkaround to make the .log and .log.json filenames the same
242 runner.timestamp = timestamp249 runner.timestamp = timestamp
243 250 
@@ -284,6 +291,7 @@ def _dist_train(model,
284 runner.resume(cfg.resume_from)291 runner.resume(cfg.resume_from)
285 elif cfg.load_from:292 elif cfg.load_from:
286 runner.load_checkpoint(cfg.load_from)293 runner.load_checkpoint(cfg.load_from)
294+ runner.train_performance = train_performance
287 runner.run(data_loaders, cfg.workflow, cfg.total_epochs)295 runner.run(data_loaders, cfg.workflow, cfg.total_epochs)
288 296 
289 297 
@@ -292,7 +300,8 @@ def _non_dist_train(model,
292 cfg,300 cfg,
293 validate=False,301 validate=False,
294 logger=None,302 logger=None,
295- timestamp=None):303+ timestamp=None,
304+ train_performance=False):
296 if validate:305 if validate:
297 raise NotImplementedError('Built-in validation is not implemented '306 raise NotImplementedError('Built-in validation is not implemented '
298 'yet in not-distributed training. Use '307 'yet in not-distributed training. Use '
@@ -318,9 +327,10 @@ def _non_dist_train(model,
318 model = MMDataParallel(model.npu(), device_ids=range(cfg.gpus))327 model = MMDataParallel(model.npu(), device_ids=range(cfg.gpus))
319 328 
320 # build runner329 # build runner
321- #optimizer = build_optimizer(model, cfg.optimizer)330+ # optimizer = build_optimizer(model, cfg.optimizer)
322 runner = Runner(331 runner = Runner(
323- model, batch_processor, optimizer, cfg.work_dir, logger=logger, samples_per_gpu=cfg.data.imgs_per_gpu, num_of_gpus = cfg.gpus)332+ model, batch_processor, optimizer, cfg.work_dir, logger=logger, samples_per_gpu=cfg.data.imgs_per_gpu,
333+ num_of_gpus=cfg.gpus)
324 # an ugly walkaround to make the .log and .log.json filenames the same334 # an ugly walkaround to make the .log and .log.json filenames the same
325 runner.timestamp = timestamp335 runner.timestamp = timestamp
326 # fp16 setting336 # fp16 setting
@@ -337,4 +347,5 @@ def _non_dist_train(model,
337 runner.resume(cfg.resume_from)347 runner.resume(cfg.resume_from)
338 elif cfg.load_from:348 elif cfg.load_from:
339 runner.load_checkpoint(cfg.load_from)349 runner.load_checkpoint(cfg.load_from)
340- runner.run(data_loaders, cfg.workflow, cfg.total_epochs)350+ runner.train_performance = train_performance
351+ runner.run(data_loaders, cfg.workflow, cfg.total_epochs)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/anchor/anchor_generator.py+2-2
@@ -107,6 +107,6 @@ class AnchorGenerator(object):
107 valid_xx, valid_yy = self._meshgrid(valid_x, valid_y)107 valid_xx, valid_yy = self._meshgrid(valid_x, valid_y)
108 valid = valid_xx & valid_yy108 valid = valid_xx & valid_yy
109 valid = valid[:,109 valid = valid[:,
110- None].expand(valid.size(0),110+ None].expand(valid.size(0),
111- self.num_base_anchors).contiguous().view(-1)111+ self.num_base_anchors).contiguous().view(-1)
112 return valid112 return valid
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/anchor/anchor_target.py+20-20
@@ -62,19 +62,19 @@ def anchor_target(anchor_list,
62 gt_labels_list = [None for _ in range(num_imgs)]62 gt_labels_list = [None for _ in range(num_imgs)]
63 (all_labels, all_label_weights, all_bbox_targets, all_bbox_weights,63 (all_labels, all_label_weights, all_bbox_targets, all_bbox_weights,
64 pos_inds_list, neg_inds_list) = multi_apply(64 pos_inds_list, neg_inds_list) = multi_apply(
65- anchor_target_single,65+ anchor_target_single,
66- anchor_list,66+ anchor_list,
67- valid_flag_list,67+ valid_flag_list,
68- gt_bboxes_list,68+ gt_bboxes_list,
69- gt_bboxes_ignore_list,69+ gt_bboxes_ignore_list,
70- gt_labels_list,70+ gt_labels_list,
71- img_metas,71+ img_metas,
72- target_means=target_means,72+ target_means=target_means,
73- target_stds=target_stds,73+ target_stds=target_stds,
74- cfg=cfg,74+ cfg=cfg,
75- label_channels=label_channels,75+ label_channels=label_channels,
76- sampling=sampling,76+ sampling=sampling,
77- unmap_outputs=unmap_outputs)77+ unmap_outputs=unmap_outputs)
78 # no valid anchors78 # no valid anchors
79 if any([labels is None for labels in all_labels]):79 if any([labels is None for labels in all_labels]):
80 return None80 return None
@@ -121,7 +121,7 @@ def anchor_target_single(flat_anchors,
121 img_meta['img_shape'][:2],121 img_meta['img_shape'][:2],
122 cfg.allowed_border)122 cfg.allowed_border)
123 if not inside_flags.any():123 if not inside_flags.any():
124- return (None, ) * 6124+ return (None,) * 6
125 # assign gt and sample anchors125 # assign gt and sample anchors
126 anchors = flat_anchors[inside_flags, :]126 anchors = flat_anchors[inside_flags, :]
127 127 
@@ -180,10 +180,10 @@ def anchor_inside_flags(flat_anchors,
180 img_h, img_w = img_shape[:2]180 img_h, img_w = img_shape[:2]
181 if allowed_border >= 0:181 if allowed_border >= 0:
182 inside_flags = valid_flags & \182 inside_flags = valid_flags & \
183- (flat_anchors[:, 0] >= -allowed_border).type(torch.uint8) & \183+ (flat_anchors[:, 0] >= -allowed_border).type(torch.uint8) & \
184- (flat_anchors[:, 1] >= -allowed_border).type(torch.uint8) & \184+ (flat_anchors[:, 1] >= -allowed_border).type(torch.uint8) & \
185- (flat_anchors[:, 2] < img_w + allowed_border).type(torch.uint8) & \185+ (flat_anchors[:, 2] < img_w + allowed_border).type(torch.uint8) & \
186- (flat_anchors[:, 3] < img_h + allowed_border).type(torch.uint8)186+ (flat_anchors[:, 3] < img_h + allowed_border).type(torch.uint8)
187 else:187 else:
188 inside_flags = valid_flags188 inside_flags = valid_flags
189 return inside_flags189 return inside_flags
@@ -193,10 +193,10 @@ def unmap(data, count, inds, fill=0):
193 """ Unmap a subset of item (data) back to the original set of items (of193 """ Unmap a subset of item (data) back to the original set of items (of
194 size count) """194 size count) """
195 if data.dim() == 1:195 if data.dim() == 1:
196- ret = data.new_full((count, ), fill)196+ ret = data.new_full((count,), fill)
197 ret[inds] = data197 ret[inds] = data
198 else:198 else:
199- new_size = (count, ) + data.size()[1:]199+ new_size = (count,) + data.size()[1:]
200 ret = data.new_full(new_size, fill)200 ret = data.new_full(new_size, fill)
201 ret[inds, :] = data201 ret[inds, :] = data
202 return ret202 return ret
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/anchor/guided_anchor_target.py+18-18
@@ -93,7 +93,7 @@ def ga_loc_target(gt_bboxes_list,
93 scale = torch.sqrt((gt_bboxes[:, 2] - gt_bboxes[:, 0] + 1) *93 scale = torch.sqrt((gt_bboxes[:, 2] - gt_bboxes[:, 0] + 1) *
94 (gt_bboxes[:, 3] - gt_bboxes[:, 1] + 1))94 (gt_bboxes[:, 3] - gt_bboxes[:, 1] + 1))
95 min_anchor_size = scale.new_full(95 min_anchor_size = scale.new_full(
96- (1, ), float(anchor_scale * anchor_strides[0]))96+ (1,), float(anchor_scale * anchor_strides[0]))
97 # assign gt bboxes to different feature levels w.r.t. their scales97 # assign gt bboxes to different feature levels w.r.t. their scales
98 target_lvls = torch.floor(98 target_lvls = torch.floor(
99 torch.log2(scale) - torch.log2(min_anchor_size) + 0.5)99 torch.log2(scale) - torch.log2(min_anchor_size) + 0.5)
@@ -109,11 +109,11 @@ def ga_loc_target(gt_bboxes_list,
109 ctr_x1, ctr_y1, ctr_x2, ctr_y2 = calc_region(109 ctr_x1, ctr_y1, ctr_x2, ctr_y2 = calc_region(
110 gt_, r1, featmap_sizes[lvl])110 gt_, r1, featmap_sizes[lvl])
111 all_loc_targets[lvl][img_id, 0, ctr_y1:ctr_y2 + 1,111 all_loc_targets[lvl][img_id, 0, ctr_y1:ctr_y2 + 1,
112- ctr_x1:ctr_x2 + 1] = 1112+ ctr_x1:ctr_x2 + 1] = 1
113 all_loc_weights[lvl][img_id, 0, ignore_y1:ignore_y2 + 1,113 all_loc_weights[lvl][img_id, 0, ignore_y1:ignore_y2 + 1,
114- ignore_x1:ignore_x2 + 1] = 0114+ ignore_x1:ignore_x2 + 1] = 0
115 all_loc_weights[lvl][img_id, 0, ctr_y1:ctr_y2 + 1,115 all_loc_weights[lvl][img_id, 0, ctr_y1:ctr_y2 + 1,
116- ctr_x1:ctr_x2 + 1] = 1116+ ctr_x1:ctr_x2 + 1] = 1
117 # calculate ignore map on nearby low level feature117 # calculate ignore map on nearby low level feature
118 if lvl > 0:118 if lvl > 0:
119 d_lvl = lvl - 1119 d_lvl = lvl - 1
@@ -122,7 +122,7 @@ def ga_loc_target(gt_bboxes_list,
122 ignore_x1, ignore_y1, ignore_x2, ignore_y2 = calc_region(122 ignore_x1, ignore_y1, ignore_x2, ignore_y2 = calc_region(
123 gt_, r2, featmap_sizes[d_lvl])123 gt_, r2, featmap_sizes[d_lvl])
124 all_ignore_map[d_lvl][img_id, 0, ignore_y1:ignore_y2 + 1,124 all_ignore_map[d_lvl][img_id, 0, ignore_y1:ignore_y2 + 1,
125- ignore_x1:ignore_x2 + 1] = 1125+ ignore_x1:ignore_x2 + 1] = 1
126 # calculate ignore map on nearby high level feature126 # calculate ignore map on nearby high level feature
127 if lvl < num_lvls - 1:127 if lvl < num_lvls - 1:
128 u_lvl = lvl + 1128 u_lvl = lvl + 1
@@ -131,7 +131,7 @@ def ga_loc_target(gt_bboxes_list,
131 ignore_x1, ignore_y1, ignore_x2, ignore_y2 = calc_region(131 ignore_x1, ignore_y1, ignore_x2, ignore_y2 = calc_region(
132 gt_, r2, featmap_sizes[u_lvl])132 gt_, r2, featmap_sizes[u_lvl])
133 all_ignore_map[u_lvl][img_id, 0, ignore_y1:ignore_y2 + 1,133 all_ignore_map[u_lvl][img_id, 0, ignore_y1:ignore_y2 + 1,
134- ignore_x1:ignore_x2 + 1] = 1134+ ignore_x1:ignore_x2 + 1] = 1
135 for lvl_id in range(num_lvls):135 for lvl_id in range(num_lvls):
136 # ignore negative regions w.r.t. ignore map136 # ignore negative regions w.r.t. ignore map
137 all_loc_weights[lvl_id][(all_loc_weights[lvl_id] < 0)137 all_loc_weights[lvl_id][(all_loc_weights[lvl_id] < 0)
@@ -191,17 +191,17 @@ def ga_shape_target(approx_list,
191 gt_bboxes_ignore_list = [None for _ in range(num_imgs)]191 gt_bboxes_ignore_list = [None for _ in range(num_imgs)]
192 (all_bbox_anchors, all_bbox_gts, all_bbox_weights, pos_inds_list,192 (all_bbox_anchors, all_bbox_gts, all_bbox_weights, pos_inds_list,
193 neg_inds_list) = multi_apply(193 neg_inds_list) = multi_apply(
194- ga_shape_target_single,194+ ga_shape_target_single,
195- approx_flat_list,195+ approx_flat_list,
196- inside_flag_flat_list,196+ inside_flag_flat_list,
197- square_flat_list,197+ square_flat_list,
198- gt_bboxes_list,198+ gt_bboxes_list,
199- gt_bboxes_ignore_list,199+ gt_bboxes_ignore_list,
200- img_metas,200+ img_metas,
201- approxs_per_octave=approxs_per_octave,201+ approxs_per_octave=approxs_per_octave,
202- cfg=cfg,202+ cfg=cfg,
203- sampling=sampling,203+ sampling=sampling,
204- unmap_outputs=unmap_outputs)204+ unmap_outputs=unmap_outputs)
205 # no valid anchors205 # no valid anchors
206 if any([bbox_anchors is None for bbox_anchors in all_bbox_anchors]):206 if any([bbox_anchors is None for bbox_anchors in all_bbox_anchors]):
207 return None207 return None
@@ -264,7 +264,7 @@ def ga_shape_target_single(flat_approxs,
264 tuple264 tuple
265 """265 """
266 if not inside_flags.any():266 if not inside_flags.any():
267- return (None, ) * 5267+ return (None,) * 5
268 # assign gt and sample anchors268 # assign gt and sample anchors
269 expand_inside_flags = inside_flags[:, None].expand(269 expand_inside_flags = inside_flags[:, None].expand(
270 -1, approxs_per_octave).reshape(-1)270 -1, approxs_per_octave).reshape(-1)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/anchor/point_generator.py+1-1
@@ -30,7 +30,7 @@ class PointGenerator(object):
30 shift_x = torch.arange(0., feat_w, device=device) * stride30 shift_x = torch.arange(0., feat_w, device=device) * stride
31 shift_y = torch.arange(0., feat_h, device=device) * stride31 shift_y = torch.arange(0., feat_h, device=device) * stride
32 shift_xx, shift_yy = self._meshgrid(shift_x, shift_y)32 shift_xx, shift_yy = self._meshgrid(shift_x, shift_y)
33- stride = shift_x.new_full((shift_xx.shape[0], ), stride)33+ stride = shift_x.new_full((shift_xx.shape[0],), stride)
34 shifts = torch.stack([shift_xx, shift_yy, stride], dim=-1)34 shifts = torch.stack([shift_xx, shift_yy, stride], dim=-1)
35 all_points = shifts.to(device)35 all_points = shifts.to(device)
36 return all_points36 return all_points
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/anchor/point_target.py+13-13
@@ -59,16 +59,16 @@ def point_target(proposals_list,
59 gt_labels_list = [None for _ in range(num_imgs)]59 gt_labels_list = [None for _ in range(num_imgs)]
60 (all_labels, all_label_weights, all_bbox_gt, all_proposals,60 (all_labels, all_label_weights, all_bbox_gt, all_proposals,
61 all_proposal_weights, pos_inds_list, neg_inds_list) = multi_apply(61 all_proposal_weights, pos_inds_list, neg_inds_list) = multi_apply(
62- point_target_single,62+ point_target_single,
63- proposals_list,63+ proposals_list,
64- valid_flag_list,64+ valid_flag_list,
65- gt_bboxes_list,65+ gt_bboxes_list,
66- gt_bboxes_ignore_list,66+ gt_bboxes_ignore_list,
67- gt_labels_list,67+ gt_labels_list,
68- cfg=cfg,68+ cfg=cfg,
69- label_channels=label_channels,69+ label_channels=label_channels,
70- sampling=sampling,70+ sampling=sampling,
71- unmap_outputs=unmap_outputs)71+ unmap_outputs=unmap_outputs)
72 # no valid points72 # no valid points
73 if any([labels is None for labels in all_labels]):73 if any([labels is None for labels in all_labels]):
74 return None74 return None
@@ -112,7 +112,7 @@ def point_target_single(flat_proposals,
112 unmap_outputs=True):112 unmap_outputs=True):
113 inside_flags = valid_flags113 inside_flags = valid_flags
114 if not inside_flags.any():114 if not inside_flags.any():
115- return (None, ) * 7115+ return (None,) * 7
116 # assign gt and sample proposals116 # assign gt and sample proposals
117 proposals = flat_proposals[inside_flags, :]117 proposals = flat_proposals[inside_flags, :]
118 118 
@@ -170,10 +170,10 @@ def unmap(data, count, inds, fill=0):
170 """ Unmap a subset of item (data) back to the original set of items (of170 """ Unmap a subset of item (data) back to the original set of items (of
171 size count) """171 size count) """
172 if data.dim() == 1:172 if data.dim() == 1:
173- ret = data.new_full((count, ), fill)173+ ret = data.new_full((count,), fill)
174 ret[inds] = data174 ret[inds] = data
175 else:175 else:
176- new_size = (count, ) + data.size()[1:]176+ new_size = (count,) + data.size()[1:]
177 ret = data.new_full(new_size, fill)177 ret = data.new_full(new_size, fill)
178 ret[inds, :] = data178 ret[inds, :] = data
179 return ret179 return ret
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/bbox/assigners/approx_max_iou_assigner.py+1-1
@@ -114,7 +114,7 @@ class ApproxMaxIoUAssigner(MaxIoUAssigner):
114 approxs.view(num_squares, approxs_per_octave, 4), 0,114 approxs.view(num_squares, approxs_per_octave, 4), 0,
115 1).contiguous().view(-1, 4)115 1).contiguous().view(-1, 4)
116 assign_on_cpu = True if (self.gpu_assign_thr > 0) and (116 assign_on_cpu = True if (self.gpu_assign_thr > 0) and (
117- num_gts > self.gpu_assign_thr) else False117+ num_gts > self.gpu_assign_thr) else False
118 # compute overlap and assign gt on CPU when number of GT is large118 # compute overlap and assign gt on CPU when number of GT is large
119 if assign_on_cpu:119 if assign_on_cpu:
120 device = approxs.device120 device = approxs.device
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/bbox/assigners/atss_assigner.py+4-4
@@ -78,20 +78,20 @@ class ATSSAssigner(BaseAssigner):
78 overlaps = bbox_overlaps(bboxes, gt_bboxes)78 overlaps = bbox_overlaps(bboxes, gt_bboxes)
79 79 
80 # assign 0 by default80 # assign 0 by default
81- assigned_gt_inds = overlaps.new_full((num_bboxes, ),81+ assigned_gt_inds = overlaps.new_full((num_bboxes,),
82 0,82 0,
83 dtype=torch.long)83 dtype=torch.long)
84 84 
85 if num_gt == 0 or num_bboxes == 0:85 if num_gt == 0 or num_bboxes == 0:
86 # No ground truth or boxes, return empty assignment86 # No ground truth or boxes, return empty assignment
87- max_overlaps = overlaps.new_zeros((num_bboxes, ))87+ max_overlaps = overlaps.new_zeros((num_bboxes,))
88 if num_gt == 0:88 if num_gt == 0:
89 # No truth, assign everything to background89 # No truth, assign everything to background
90 assigned_gt_inds[:] = 090 assigned_gt_inds[:] = 0
91 if gt_labels is None:91 if gt_labels is None:
92 assigned_labels = None92 assigned_labels = None
93 else:93 else:
94- assigned_labels = overlaps.new_zeros((num_bboxes, ),94+ assigned_labels = overlaps.new_zeros((num_bboxes,),
95 dtype=torch.long)95 dtype=torch.long)
96 return AssignResult(96 return AssignResult(
97 num_gt, assigned_gt_inds, max_overlaps, labels=assigned_labels)97 num_gt, assigned_gt_inds, max_overlaps, labels=assigned_labels)
@@ -162,7 +162,7 @@ class ATSSAssigner(BaseAssigner):
162 max_overlaps != -INF] = argmax_overlaps[max_overlaps != -INF] + 1162 max_overlaps != -INF] = argmax_overlaps[max_overlaps != -INF] + 1
163 163 
164 if gt_labels is not None:164 if gt_labels is not None:
165- assigned_labels = assigned_gt_inds.new_zeros((num_bboxes, ))165+ assigned_labels = assigned_gt_inds.new_zeros((num_bboxes,))
166 pos_inds = torch.nonzero(assigned_gt_inds > 0).squeeze()166 pos_inds = torch.nonzero(assigned_gt_inds > 0).squeeze()
167 if pos_inds.numel() > 0:167 if pos_inds.numel() > 0:
168 assigned_labels[pos_inds] = gt_labels[168 assigned_labels[pos_inds] = gt_labels[
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/bbox/assigners/max_iou_assigner.py+5-5
@@ -98,7 +98,7 @@ class MaxIoUAssigner(BaseAssigner):
98 >>> assert torch.all(assign_result.gt_inds == expected_gt_inds)98 >>> assert torch.all(assign_result.gt_inds == expected_gt_inds)
99 """99 """
100 assign_on_cpu = True if (self.gpu_assign_thr > 0) and (100 assign_on_cpu = True if (self.gpu_assign_thr > 0) and (
101- gt_bboxes.shape[0] > self.gpu_assign_thr) else False101+ gt_bboxes.shape[0] > self.gpu_assign_thr) else False
102 # compute overlap and assign gt on CPU when number of GT is large102 # compute overlap and assign gt on CPU when number of GT is large
103 if assign_on_cpu:103 if assign_on_cpu:
104 device = bboxes.device104 device = bboxes.device
@@ -146,20 +146,20 @@ class MaxIoUAssigner(BaseAssigner):
146 num_gts, num_bboxes = overlaps.size(0), overlaps.size(1)146 num_gts, num_bboxes = overlaps.size(0), overlaps.size(1)
147 147 
148 # 1. assign -1 by default148 # 1. assign -1 by default
149- assigned_gt_inds = overlaps.new_full((num_bboxes, ),149+ assigned_gt_inds = overlaps.new_full((num_bboxes,),
150 -1,150 -1,
151 dtype=torch.long)151 dtype=torch.long)
152 152 
153 if num_gts == 0 or num_bboxes == 0:153 if num_gts == 0 or num_bboxes == 0:
154 # No ground truth or boxes, return empty assignment154 # No ground truth or boxes, return empty assignment
155- max_overlaps = overlaps.new_zeros((num_bboxes, ))155+ max_overlaps = overlaps.new_zeros((num_bboxes,))
156 if num_gts == 0:156 if num_gts == 0:
157 # No truth, assign everything to background157 # No truth, assign everything to background
158 assigned_gt_inds[:] = 0158 assigned_gt_inds[:] = 0
159 if gt_labels is None:159 if gt_labels is None:
160 assigned_labels = None160 assigned_labels = None
161 else:161 else:
162- assigned_labels = overlaps.new_zeros((num_bboxes, ),162+ assigned_labels = overlaps.new_zeros((num_bboxes,),
163 dtype=torch.long)163 dtype=torch.long)
164 return AssignResult(164 return AssignResult(
165 num_gts,165 num_gts,
@@ -197,7 +197,7 @@ class MaxIoUAssigner(BaseAssigner):
197 assigned_gt_inds[gt_argmax_overlaps[i]] = i + 1197 assigned_gt_inds[gt_argmax_overlaps[i]] = i + 1
198 198 
199 if gt_labels is not None:199 if gt_labels is not None:
200- assigned_labels = assigned_gt_inds.new_zeros((num_bboxes, ))200+ assigned_labels = assigned_gt_inds.new_zeros((num_bboxes,))
201 pos_inds = torch.nonzero(assigned_gt_inds > 0).squeeze()201 pos_inds = torch.nonzero(assigned_gt_inds > 0).squeeze()
202 if pos_inds.numel() > 0:202 if pos_inds.numel() > 0:
203 assigned_labels[pos_inds] = gt_labels[203 assigned_labels[pos_inds] = gt_labels[
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/bbox/assigners/point_assigner.py+5-5
@@ -65,13 +65,13 @@ class PointAssigner(BaseAssigner):
65 65 
66 if num_gts == 0 or num_points == 0:66 if num_gts == 0 or num_points == 0:
67 # If no truth assign everything to the background67 # If no truth assign everything to the background
68- assigned_gt_inds = points.new_full((num_points, ),68+ assigned_gt_inds = points.new_full((num_points,),
69 0,69 0,
70 dtype=torch.long)70 dtype=torch.long)
71 if gt_labels is None:71 if gt_labels is None:
72 assigned_labels = None72 assigned_labels = None
73 else:73 else:
74- assigned_labels = points.new_zeros((num_points, ),74+ assigned_labels = points.new_zeros((num_points,),
75 dtype=torch.long)75 dtype=torch.long)
76 return AssignResult(76 return AssignResult(
77 num_gts, assigned_gt_inds, None, labels=assigned_labels)77 num_gts, assigned_gt_inds, None, labels=assigned_labels)
@@ -91,9 +91,9 @@ class PointAssigner(BaseAssigner):
91 gt_bboxes_lvl = torch.clamp(gt_bboxes_lvl, min=lvl_min, max=lvl_max)91 gt_bboxes_lvl = torch.clamp(gt_bboxes_lvl, min=lvl_min, max=lvl_max)
92 92 
93 # stores the assigned gt index of each point93 # stores the assigned gt index of each point
94- assigned_gt_inds = points.new_zeros((num_points, ), dtype=torch.long)94+ assigned_gt_inds = points.new_zeros((num_points,), dtype=torch.long)
95 # stores the assigned gt dist (to this point) of each point95 # stores the assigned gt dist (to this point) of each point
96- assigned_gt_dist = points.new_full((num_points, ), float('inf'))96+ assigned_gt_dist = points.new_full((num_points,), float('inf'))
97 points_range = torch.arange(points.shape[0])97 points_range = torch.arange(points.shape[0])
98 98 
99 for idx in range(num_gts):99 for idx in range(num_gts):
@@ -132,7 +132,7 @@ class PointAssigner(BaseAssigner):
132 less_than_recorded_index]132 less_than_recorded_index]
133 133 
134 if gt_labels is not None:134 if gt_labels is not None:
135- assigned_labels = assigned_gt_inds.new_zeros((num_points, ))135+ assigned_labels = assigned_gt_inds.new_zeros((num_points,))
136 pos_inds = torch.nonzero(assigned_gt_inds > 0).squeeze()136 pos_inds = torch.nonzero(assigned_gt_inds > 0).squeeze()
137 if pos_inds.numel() > 0:137 if pos_inds.numel() > 0:
138 assigned_labels[pos_inds] = gt_labels[138 assigned_labels[pos_inds] = gt_labels[
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/bbox/geometry.py+4-4
@@ -75,11 +75,11 @@ def bbox_overlaps(bboxes1, bboxes2, mode='iou', is_aligned=False):
75 wh = (rb - lt + 1).clamp(min=0) # [rows, 2]75 wh = (rb - lt + 1).clamp(min=0) # [rows, 2]
76 overlap = wh[:, 0] * wh[:, 1]76 overlap = wh[:, 0] * wh[:, 1]
77 area1 = (bboxes1[:, 2] - bboxes1[:, 0] + 1) * (77 area1 = (bboxes1[:, 2] - bboxes1[:, 0] + 1) * (
78- bboxes1[:, 3] - bboxes1[:, 1] + 1)78+ bboxes1[:, 3] - bboxes1[:, 1] + 1)
79 79 
80 if mode == 'iou':80 if mode == 'iou':
81 area2 = (bboxes2[:, 2] - bboxes2[:, 0] + 1) * (81 area2 = (bboxes2[:, 2] - bboxes2[:, 0] + 1) * (
82- bboxes2[:, 3] - bboxes2[:, 1] + 1)82+ bboxes2[:, 3] - bboxes2[:, 1] + 1)
83 ious = overlap / (area1 + area2 - overlap)83 ious = overlap / (area1 + area2 - overlap)
84 else:84 else:
85 ious = overlap / area185 ious = overlap / area1
@@ -90,11 +90,11 @@ def bbox_overlaps(bboxes1, bboxes2, mode='iou', is_aligned=False):
90 wh = (rb - lt + 1).clamp(min=0) # [rows, cols, 2]90 wh = (rb - lt + 1).clamp(min=0) # [rows, cols, 2]
91 overlap = wh[:, :, 0] * wh[:, :, 1]91 overlap = wh[:, :, 0] * wh[:, :, 1]
92 area1 = (bboxes1[:, 2] - bboxes1[:, 0] + 1) * (92 area1 = (bboxes1[:, 2] - bboxes1[:, 0] + 1) * (
93- bboxes1[:, 3] - bboxes1[:, 1] + 1)93+ bboxes1[:, 3] - bboxes1[:, 1] + 1)
94 94 
95 if mode == 'iou':95 if mode == 'iou':
96 area2 = (bboxes2[:, 2] - bboxes2[:, 0] + 1) * (96 area2 = (bboxes2[:, 2] - bboxes2[:, 0] + 1) * (
97- bboxes2[:, 3] - bboxes2[:, 1] + 1)97+ bboxes2[:, 3] - bboxes2[:, 1] + 1)
98 ious = overlap / (area1[:, None] + area2 - overlap)98 ious = overlap / (area1[:, None] + area2 - overlap)
99 else:99 else:
100 ious = overlap / (area1[:, None])100 ious = overlap / (area1[:, None])
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/bbox/samplers/base_sampler.py+1-1
@@ -80,7 +80,7 @@ class BaseSampler(metaclass=ABCMeta):
80 80 
81 bboxes = bboxes[:, :4]81 bboxes = bboxes[:, :4]
82 82 
83- gt_flags = bboxes.new_zeros((bboxes.shape[0], ), dtype=torch.uint8)83+ gt_flags = bboxes.new_zeros((bboxes.shape[0],), dtype=torch.uint8)
84 if self.add_gt_as_proposals and len(gt_bboxes) > 0:84 if self.add_gt_as_proposals and len(gt_bboxes) > 0:
85 if gt_labels is None:85 if gt_labels is None:
86 raise ValueError(86 raise ValueError(
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/evaluation/bbox_overlaps.py+2-2
@@ -43,9 +43,9 @@ def bbox_overlaps(bboxes1, bboxes2, mode='iou'):
43 ious = np.zeros((cols, rows), dtype=np.float32)43 ious = np.zeros((cols, rows), dtype=np.float32)
44 exchange = True44 exchange = True
45 area1 = (bboxes1[:, 2] - bboxes1[:, 0] + 1) * (45 area1 = (bboxes1[:, 2] - bboxes1[:, 0] + 1) * (
46- bboxes1[:, 3] - bboxes1[:, 1] + 1)46+ bboxes1[:, 3] - bboxes1[:, 1] + 1)
47 area2 = (bboxes2[:, 2] - bboxes2[:, 0] + 1) * (47 area2 = (bboxes2[:, 2] - bboxes2[:, 0] + 1) * (
48- bboxes2[:, 3] - bboxes2[:, 1] + 1)48+ bboxes2[:, 3] - bboxes2[:, 1] + 1)
49 for i in range(bboxes1.shape[0]):49 for i in range(bboxes1.shape[0]):
50 x_start = np.maximum(bboxes1[i, 0], bboxes2[:, 0])50 x_start = np.maximum(bboxes1[i, 0], bboxes2[:, 0])
51 y_start = np.maximum(bboxes1[i, 1], bboxes2[:, 1])51 y_start = np.maximum(bboxes1[i, 1], bboxes2[:, 1])
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/evaluation/coco_utils.py+1-1
@@ -105,7 +105,7 @@ def fast_eval_recall(results,
105 elif not isinstance(results, list):105 elif not isinstance(results, list):
106 raise TypeError(106 raise TypeError(
107 'results must be a list of numpy arrays or a filename, not {}'.107 'results must be a list of numpy arrays or a filename, not {}'.
108- format(type(results)))108+ format(type(results)))
109 109 
110 gt_bboxes = []110 gt_bboxes = []
111 img_ids = coco.getImgIds()111 img_ids = coco.getImgIds()
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/evaluation/mean_ap.py+5-5
@@ -113,7 +113,7 @@ def tpfp_imagenet(det_bboxes,
113 fp[...] = 1113 fp[...] = 1
114 else:114 else:
115 det_areas = (det_bboxes[:, 2] - det_bboxes[:, 0] + 1) * (115 det_areas = (det_bboxes[:, 2] - det_bboxes[:, 0] + 1) * (
116- det_bboxes[:, 3] - det_bboxes[:, 1] + 1)116+ det_bboxes[:, 3] - det_bboxes[:, 1] + 1)
117 for i, (min_area, max_area) in enumerate(area_ranges):117 for i, (min_area, max_area) in enumerate(area_ranges):
118 fp[i, (det_areas >= min_area) & (det_areas < max_area)] = 1118 fp[i, (det_areas >= min_area) & (det_areas < max_area)] = 1
119 return tp, fp119 return tp, fp
@@ -209,7 +209,7 @@ def tpfp_default(det_bboxes,
209 fp[...] = 1209 fp[...] = 1
210 else:210 else:
211 det_areas = (det_bboxes[:, 2] - det_bboxes[:, 0] + 1) * (211 det_areas = (det_bboxes[:, 2] - det_bboxes[:, 0] + 1) * (
212- det_bboxes[:, 3] - det_bboxes[:, 1] + 1)212+ det_bboxes[:, 3] - det_bboxes[:, 1] + 1)
213 for i, (min_area, max_area) in enumerate(area_ranges):213 for i, (min_area, max_area) in enumerate(area_ranges):
214 fp[i, (det_areas >= min_area) & (det_areas < max_area)] = 1214 fp[i, (det_areas >= min_area) & (det_areas < max_area)] = 1
215 return tp, fp215 return tp, fp
@@ -228,7 +228,7 @@ def tpfp_default(det_bboxes,
228 gt_area_ignore = np.zeros_like(gt_ignore_inds, dtype=bool)228 gt_area_ignore = np.zeros_like(gt_ignore_inds, dtype=bool)
229 else:229 else:
230 gt_areas = (gt_bboxes[:, 2] - gt_bboxes[:, 0] + 1) * (230 gt_areas = (gt_bboxes[:, 2] - gt_bboxes[:, 0] + 1) * (
231- gt_bboxes[:, 3] - gt_bboxes[:, 1] + 1)231+ gt_bboxes[:, 3] - gt_bboxes[:, 1] + 1)
232 gt_area_ignore = (gt_areas < min_area) | (gt_areas >= max_area)232 gt_area_ignore = (gt_areas < min_area) | (gt_areas >= max_area)
233 for i in sort_inds:233 for i in sort_inds:
234 if ious_max[i] >= iou_thr:234 if ious_max[i] >= iou_thr:
@@ -318,7 +318,7 @@ def eval_map(det_results,
318 num_imgs = len(det_results)318 num_imgs = len(det_results)
319 num_scales = len(scale_ranges) if scale_ranges is not None else 1319 num_scales = len(scale_ranges) if scale_ranges is not None else 1
320 num_classes = len(det_results[0]) # positive class num320 num_classes = len(det_results[0]) # positive class num
321- area_ranges = ([(rg[0]**2, rg[1]**2) for rg in scale_ranges]321+ area_ranges = ([(rg[0] ** 2, rg[1] ** 2) for rg in scale_ranges]
322 if scale_ranges is not None else None)322 if scale_ranges is not None else None)
323 323 
324 pool = Pool(nproc)324 pool = Pool(nproc)
@@ -347,7 +347,7 @@ def eval_map(det_results,
347 num_gts[0] += bbox.shape[0]347 num_gts[0] += bbox.shape[0]
348 else:348 else:
349 gt_areas = (bbox[:, 2] - bbox[:, 0] + 1) * (349 gt_areas = (bbox[:, 2] - bbox[:, 0] + 1) * (
350- bbox[:, 3] - bbox[:, 1] + 1)350+ bbox[:, 3] - bbox[:, 1] + 1)
351 for k, (min_area, max_area) in enumerate(area_ranges):351 for k, (min_area, max_area) in enumerate(area_ranges):
352 num_gts[k] += np.sum((gt_areas >= min_area)352 num_gts[k] += np.sum((gt_areas >= min_area)
353 & (gt_areas < max_area))353 & (gt_areas < max_area))
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/evaluation/recall.py+0-1
@@ -19,7 +19,6 @@ from .bbox_overlaps import bbox_overlaps
19 19 
20 20 
21def _recalls(all_ious, proposal_nums, thrs):21def _recalls(all_ious, proposal_nums, thrs):
22- 
23 img_num = all_ious.shape[0]22 img_num = all_ious.shape[0]
24 total_gt_num = sum([ious.shape[0] for ious in all_ious])23 total_gt_num = sum([ious.shape[0] for ious in all_ious])
25 24 
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/mask/mask_target.py+1-1
@@ -51,5 +51,5 @@ def mask_target_single(pos_proposals, pos_assigned_gt_inds, gt_masks, cfg):
51 mask_targets = torch.from_numpy(np.stack(mask_targets)).float().to(51 mask_targets = torch.from_numpy(np.stack(mask_targets)).float().to(
52 pos_proposals.device)52 pos_proposals.device)
53 else:53 else:
54- mask_targets = pos_proposals.new_zeros((0, ) + mask_size)54+ mask_targets = pos_proposals.new_zeros((0,) + mask_size)
55 return mask_targets55 return mask_targets
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/post_processing/bbox_nms.py+3-2
@@ -14,6 +14,7 @@
14 14 
15import torch15import torch
16 16 
17+ 
17# from mmdet.ops.nms import nms_wrapper18# from mmdet.ops.nms import nms_wrapper
18 19 
19 20 
@@ -60,7 +61,7 @@ def multiclass_nms(multi_bboxes,
60 _scores *= score_factors[cls_inds]61 _scores *= score_factors[cls_inds]
61 cls_dets = torch.cat([_bboxes, _scores[:, None]], dim=1)62 cls_dets = torch.cat([_bboxes, _scores[:, None]], dim=1)
62 cls_dets, _ = nms_op(cls_dets, **nms_cfg_)63 cls_dets, _ = nms_op(cls_dets, **nms_cfg_)
63- cls_labels = multi_bboxes.new_full((cls_dets.shape[0], ),64+ cls_labels = multi_bboxes.new_full((cls_dets.shape[0],),
64 i - 1,65 i - 1,
65 dtype=torch.long)66 dtype=torch.long)
66 bboxes.append(cls_dets)67 bboxes.append(cls_dets)
@@ -75,6 +76,6 @@ def multiclass_nms(multi_bboxes,
75 labels = labels[inds]76 labels = labels[inds]
76 else:77 else:
77 bboxes = multi_bboxes.new_zeros((0, 5))78 bboxes = multi_bboxes.new_zeros((0, 5))
78- labels = multi_bboxes.new_zeros((0, ), dtype=torch.long)79+ labels = multi_bboxes.new_zeros((0,), dtype=torch.long)
79 80 
80 return bboxes, labels81 return bboxes, labels
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/post_processing/matrix_nms.py+3-3
@@ -58,7 +58,7 @@ def matrix_nms(seg_masks, cate_labels, cate_scores, kernel='gaussian', sigma=2.0
58 compensate_matrix = torch.exp(-1 * sigma * (compensate_iou ** 2))58 compensate_matrix = torch.exp(-1 * sigma * (compensate_iou ** 2))
59 decay_coefficient, _ = (decay_matrix / compensate_matrix).min(0)59 decay_coefficient, _ = (decay_matrix / compensate_matrix).min(0)
60 elif kernel == 'linear':60 elif kernel == 'linear':
61- decay_matrix = (1-decay_iou)/(1-compensate_iou)61+ decay_matrix = (1 - decay_iou) / (1 - compensate_iou)
62 decay_coefficient, _ = decay_matrix.min(0)62 decay_coefficient, _ = decay_matrix.min(0)
63 else:63 else:
64 raise NotImplementedError64 raise NotImplementedError
@@ -111,7 +111,7 @@ def multiclass_nms(multi_bboxes,
111 _scores *= score_factors[cls_inds]111 _scores *= score_factors[cls_inds]
112 cls_dets = torch.cat([_bboxes, _scores[:, None]], dim=1)112 cls_dets = torch.cat([_bboxes, _scores[:, None]], dim=1)
113 cls_dets, _ = nms_op(cls_dets, **nms_cfg_)113 cls_dets, _ = nms_op(cls_dets, **nms_cfg_)
114- cls_labels = multi_bboxes.new_full((cls_dets.shape[0], ),114+ cls_labels = multi_bboxes.new_full((cls_dets.shape[0],),
115 i - 1,115 i - 1,
116 dtype=torch.long)116 dtype=torch.long)
117 bboxes.append(cls_dets)117 bboxes.append(cls_dets)
@@ -126,6 +126,6 @@ def multiclass_nms(multi_bboxes,
126 labels = labels[inds]126 labels = labels[inds]
127 else:127 else:
128 bboxes = multi_bboxes.new_zeros((0, 5))128 bboxes = multi_bboxes.new_zeros((0, 5))
129- labels = multi_bboxes.new_zeros((0, ), dtype=torch.long)129+ labels = multi_bboxes.new_zeros((0,), dtype=torch.long)
130 130 
131 return bboxes, labels131 return bboxes, labels
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/core/utils/misc.py+2-2
@@ -42,10 +42,10 @@ def unmap(data, count, inds, fill=0):
42 """ Unmap a subset of item (data) back to the original set of items (of42 """ Unmap a subset of item (data) back to the original set of items (of
43 size count) """43 size count) """
44 if data.dim() == 1:44 if data.dim() == 1:
45- ret = data.new_full((count, ), fill)45+ ret = data.new_full((count,), fill)
46 ret[inds] = data46 ret[inds] = data
47 else:47 else:
48- new_size = (count, ) + data.size()[1:]48+ new_size = (count,) + data.size()[1:]
49 ret = data.new_full(new_size, fill)49 ret = data.new_full(new_size, fill)
50 ret[inds, :] = data50 ret[inds, :] = data
51 return ret51 return ret
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/datasets/cityscapes.py+0-1
@@ -18,6 +18,5 @@ from .registry import DATASETS
18 18 
19@DATASETS.register_module19@DATASETS.register_module
20class CityscapesDataset(CocoDataset):20class CityscapesDataset(CocoDataset):
21- 
22 CLASSES = ('person', 'rider', 'car', 'truck', 'bus', 'train', 'motorcycle',21 CLASSES = ('person', 'rider', 'car', 'truck', 'bus', 'train', 'motorcycle',
23 'bicycle')22 'bicycle')
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/datasets/coco.py+0-1
@@ -21,7 +21,6 @@ from .registry import DATASETS
21 21 
22@DATASETS.register_module22@DATASETS.register_module
23class CocoDataset(CustomDataset):23class CocoDataset(CustomDataset):
24- 
25 CLASSES = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',24 CLASSES = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',
26 'train', 'truck', 'boat', 'traffic_light', 'fire_hydrant',25 'train', 'truck', 'boat', 'traffic_light', 'fire_hydrant',
27 'stop_sign', 'parking_meter', 'bench', 'bird', 'cat', 'dog',26 'stop_sign', 'parking_meter', 'bench', 'bird', 'cat', 'dog',
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/datasets/loader/build_loader.py+1-0
@@ -24,6 +24,7 @@ from .sampler import DistributedGroupSampler, DistributedSampler, GroupSampler
24if platform.system() != 'Windows':24if platform.system() != 'Windows':
25 # https://github.com/pytorch/pytorch/issues/97325 # https://github.com/pytorch/pytorch/issues/973
26 import resource26 import resource
27+ 
27 rlimit = resource.getrlimit(resource.RLIMIT_NOFILE)28 rlimit = resource.getrlimit(resource.RLIMIT_NOFILE)
28 resource.setrlimit(resource.RLIMIT_NOFILE, (4096, rlimit[1]))29 resource.setrlimit(resource.RLIMIT_NOFILE, (4096, rlimit[1]))
29 30 
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/datasets/pipelines/transforms.py+8-8
@@ -317,7 +317,7 @@ class Pad(object):
317 if padded_masks:317 if padded_masks:
318 results[key] = np.stack(padded_masks, axis=0)318 results[key] = np.stack(padded_masks, axis=0)
319 else:319 else:
320- results[key] = np.empty((0, ) + pad_shape, dtype=np.uint8)320+ results[key] = np.empty((0,) + pad_shape, dtype=np.uint8)
321 321 
322 def _pad_seg(self, results):322 def _pad_seg(self, results):
323 for key in results.get('seg_fields', []):323 for key in results.get('seg_fields', []):
@@ -409,7 +409,7 @@ class RandomCrop(object):
409 if 'gt_bboxes' in results:409 if 'gt_bboxes' in results:
410 gt_bboxes = results['gt_bboxes']410 gt_bboxes = results['gt_bboxes']
411 valid_inds = (gt_bboxes[:, 2] > gt_bboxes[:, 0]) & (411 valid_inds = (gt_bboxes[:, 2] > gt_bboxes[:, 0]) & (
412- gt_bboxes[:, 3] > gt_bboxes[:, 1])412+ gt_bboxes[:, 3] > gt_bboxes[:, 1])
413 # if no gt bbox remains after cropping, just skip this image413 # if no gt bbox remains after cropping, just skip this image
414 if not np.any(valid_inds):414 if not np.any(valid_inds):
415 return None415 return None
@@ -422,7 +422,7 @@ class RandomCrop(object):
422 valid_gt_masks = []422 valid_gt_masks = []
423 for i in np.where(valid_inds)[0]:423 for i in np.where(valid_inds)[0]:
424 gt_mask = results['gt_masks'][i][crop_y1:crop_y2,424 gt_mask = results['gt_masks'][i][crop_y1:crop_y2,
425- crop_x1:crop_x2]425+ crop_x1:crop_x2]
426 valid_gt_masks.append(gt_mask)426 valid_gt_masks.append(gt_mask)
427 results['gt_masks'] = np.stack(valid_gt_masks)427 results['gt_masks'] = np.stack(valid_gt_masks)
428 428 
@@ -540,8 +540,8 @@ class PhotoMetricDistortion(object):
540 repr_str = self.__class__.__name__540 repr_str = self.__class__.__name__
541 repr_str += ('(brightness_delta={}, contrast_range={}, '541 repr_str += ('(brightness_delta={}, contrast_range={}, '
542 'saturation_range={}, hue_delta={})').format(542 'saturation_range={}, hue_delta={})').format(
543- self.brightness_delta, self.contrast_range,543+ self.brightness_delta, self.contrast_range,
544- self.saturation_range, self.hue_delta)544+ self.saturation_range, self.hue_delta)
545 return repr_str545 return repr_str
546 546 
547 547 
@@ -616,8 +616,8 @@ class Expand(object):
616 repr_str = self.__class__.__name__616 repr_str = self.__class__.__name__
617 repr_str += '(mean={}, to_rgb={}, ratio_range={}, ' \617 repr_str += '(mean={}, to_rgb={}, ratio_range={}, ' \
618 'seg_ignore_label={})'.format(618 'seg_ignore_label={})'.format(
619- self.mean, self.to_rgb, self.ratio_range,619+ self.mean, self.to_rgb, self.ratio_range,
620- self.seg_ignore_label)620+ self.seg_ignore_label)
621 return repr_str621 return repr_str
622 622 
623 623 
@@ -700,7 +700,7 @@ class MinIoURandomCrop(object):
700 # not tested700 # not tested
701 if 'gt_semantic_seg' in results:701 if 'gt_semantic_seg' in results:
702 results['gt_semantic_seg'] = results['gt_semantic_seg'][702 results['gt_semantic_seg'] = results['gt_semantic_seg'][
703- patch[1]:patch[3], patch[0]:patch[2]]703+ patch[1]:patch[3], patch[0]:patch[2]]
704 return results704 return results
705 705 
706 def __repr__(self):706 def __repr__(self):
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/datasets/voc.py+0-1
@@ -18,7 +18,6 @@ from .xml_style import XMLDataset
18 18 
19@DATASETS.register_module19@DATASETS.register_module
20class VOCDataset(XMLDataset):20class VOCDataset(XMLDataset):
21- 
22 CLASSES = ('aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car',21 CLASSES = ('aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car',
23 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse',22 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse',
24 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train',23 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train',
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/datasets/wider_face.py+1-1
@@ -28,7 +28,7 @@ class WIDERFaceDataset(XMLDataset):
28 Conversion scripts can be found in28 Conversion scripts can be found in
29 https://github.com/sovrasov/wider-face-pascal-voc-annotations29 https://github.com/sovrasov/wider-face-pascal-voc-annotations
30 """30 """
31- CLASSES = ('face', )31+ CLASSES = ('face',)
32 32 
33 def __init__(self, **kwargs):33 def __init__(self, **kwargs):
34 super(WIDERFaceDataset, self).__init__(**kwargs)34 super(WIDERFaceDataset, self).__init__(**kwargs)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/datasets/xml_style.py+2-2
@@ -82,13 +82,13 @@ class XMLDataset(CustomDataset):
82 labels.append(label)82 labels.append(label)
83 if not bboxes:83 if not bboxes:
84 bboxes = np.zeros((0, 4))84 bboxes = np.zeros((0, 4))
85- labels = np.zeros((0, ))85+ labels = np.zeros((0,))
86 else:86 else:
87 bboxes = np.array(bboxes, ndmin=2) - 187 bboxes = np.array(bboxes, ndmin=2) - 1
88 labels = np.array(labels)88 labels = np.array(labels)
89 if not bboxes_ignore:89 if not bboxes_ignore:
90 bboxes_ignore = np.zeros((0, 4))90 bboxes_ignore = np.zeros((0, 4))
91- labels_ignore = np.zeros((0, ))91+ labels_ignore = np.zeros((0,))
92 else:92 else:
93 bboxes_ignore = np.array(bboxes_ignore, ndmin=2) - 193 bboxes_ignore = np.array(bboxes_ignore, ndmin=2) - 1
94 labels_ignore = np.array(labels_ignore)94 labels_ignore = np.array(labels_ignore)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/__init__.py+1-0
@@ -23,6 +23,7 @@ from .mask_heads import * # noqa: F401,F403
23from .necks import * # noqa: F401,F40323from .necks import * # noqa: F401,F403
24from .registry import (BACKBONES, DETECTORS, HEADS, LOSSES, NECKS,24from .registry import (BACKBONES, DETECTORS, HEADS, LOSSES, NECKS,
25 ROI_EXTRACTORS, SHARED_HEADS)25 ROI_EXTRACTORS, SHARED_HEADS)
26+ 
26# from .roi_extractors import * # noqa: F401,F40327# from .roi_extractors import * # noqa: F401,F403
27# from .shared_heads import * # noqa: F401,F40328# from .shared_heads import * # noqa: F401,F403
28 29 
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/__init__.py+1-0
@@ -27,6 +27,7 @@
27# from .ssd_head import SSDHead27# from .ssd_head import SSDHead
28from .solo_head import SOLOHead28from .solo_head import SOLOHead
29from .solov2_head import SOLOv2Head29from .solov2_head import SOLOv2Head
30+ 
30# from .solov2_light_head import SOLOv2LightHead31# from .solov2_light_head import SOLOv2LightHead
31# from .decoupled_solo_head import DecoupledSOLOHead32# from .decoupled_solo_head import DecoupledSOLOHead
32# from .decoupled_solo_light_head import DecoupledSOLOLightHead33# from .decoupled_solo_light_head import DecoupledSOLOLightHead
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/atss_head.py+25-25
@@ -67,7 +67,7 @@ class ATSSHead(AnchorHead):
67 self.norm_cfg = norm_cfg67 self.norm_cfg = norm_cfg
68 68 
69 octave_scales = np.array(69 octave_scales = np.array(
70- [2**(i / scales_per_octave) for i in range(scales_per_octave)])70+ [2 ** (i / scales_per_octave) for i in range(scales_per_octave)])
71 anchor_scales = octave_scales * octave_base_scale71 anchor_scales = octave_scales * octave_base_scale
72 super(ATSSHead, self).__init__(72 super(ATSSHead, self).__init__(
73 num_classes, in_channels, anchor_scales=anchor_scales, **kwargs)73 num_classes, in_channels, anchor_scales=anchor_scales, **kwargs)
@@ -226,18 +226,18 @@ class ATSSHead(AnchorHead):
226 torch.tensor(num_total_pos).cuda()).item()226 torch.tensor(num_total_pos).cuda()).item()
227 num_total_samples = max(num_total_samples, 1.0)227 num_total_samples = max(num_total_samples, 1.0)
228 228 
229- losses_cls, losses_bbox, loss_centerness,\229+ losses_cls, losses_bbox, loss_centerness, \
230- bbox_avg_factor = multi_apply(230+ bbox_avg_factor = multi_apply(
231- self.loss_single,231+ self.loss_single,
232- anchor_list,232+ anchor_list,
233- cls_scores,233+ cls_scores,
234- bbox_preds,234+ bbox_preds,
235- centernesses,235+ centernesses,
236- labels_list,236+ labels_list,
237- label_weights_list,237+ label_weights_list,
238- bbox_targets_list,238+ bbox_targets_list,
239- num_total_samples=num_total_samples,239+ num_total_samples=num_total_samples,
240- cfg=cfg)240+ cfg=cfg)
241 241 
242 bbox_avg_factor = sum(bbox_avg_factor)242 bbox_avg_factor = sum(bbox_avg_factor)
243 bbox_avg_factor = reduce_mean(bbox_avg_factor).item()243 bbox_avg_factor = reduce_mean(bbox_avg_factor).item()
@@ -394,17 +394,17 @@ class ATSSHead(AnchorHead):
394 gt_labels_list = [None for _ in range(num_imgs)]394 gt_labels_list = [None for _ in range(num_imgs)]
395 (all_anchors, all_labels, all_label_weights, all_bbox_targets,395 (all_anchors, all_labels, all_label_weights, all_bbox_targets,
396 all_bbox_weights, pos_inds_list, neg_inds_list) = multi_apply(396 all_bbox_weights, pos_inds_list, neg_inds_list) = multi_apply(
397- self.atss_target_single,397+ self.atss_target_single,
398- anchor_list,398+ anchor_list,
399- valid_flag_list,399+ valid_flag_list,
400- num_level_anchors_list,400+ num_level_anchors_list,
401- gt_bboxes_list,401+ gt_bboxes_list,
402- gt_bboxes_ignore_list,402+ gt_bboxes_ignore_list,
403- gt_labels_list,403+ gt_labels_list,
404- img_metas,404+ img_metas,
405- cfg=cfg,405+ cfg=cfg,
406- label_channels=label_channels,406+ label_channels=label_channels,
407- unmap_outputs=unmap_outputs)407+ unmap_outputs=unmap_outputs)
408 # no valid anchors408 # no valid anchors
409 if any([labels is None for labels in all_labels]):409 if any([labels is None for labels in all_labels]):
410 return None410 return None
@@ -439,7 +439,7 @@ class ATSSHead(AnchorHead):
439 img_meta['img_shape'][:2],439 img_meta['img_shape'][:2],
440 cfg.allowed_border)440 cfg.allowed_border)
441 if not inside_flags.any():441 if not inside_flags.any():
442- return (None, ) * 6442+ return (None,) * 6
443 # assign gt and sample anchors443 # assign gt and sample anchors
444 anchors = flat_anchors[inside_flags, :]444 anchors = flat_anchors[inside_flags, :]
445 445 
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/decoupled_solo_head.py+41-35
@@ -25,6 +25,7 @@ from ..utils import bias_init_with_prob, ConvModule
25 25 
26INF = 1e826INF = 1e8
27 27 
28+ 
28def center_of_mass(bitmasks):29def center_of_mass(bitmasks):
29 _, h, w = bitmasks.size()30 _, h, w = bitmasks.size()
30 ys = torch.arange(0, h, dtype=torch.float32, device=bitmasks.device)31 ys = torch.arange(0, h, dtype=torch.float32, device=bitmasks.device)
@@ -37,6 +38,7 @@ def center_of_mass(bitmasks):
37 center_y = m01 / m0038 center_y = m01 / m00
38 return center_x, center_y39 return center_x, center_y
39 40 
41+ 
40def points_nms(heat, kernel=2):42def points_nms(heat, kernel=2):
41 # kernel must be 243 # kernel must be 2
42 hmax = nn.functional.max_pool2d(44 hmax = nn.functional.max_pool2d(
@@ -44,6 +46,7 @@ def points_nms(heat, kernel=2):
44 keep = (hmax[:, :, :-1, :-1] == heat).float()46 keep = (hmax[:, :, :-1, :-1] == heat).float()
45 return heat * keep47 return heat * keep
46 48 
49+ 
47def dice_loss(input, target):50def dice_loss(input, target):
48 input = input.contiguous().view(input.size()[0], -1)51 input = input.contiguous().view(input.size()[0], -1)
49 target = target.contiguous().view(target.size()[0], -1).float()52 target = target.contiguous().view(target.size()[0], -1).float()
@@ -52,7 +55,8 @@ def dice_loss(input, target):
52 b = torch.sum(input * input, 1) + 0.00155 b = torch.sum(input * input, 1) + 0.001
53 c = torch.sum(target * target, 1) + 0.00156 c = torch.sum(target * target, 1) + 0.001
54 d = (2 * a) / (b + c)57 d = (2 * a) / (b + c)
55- return 1-d58+ return 1 - d
59+ 
56 60 
57@HEADS.register_module61@HEADS.register_module
58class DecoupledSOLOHead(nn.Module):62class DecoupledSOLOHead(nn.Module):
@@ -166,10 +170,10 @@ class DecoupledSOLOHead(nn.Module):
166 return ins_pred_x, ins_pred_y, cate_pred170 return ins_pred_x, ins_pred_y, cate_pred
167 171 
168 def split_feats(self, feats):172 def split_feats(self, feats):
169- return (F.interpolate(feats[0], scale_factor=0.5, mode='bilinear'), 173+ return (F.interpolate(feats[0], scale_factor=0.5, mode='bilinear'),
170- feats[1], 174+ feats[1],
171- feats[2], 175+ feats[2],
172- feats[3], 176+ feats[3],
173 F.interpolate(feats[4], size=feats[3].shape[-2:], mode='bilinear'))177 F.interpolate(feats[4], size=feats[3].shape[-2:], mode='bilinear'))
174 178 
175 def forward_single(self, x, idx, eval=False, upsampled_size=None):179 def forward_single(self, x, idx, eval=False, upsampled_size=None):
@@ -198,7 +202,7 @@ class DecoupledSOLOHead(nn.Module):
198 # cate branch202 # cate branch
199 for i, cate_layer in enumerate(self.cate_convs):203 for i, cate_layer in enumerate(self.cate_convs):
200 if i == self.cate_down_pos:204 if i == self.cate_down_pos:
201- seg_num_grid = self.seg_num_grids[idx] 205+ seg_num_grid = self.seg_num_grids[idx]
202 cate_feat = F.interpolate(cate_feat, size=seg_num_grid, mode='bilinear')206 cate_feat = F.interpolate(cate_feat, size=seg_num_grid, mode='bilinear')
203 cate_feat = cate_layer(cate_feat)207 cate_feat = cate_layer(cate_feat)
204 208 
@@ -236,16 +240,16 @@ class DecoupledSOLOHead(nn.Module):
236 for ins_labels_level, ins_ind_labels_level in zip(zip(*ins_label_list), zip(*ins_ind_label_list))]240 for ins_labels_level, ins_ind_labels_level in zip(zip(*ins_label_list), zip(*ins_ind_label_list))]
237 241 
238 ins_preds_x_final = [torch.cat([ins_preds_level_img_x[ins_ind_labels_level_img[:, 1], ...]242 ins_preds_x_final = [torch.cat([ins_preds_level_img_x[ins_ind_labels_level_img[:, 1], ...]
239- for ins_preds_level_img_x, ins_ind_labels_level_img in243+ for ins_preds_level_img_x, ins_ind_labels_level_img in
240- zip(ins_preds_level_x, ins_ind_labels_level)], 0)244+ zip(ins_preds_level_x, ins_ind_labels_level)], 0)
241- for ins_preds_level_x, ins_ind_labels_level in245+ for ins_preds_level_x, ins_ind_labels_level in
242- zip(ins_preds_x, zip(*ins_ind_label_list_xy))]246+ zip(ins_preds_x, zip(*ins_ind_label_list_xy))]
243 247 
244 ins_preds_y_final = [torch.cat([ins_preds_level_img_y[ins_ind_labels_level_img[:, 0], ...]248 ins_preds_y_final = [torch.cat([ins_preds_level_img_y[ins_ind_labels_level_img[:, 0], ...]
245- for ins_preds_level_img_y, ins_ind_labels_level_img in249+ for ins_preds_level_img_y, ins_ind_labels_level_img in
246- zip(ins_preds_level_y, ins_ind_labels_level)], 0)250+ zip(ins_preds_level_y, ins_ind_labels_level)], 0)
247- for ins_preds_level_y, ins_ind_labels_level in251+ for ins_preds_level_y, ins_ind_labels_level in
248- zip(ins_preds_y, zip(*ins_ind_label_list_xy))]252+ zip(ins_preds_y, zip(*ins_ind_label_list_xy))]
249 253 
250 num_ins = 0.254 num_ins = 0.
251 # dice loss255 # dice loss
@@ -255,7 +259,7 @@ class DecoupledSOLOHead(nn.Module):
255 if mask_n == 0:259 if mask_n == 0:
256 continue260 continue
257 num_ins += mask_n261 num_ins += mask_n
258- input = (input_x.sigmoid())*(input_y.sigmoid())262+ input = (input_x.sigmoid()) * (input_y.sigmoid())
259 loss_ins.append(dice_loss(input, target))263 loss_ins.append(dice_loss(input, target))
260 264 
261 loss_ins = torch.cat(loss_ins).mean() * self.ins_loss_weight265 loss_ins = torch.cat(loss_ins).mean() * self.ins_loss_weight
@@ -280,10 +284,10 @@ class DecoupledSOLOHead(nn.Module):
280 loss_cate=loss_cate)284 loss_cate=loss_cate)
281 285 
282 def solo_target_single(self,286 def solo_target_single(self,
283- gt_bboxes_raw,287+ gt_bboxes_raw,
284- gt_labels_raw,288+ gt_labels_raw,
285- gt_masks_raw,289+ gt_masks_raw,
286- featmap_sizes=None):290+ featmap_sizes=None):
287 291 
288 device = gt_labels_raw[0].device292 device = gt_labels_raw[0].device
289 # ins293 # ins
@@ -296,9 +300,9 @@ class DecoupledSOLOHead(nn.Module):
296 for (lower_bound, upper_bound), stride, featmap_size, num_grid \300 for (lower_bound, upper_bound), stride, featmap_size, num_grid \
297 in zip(self.scale_ranges, self.strides, featmap_sizes, self.seg_num_grids):301 in zip(self.scale_ranges, self.strides, featmap_sizes, self.seg_num_grids):
298 302 
299- ins_label = torch.zeros([num_grid**2, featmap_size[0], featmap_size[1]], dtype=torch.uint8, device=device)303+ ins_label = torch.zeros([num_grid ** 2, featmap_size[0], featmap_size[1]], dtype=torch.uint8, device=device)
300 cate_label = torch.zeros([num_grid, num_grid], dtype=torch.int64, device=device)304 cate_label = torch.zeros([num_grid, num_grid], dtype=torch.int64, device=device)
301- ins_ind_label = torch.zeros([num_grid**2], dtype=torch.bool, device=device)305+ ins_ind_label = torch.zeros([num_grid ** 2], dtype=torch.bool, device=device)
302 306 
303 hit_indices = ((gt_areas >= lower_bound) & (gt_areas <= upper_bound)).nonzero().flatten()307 hit_indices = ((gt_areas >= lower_bound) & (gt_areas <= upper_bound)).nonzero().flatten()
304 308 
@@ -324,9 +328,12 @@ class DecoupledSOLOHead(nn.Module):
324 valid_mask_flags = gt_masks_pt.sum(dim=-1).sum(dim=-1) > 0328 valid_mask_flags = gt_masks_pt.sum(dim=-1).sum(dim=-1) > 0
325 329 
326 output_stride = stride / 2330 output_stride = stride / 2
327- for seg_mask, gt_label, half_h, half_w, center_h, center_w, valid_mask_flag in zip(gt_masks, gt_labels, half_hs, half_ws, center_hs, center_ws, valid_mask_flags):331+ for seg_mask, gt_label, half_h, half_w, center_h, center_w, valid_mask_flag in zip(gt_masks, gt_labels,
332+ half_hs, half_ws,
333+ center_hs, center_ws,
334+ valid_mask_flags):
328 if not valid_mask_flag:335 if not valid_mask_flag:
329- continue336+ continue
330 upsampled_size = (featmap_sizes[0][0] * 4, featmap_sizes[0][1] * 4)337 upsampled_size = (featmap_sizes[0][0] * 4, featmap_sizes[0][1] * 4)
331 coord_w = int((center_w / upsampled_size[1]) // (1. / num_grid))338 coord_w = int((center_w / upsampled_size[1]) // (1. / num_grid))
332 coord_h = int((center_h / upsampled_size[0]) // (1. / num_grid))339 coord_h = int((center_h / upsampled_size[0]) // (1. / num_grid))
@@ -337,18 +344,18 @@ class DecoupledSOLOHead(nn.Module):
337 left_box = max(0, int(((center_w - half_w) / upsampled_size[1]) // (1. / num_grid)))344 left_box = max(0, int(((center_w - half_w) / upsampled_size[1]) // (1. / num_grid)))
338 right_box = min(num_grid - 1, int(((center_w + half_w) / upsampled_size[1]) // (1. / num_grid)))345 right_box = min(num_grid - 1, int(((center_w + half_w) / upsampled_size[1]) // (1. / num_grid)))
339 346 
340- top = max(top_box, coord_h-1)347+ top = max(top_box, coord_h - 1)
341- down = min(down_box, coord_h+1)348+ down = min(down_box, coord_h + 1)
342- left = max(coord_w-1, left_box)349+ left = max(coord_w - 1, left_box)
343- right = min(right_box, coord_w+1)350+ right = min(right_box, coord_w + 1)
344 351 
345 # squared352 # squared
346- cate_label[top:(down+1), left:(right+1)] = gt_label353+ cate_label[top:(down + 1), left:(right + 1)] = gt_label
347 # ins354 # ins
348 seg_mask = mmcv.imrescale(seg_mask, scale=1. / output_stride)355 seg_mask = mmcv.imrescale(seg_mask, scale=1. / output_stride)
349 seg_mask = torch.from_numpy(seg_mask).to(device=device)356 seg_mask = torch.from_numpy(seg_mask).to(device=device)
350- for i in range(top, down+1):357+ for i in range(top, down + 1):
351- for j in range(left, right+1):358+ for j in range(left, right + 1):
352 label = int(i * num_grid + j)359 label = int(i * num_grid + j)
353 ins_label[label, :seg_mask.shape[0], :seg_mask.shape[1]] = seg_mask360 ins_label[label, :seg_mask.shape[0], :seg_mask.shape[1]] = seg_mask
354 ins_ind_label[label] = True361 ins_ind_label[label] = True
@@ -404,7 +411,6 @@ class DecoupledSOLOHead(nn.Module):
404 cfg,411 cfg,
405 rescale=False, debug=False):412 rescale=False, debug=False):
406 413 
407- 
408 # overall info.414 # overall info.
409 h, w, _ = img_shape415 h, w, _ = img_shape
410 upsampled_size_out = (featmap_size[0] * 4, featmap_size[1] * 4)416 upsampled_size_out = (featmap_size[0] * 4, featmap_size[1] * 4)
@@ -489,10 +495,10 @@ class DecoupledSOLOHead(nn.Module):
489 cate_labels = cate_labels[sort_inds]495 cate_labels = cate_labels[sort_inds]
490 496 
491 seg_masks_soft = F.interpolate(seg_masks_soft.unsqueeze(0),497 seg_masks_soft = F.interpolate(seg_masks_soft.unsqueeze(0),
492- size=upsampled_size_out,498+ size=upsampled_size_out,
493- mode='bilinear')[:, :, :h, :w]499+ mode='bilinear')[:, :, :h, :w]
494 seg_masks = F.interpolate(seg_masks_soft,500 seg_masks = F.interpolate(seg_masks_soft,
495- size=ori_shape[:2],501+ size=ori_shape[:2],
496- mode='bilinear').squeeze(0)502+ mode='bilinear').squeeze(0)
497 seg_masks = seg_masks > cfg.mask_thr503 seg_masks = seg_masks > cfg.mask_thr
498 return seg_masks, cate_labels, cate_scores504 return seg_masks, cate_labels, cate_scores
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/decoupled_solo_light_head.py+41-35
@@ -25,6 +25,7 @@ from ..utils import bias_init_with_prob, ConvModule
25 25 
26INF = 1e826INF = 1e8
27 27 
28+ 
28def center_of_mass(bitmasks):29def center_of_mass(bitmasks):
29 _, h, w = bitmasks.size()30 _, h, w = bitmasks.size()
30 ys = torch.arange(0, h, dtype=torch.float32, device=bitmasks.device)31 ys = torch.arange(0, h, dtype=torch.float32, device=bitmasks.device)
@@ -37,6 +38,7 @@ def center_of_mass(bitmasks):
37 center_y = m01 / m0038 center_y = m01 / m00
38 return center_x, center_y39 return center_x, center_y
39 40 
41+ 
40def points_nms(heat, kernel=2):42def points_nms(heat, kernel=2):
41 # kernel must be 243 # kernel must be 2
42 hmax = nn.functional.max_pool2d(44 hmax = nn.functional.max_pool2d(
@@ -44,6 +46,7 @@ def points_nms(heat, kernel=2):
44 keep = (hmax[:, :, :-1, :-1] == heat).float()46 keep = (hmax[:, :, :-1, :-1] == heat).float()
45 return heat * keep47 return heat * keep
46 48 
49+ 
47def dice_loss(input, target):50def dice_loss(input, target):
48 input = input.contiguous().view(input.size()[0], -1)51 input = input.contiguous().view(input.size()[0], -1)
49 target = target.contiguous().view(target.size()[0], -1).float()52 target = target.contiguous().view(target.size()[0], -1).float()
@@ -52,7 +55,8 @@ def dice_loss(input, target):
52 b = torch.sum(input * input, 1) + 0.00155 b = torch.sum(input * input, 1) + 0.001
53 c = torch.sum(target * target, 1) + 0.00156 c = torch.sum(target * target, 1) + 0.001
54 d = (2 * a) / (b + c)57 d = (2 * a) / (b + c)
55- return 1-d58+ return 1 - d
59+ 
56 60 
57@HEADS.register_module61@HEADS.register_module
58class DecoupledSOLOLightHead(nn.Module):62class DecoupledSOLOLightHead(nn.Module):
@@ -163,10 +167,10 @@ class DecoupledSOLOLightHead(nn.Module):
163 return ins_pred_x, ins_pred_y, cate_pred167 return ins_pred_x, ins_pred_y, cate_pred
164 168 
165 def split_feats(self, feats):169 def split_feats(self, feats):
166- return (F.interpolate(feats[0], scale_factor=0.5, mode='bilinear'), 170+ return (F.interpolate(feats[0], scale_factor=0.5, mode='bilinear'),
167- feats[1], 171+ feats[1],
168- feats[2], 172+ feats[2],
169- feats[3], 173+ feats[3],
170 F.interpolate(feats[4], size=feats[3].shape[-2:], mode='bilinear'))174 F.interpolate(feats[4], size=feats[3].shape[-2:], mode='bilinear'))
171 175 
172 def forward_single(self, x, idx, eval=False, upsampled_size=None):176 def forward_single(self, x, idx, eval=False, upsampled_size=None):
@@ -193,7 +197,7 @@ class DecoupledSOLOLightHead(nn.Module):
193 # cate branch197 # cate branch
194 for i, cate_layer in enumerate(self.cate_convs):198 for i, cate_layer in enumerate(self.cate_convs):
195 if i == self.cate_down_pos:199 if i == self.cate_down_pos:
196- seg_num_grid = self.seg_num_grids[idx] 200+ seg_num_grid = self.seg_num_grids[idx]
197 cate_feat = F.interpolate(cate_feat, size=seg_num_grid, mode='bilinear')201 cate_feat = F.interpolate(cate_feat, size=seg_num_grid, mode='bilinear')
198 cate_feat = cate_layer(cate_feat)202 cate_feat = cate_layer(cate_feat)
199 203 
@@ -231,16 +235,16 @@ class DecoupledSOLOLightHead(nn.Module):
231 for ins_labels_level, ins_ind_labels_level in zip(zip(*ins_label_list), zip(*ins_ind_label_list))]235 for ins_labels_level, ins_ind_labels_level in zip(zip(*ins_label_list), zip(*ins_ind_label_list))]
232 236 
233 ins_preds_x_final = [torch.cat([ins_preds_level_img_x[ins_ind_labels_level_img[:, 1], ...]237 ins_preds_x_final = [torch.cat([ins_preds_level_img_x[ins_ind_labels_level_img[:, 1], ...]
234- for ins_preds_level_img_x, ins_ind_labels_level_img in238+ for ins_preds_level_img_x, ins_ind_labels_level_img in
235- zip(ins_preds_level_x, ins_ind_labels_level)], 0)239+ zip(ins_preds_level_x, ins_ind_labels_level)], 0)
236- for ins_preds_level_x, ins_ind_labels_level in240+ for ins_preds_level_x, ins_ind_labels_level in
237- zip(ins_preds_x, zip(*ins_ind_label_list_xy))]241+ zip(ins_preds_x, zip(*ins_ind_label_list_xy))]
238 242 
239 ins_preds_y_final = [torch.cat([ins_preds_level_img_y[ins_ind_labels_level_img[:, 0], ...]243 ins_preds_y_final = [torch.cat([ins_preds_level_img_y[ins_ind_labels_level_img[:, 0], ...]
240- for ins_preds_level_img_y, ins_ind_labels_level_img in244+ for ins_preds_level_img_y, ins_ind_labels_level_img in
241- zip(ins_preds_level_y, ins_ind_labels_level)], 0)245+ zip(ins_preds_level_y, ins_ind_labels_level)], 0)
242- for ins_preds_level_y, ins_ind_labels_level in246+ for ins_preds_level_y, ins_ind_labels_level in
243- zip(ins_preds_y, zip(*ins_ind_label_list_xy))]247+ zip(ins_preds_y, zip(*ins_ind_label_list_xy))]
244 248 
245 num_ins = 0.249 num_ins = 0.
246 # dice loss250 # dice loss
@@ -250,7 +254,7 @@ class DecoupledSOLOLightHead(nn.Module):
250 if mask_n == 0:254 if mask_n == 0:
251 continue255 continue
252 num_ins += mask_n256 num_ins += mask_n
253- input = (input_x.sigmoid())*(input_y.sigmoid())257+ input = (input_x.sigmoid()) * (input_y.sigmoid())
254 loss_ins.append(dice_loss(input, target))258 loss_ins.append(dice_loss(input, target))
255 259 
256 loss_ins = torch.cat(loss_ins).mean() * self.ins_loss_weight260 loss_ins = torch.cat(loss_ins).mean() * self.ins_loss_weight
@@ -275,10 +279,10 @@ class DecoupledSOLOLightHead(nn.Module):
275 loss_cate=loss_cate)279 loss_cate=loss_cate)
276 280 
277 def solo_target_single(self,281 def solo_target_single(self,
278- gt_bboxes_raw,282+ gt_bboxes_raw,
279- gt_labels_raw,283+ gt_labels_raw,
280- gt_masks_raw,284+ gt_masks_raw,
281- featmap_sizes=None):285+ featmap_sizes=None):
282 286 
283 device = gt_labels_raw[0].device287 device = gt_labels_raw[0].device
284 # ins288 # ins
@@ -291,9 +295,9 @@ class DecoupledSOLOLightHead(nn.Module):
291 for (lower_bound, upper_bound), stride, featmap_size, num_grid \295 for (lower_bound, upper_bound), stride, featmap_size, num_grid \
292 in zip(self.scale_ranges, self.strides, featmap_sizes, self.seg_num_grids):296 in zip(self.scale_ranges, self.strides, featmap_sizes, self.seg_num_grids):
293 297 
294- ins_label = torch.zeros([num_grid**2, featmap_size[0], featmap_size[1]], dtype=torch.uint8, device=device)298+ ins_label = torch.zeros([num_grid ** 2, featmap_size[0], featmap_size[1]], dtype=torch.uint8, device=device)
295 cate_label = torch.zeros([num_grid, num_grid], dtype=torch.int64, device=device)299 cate_label = torch.zeros([num_grid, num_grid], dtype=torch.int64, device=device)
296- ins_ind_label = torch.zeros([num_grid**2], dtype=torch.bool, device=device)300+ ins_ind_label = torch.zeros([num_grid ** 2], dtype=torch.bool, device=device)
297 301 
298 hit_indices = ((gt_areas >= lower_bound) & (gt_areas <= upper_bound)).nonzero().flatten()302 hit_indices = ((gt_areas >= lower_bound) & (gt_areas <= upper_bound)).nonzero().flatten()
299 303 
@@ -319,9 +323,12 @@ class DecoupledSOLOLightHead(nn.Module):
319 valid_mask_flags = gt_masks_pt.sum(dim=-1).sum(dim=-1) > 0323 valid_mask_flags = gt_masks_pt.sum(dim=-1).sum(dim=-1) > 0
320 324 
321 output_stride = stride / 2325 output_stride = stride / 2
322- for seg_mask, gt_label, half_h, half_w, center_h, center_w, valid_mask_flag in zip(gt_masks, gt_labels, half_hs, half_ws, center_hs, center_ws, valid_mask_flags):326+ for seg_mask, gt_label, half_h, half_w, center_h, center_w, valid_mask_flag in zip(gt_masks, gt_labels,
327+ half_hs, half_ws,
328+ center_hs, center_ws,
329+ valid_mask_flags):
323 if not valid_mask_flag:330 if not valid_mask_flag:
324- continue331+ continue
325 upsampled_size = (featmap_sizes[0][0] * 4, featmap_sizes[0][1] * 4)332 upsampled_size = (featmap_sizes[0][0] * 4, featmap_sizes[0][1] * 4)
326 coord_w = int((center_w / upsampled_size[1]) // (1. / num_grid))333 coord_w = int((center_w / upsampled_size[1]) // (1. / num_grid))
327 coord_h = int((center_h / upsampled_size[0]) // (1. / num_grid))334 coord_h = int((center_h / upsampled_size[0]) // (1. / num_grid))
@@ -332,18 +339,18 @@ class DecoupledSOLOLightHead(nn.Module):
332 left_box = max(0, int(((center_w - half_w) / upsampled_size[1]) // (1. / num_grid)))339 left_box = max(0, int(((center_w - half_w) / upsampled_size[1]) // (1. / num_grid)))
333 right_box = min(num_grid - 1, int(((center_w + half_w) / upsampled_size[1]) // (1. / num_grid)))340 right_box = min(num_grid - 1, int(((center_w + half_w) / upsampled_size[1]) // (1. / num_grid)))
334 341 
335- top = max(top_box, coord_h-1)342+ top = max(top_box, coord_h - 1)
336- down = min(down_box, coord_h+1)343+ down = min(down_box, coord_h + 1)
337- left = max(coord_w-1, left_box)344+ left = max(coord_w - 1, left_box)
338- right = min(right_box, coord_w+1)345+ right = min(right_box, coord_w + 1)
339 346 
340 # squared347 # squared
341- cate_label[top:(down+1), left:(right+1)] = gt_label348+ cate_label[top:(down + 1), left:(right + 1)] = gt_label
342 # ins349 # ins
343 seg_mask = mmcv.imrescale(seg_mask, scale=1. / output_stride)350 seg_mask = mmcv.imrescale(seg_mask, scale=1. / output_stride)
344 seg_mask = torch.from_numpy(seg_mask).to(device=device)351 seg_mask = torch.from_numpy(seg_mask).to(device=device)
345- for i in range(top, down+1):352+ for i in range(top, down + 1):
346- for j in range(left, right+1):353+ for j in range(left, right + 1):
347 label = int(i * num_grid + j)354 label = int(i * num_grid + j)
348 ins_label[label, :seg_mask.shape[0], :seg_mask.shape[1]] = seg_mask355 ins_label[label, :seg_mask.shape[0], :seg_mask.shape[1]] = seg_mask
349 ins_ind_label[label] = True356 ins_ind_label[label] = True
@@ -399,7 +406,6 @@ class DecoupledSOLOLightHead(nn.Module):
399 cfg,406 cfg,
400 rescale=False, debug=False):407 rescale=False, debug=False):
401 408 
402- 
403 # overall info.409 # overall info.
404 h, w, _ = img_shape410 h, w, _ = img_shape
405 upsampled_size_out = (featmap_size[0] * 4, featmap_size[1] * 4)411 upsampled_size_out = (featmap_size[0] * 4, featmap_size[1] * 4)
@@ -484,10 +490,10 @@ class DecoupledSOLOLightHead(nn.Module):
484 cate_labels = cate_labels[sort_inds]490 cate_labels = cate_labels[sort_inds]
485 491 
486 seg_masks_soft = F.interpolate(seg_masks_soft.unsqueeze(0),492 seg_masks_soft = F.interpolate(seg_masks_soft.unsqueeze(0),
487- size=upsampled_size_out,493+ size=upsampled_size_out,
488- mode='bilinear')[:, :, :h, :w]494+ mode='bilinear')[:, :, :h, :w]
489 seg_masks = F.interpolate(seg_masks_soft,495 seg_masks = F.interpolate(seg_masks_soft,
490- size=ori_shape[:2],496+ size=ori_shape[:2],
491- mode='bilinear').squeeze(0)497+ mode='bilinear').squeeze(0)
492 seg_masks = seg_masks > cfg.mask_thr498 seg_masks = seg_masks > cfg.mask_thr
493 return seg_masks, cate_labels, cate_scores499 return seg_masks, cate_labels, cate_scores
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/fcos_head.py+5-5
@@ -374,7 +374,7 @@ class FCOSHead(nn.Module):
374 gt_bboxes.new_zeros((num_points, 4))374 gt_bboxes.new_zeros((num_points, 4))
375 375 
376 areas = (gt_bboxes[:, 2] - gt_bboxes[:, 0] + 1) * (376 areas = (gt_bboxes[:, 2] - gt_bboxes[:, 0] + 1) * (
377- gt_bboxes[:, 3] - gt_bboxes[:, 1] + 1)377+ gt_bboxes[:, 3] - gt_bboxes[:, 1] + 1)
378 # TODO: figure out why these two are different378 # TODO: figure out why these two are different
379 # areas = areas[None].expand(num_points, num_gts)379 # areas = areas[None].expand(num_points, num_gts)
380 areas = areas[None].repeat(num_points, 1)380 areas = areas[None].repeat(num_points, 1)
@@ -397,8 +397,8 @@ class FCOSHead(nn.Module):
397 # condition2: limit the regression range for each location397 # condition2: limit the regression range for each location
398 max_regress_distance = bbox_targets.max(-1)[0]398 max_regress_distance = bbox_targets.max(-1)[0]
399 inside_regress_range = (399 inside_regress_range = (
400- max_regress_distance >= regress_ranges[..., 0]) & (400+ max_regress_distance >= regress_ranges[..., 0]) & (
401- max_regress_distance <= regress_ranges[..., 1])401+ max_regress_distance <= regress_ranges[..., 1])
402 402 
403 # if there are still more than one objects for a location,403 # if there are still more than one objects for a location,
404 # we choose the one with minimal area404 # we choose the one with minimal area
@@ -417,6 +417,6 @@ class FCOSHead(nn.Module):
417 left_right = pos_bbox_targets[:, [0, 2]]417 left_right = pos_bbox_targets[:, [0, 2]]
418 top_bottom = pos_bbox_targets[:, [1, 3]]418 top_bottom = pos_bbox_targets[:, [1, 3]]
419 centerness_targets = (419 centerness_targets = (
420- left_right.min(dim=-1)[0] / left_right.max(dim=-1)[0]) * (420+ left_right.min(dim=-1)[0] / left_right.max(dim=-1)[0]) * (
421- top_bottom.min(dim=-1)[0] / top_bottom.max(dim=-1)[0])421+ top_bottom.min(dim=-1)[0] / top_bottom.max(dim=-1)[0])
422 return torch.sqrt(centerness_targets)422 return torch.sqrt(centerness_targets)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/fovea_head.py+8-8
@@ -297,16 +297,16 @@ class FoveaHead(nn.Module):
297 half_h = 0.5 * (gt_bboxes[:, 3] - gt_bboxes[:, 1])297 half_h = 0.5 * (gt_bboxes[:, 3] - gt_bboxes[:, 1])
298 # valid fovea area: left, right, top, down298 # valid fovea area: left, right, top, down
299 pos_left = torch.ceil(299 pos_left = torch.ceil(
300- gt_bboxes[:, 0] + (1 - self.sigma) * half_w - 0.5).long().\300+ gt_bboxes[:, 0] + (1 - self.sigma) * half_w - 0.5).long(). \
301 clamp(0, featmap_size[1] - 1)301 clamp(0, featmap_size[1] - 1)
302 pos_right = torch.floor(302 pos_right = torch.floor(
303- gt_bboxes[:, 0] + (1 + self.sigma) * half_w - 0.5).long().\303+ gt_bboxes[:, 0] + (1 + self.sigma) * half_w - 0.5).long(). \
304 clamp(0, featmap_size[1] - 1)304 clamp(0, featmap_size[1] - 1)
305 pos_top = torch.ceil(305 pos_top = torch.ceil(
306- gt_bboxes[:, 1] + (1 - self.sigma) * half_h - 0.5).long().\306+ gt_bboxes[:, 1] + (1 - self.sigma) * half_h - 0.5).long(). \
307 clamp(0, featmap_size[0] - 1)307 clamp(0, featmap_size[0] - 1)
308 pos_down = torch.floor(308 pos_down = torch.floor(
309- gt_bboxes[:, 1] + (1 + self.sigma) * half_h - 0.5).long().\309+ gt_bboxes[:, 1] + (1 + self.sigma) * half_h - 0.5).long(). \
310 clamp(0, featmap_size[0] - 1)310 clamp(0, featmap_size[0] - 1)
311 for px1, py1, px2, py2, label, (gt_x1, gt_y1, gt_x2, gt_y2) in \311 for px1, py1, px2, py2, label, (gt_x1, gt_y1, gt_x2, gt_y2) in \
312 zip(pos_left, pos_top, pos_right, pos_down, gt_labels,312 zip(pos_left, pos_top, pos_right, pos_down, gt_labels,
@@ -378,13 +378,13 @@ class FoveaHead(nn.Module):
378 scores = scores[topk_inds, :]378 scores = scores[topk_inds, :]
379 y = y[topk_inds]379 y = y[topk_inds]
380 x = x[topk_inds]380 x = x[topk_inds]
381- x1 = (stride * x - base_len * bbox_pred[:, 0]).\381+ x1 = (stride * x - base_len * bbox_pred[:, 0]). \
382 clamp(min=0, max=img_shape[1] - 1)382 clamp(min=0, max=img_shape[1] - 1)
383- y1 = (stride * y - base_len * bbox_pred[:, 1]).\383+ y1 = (stride * y - base_len * bbox_pred[:, 1]). \
384 clamp(min=0, max=img_shape[0] - 1)384 clamp(min=0, max=img_shape[0] - 1)
385- x2 = (stride * x + base_len * bbox_pred[:, 2]).\385+ x2 = (stride * x + base_len * bbox_pred[:, 2]). \
386 clamp(min=0, max=img_shape[1] - 1)386 clamp(min=0, max=img_shape[1] - 1)
387- y2 = (stride * y + base_len * bbox_pred[:, 3]).\387+ y2 = (stride * y + base_len * bbox_pred[:, 3]). \
388 clamp(min=0, max=img_shape[0] - 1)388 clamp(min=0, max=img_shape[0] - 1)
389 bboxes = torch.stack([x1, y1, x2, y2], -1)389 bboxes = torch.stack([x1, y1, x2, y2], -1)
390 det_bboxes.append(bboxes)390 det_bboxes.append(bboxes)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/free_anchor_retina_head.py+2-2
@@ -79,7 +79,7 @@ class FreeAnchorRetinaHead(RetinaHead):
79 positive_losses = []79 positive_losses = []
80 for _, (anchors_, gt_labels_, gt_bboxes_, cls_prob_,80 for _, (anchors_, gt_labels_, gt_bboxes_, cls_prob_,
81 bbox_preds_) in enumerate(81 bbox_preds_) in enumerate(
82- zip(anchors, gt_labels, gt_bboxes, cls_prob, bbox_preds)):82+ zip(anchors, gt_labels, gt_bboxes, cls_prob, bbox_preds)):
83 gt_labels_ -= 183 gt_labels_ -= 1
84 84 
85 with torch.no_grad():85 with torch.no_grad():
@@ -197,6 +197,6 @@ class FreeAnchorRetinaHead(RetinaHead):
197 197 
198 def negative_bag_loss(self, cls_prob, box_prob):198 def negative_bag_loss(self, cls_prob, box_prob):
199 prob = cls_prob * (1 - box_prob)199 prob = cls_prob * (1 - box_prob)
200- negative_bag_loss = prob**self.gamma * F.binary_cross_entropy(200+ negative_bag_loss = prob ** self.gamma * F.binary_cross_entropy(
201 prob, torch.zeros_like(prob), reduction='none')201 prob, torch.zeros_like(prob), reduction='none')
202 return (1 - self.alpha) * negative_bag_loss202 return (1 - self.alpha) * negative_bag_loss
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/guided_anchor_head.py+29-29
@@ -108,32 +108,32 @@ class GuidedAnchorHead(AnchorHead):
108 """108 """
109 109 
110 def __init__(110 def __init__(
111- self,111+ self,
112- num_classes,112+ num_classes,
113- in_channels,113+ in_channels,
114- feat_channels=256,114+ feat_channels=256,
115- octave_base_scale=8,115+ octave_base_scale=8,
116- scales_per_octave=3,116+ scales_per_octave=3,
117- octave_ratios=[0.5, 1.0, 2.0],117+ octave_ratios=[0.5, 1.0, 2.0],
118- anchor_strides=[4, 8, 16, 32, 64],118+ anchor_strides=[4, 8, 16, 32, 64],
119- anchor_base_sizes=None,119+ anchor_base_sizes=None,
120- anchoring_means=(.0, .0, .0, .0),120+ anchoring_means=(.0, .0, .0, .0),
121- anchoring_stds=(1.0, 1.0, 1.0, 1.0),121+ anchoring_stds=(1.0, 1.0, 1.0, 1.0),
122- target_means=(.0, .0, .0, .0),122+ target_means=(.0, .0, .0, .0),
123- target_stds=(1.0, 1.0, 1.0, 1.0),123+ target_stds=(1.0, 1.0, 1.0, 1.0),
124- deformable_groups=4,124+ deformable_groups=4,
125- loc_filter_thr=0.01,125+ loc_filter_thr=0.01,
126- loss_loc=dict(126+ loss_loc=dict(
127- type='FocalLoss',127+ type='FocalLoss',
128- use_sigmoid=True,128+ use_sigmoid=True,
129- gamma=2.0,129+ gamma=2.0,
130- alpha=0.25,130+ alpha=0.25,
131- loss_weight=1.0),131+ loss_weight=1.0),
132- loss_shape=dict(type='BoundedIoULoss', beta=0.2, loss_weight=1.0),132+ loss_shape=dict(type='BoundedIoULoss', beta=0.2, loss_weight=1.0),
133- loss_cls=dict(133+ loss_cls=dict(
134- type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0),134+ type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0),
135- loss_bbox=dict(type='SmoothL1Loss', beta=1.0,135+ loss_bbox=dict(type='SmoothL1Loss', beta=1.0,
136- loss_weight=1.0)): # yapf: disable136+ loss_weight=1.0)): # yapf: disable
137 super(AnchorHead, self).__init__()137 super(AnchorHead, self).__init__()
138 self.in_channels = in_channels138 self.in_channels = in_channels
139 self.num_classes = num_classes139 self.num_classes = num_classes
@@ -141,7 +141,7 @@ class GuidedAnchorHead(AnchorHead):
141 self.octave_base_scale = octave_base_scale141 self.octave_base_scale = octave_base_scale
142 self.scales_per_octave = scales_per_octave142 self.scales_per_octave = scales_per_octave
143 self.octave_scales = octave_base_scale * np.array(143 self.octave_scales = octave_base_scale * np.array(
144- [2**(i / scales_per_octave) for i in range(scales_per_octave)])144+ [2 ** (i / scales_per_octave) for i in range(scales_per_octave)])
145 self.approxs_per_octave = len(self.octave_scales) * len(octave_ratios)145 self.approxs_per_octave = len(self.octave_scales) * len(octave_ratios)
146 self.octave_ratios = octave_ratios146 self.octave_ratios = octave_ratios
147 self.anchor_strides = anchor_strides147 self.anchor_strides = anchor_strides
@@ -277,7 +277,7 @@ class GuidedAnchorHead(AnchorHead):
277 # inside_flag for a position is true if any anchor in this277 # inside_flag for a position is true if any anchor in this
278 # position is true278 # position is true
279 inside_flags = (279 inside_flags = (
280- torch.stack(inside_flags_list, 0).sum(dim=0) > 0)280+ torch.stack(inside_flags_list, 0).sum(dim=0) > 0)
281 multi_level_flags.append(inside_flags)281 multi_level_flags.append(inside_flags)
282 inside_flag_list.append(multi_level_flags)282 inside_flag_list.append(multi_level_flags)
283 return approxs_list, inside_flag_list283 return approxs_list, inside_flag_list
@@ -483,7 +483,7 @@ class GuidedAnchorHead(AnchorHead):
483 num_total_pos, num_total_neg) = cls_reg_targets483 num_total_pos, num_total_neg) = cls_reg_targets
484 num_total_samples = (484 num_total_samples = (
485 num_total_pos if self.cls_focal_loss else num_total_pos +485 num_total_pos if self.cls_focal_loss else num_total_pos +
486- num_total_neg)486+ num_total_neg)
487 487 
488 # get classification and bbox regression losses488 # get classification and bbox regression losses
489 losses_cls, losses_bbox = multi_apply(489 losses_cls, losses_bbox = multi_apply(
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/reppoints_head.py+4-4
@@ -187,9 +187,9 @@ class RepPointsHead(nn.Module):
187 """187 """
188 pts_reshape = pts.view(pts.shape[0], -1, 2, *pts.shape[2:])188 pts_reshape = pts.view(pts.shape[0], -1, 2, *pts.shape[2:])
189 pts_y = pts_reshape[:, :, 0, ...] if y_first else pts_reshape[:, :, 1,189 pts_y = pts_reshape[:, :, 0, ...] if y_first else pts_reshape[:, :, 1,
190- ...]190+ ...]
191 pts_x = pts_reshape[:, :, 1, ...] if y_first else pts_reshape[:, :, 0,191 pts_x = pts_reshape[:, :, 1, ...] if y_first else pts_reshape[:, :, 0,
192- ...]192+ ...]
193 if self.transform_method == 'minmax':193 if self.transform_method == 'minmax':
194 bbox_left = pts_x.min(dim=1, keepdim=True)[0]194 bbox_left = pts_x.min(dim=1, keepdim=True)[0]
195 bbox_right = pts_x.max(dim=1, keepdim=True)[0]195 bbox_right = pts_x.max(dim=1, keepdim=True)[0]
@@ -212,7 +212,7 @@ class RepPointsHead(nn.Module):
212 pts_y_std = torch.std(pts_y - pts_y_mean, dim=1, keepdim=True)212 pts_y_std = torch.std(pts_y - pts_y_mean, dim=1, keepdim=True)
213 pts_x_std = torch.std(pts_x - pts_x_mean, dim=1, keepdim=True)213 pts_x_std = torch.std(pts_x - pts_x_mean, dim=1, keepdim=True)
214 moment_transfer = (self.moment_transfer * self.moment_mul) + (214 moment_transfer = (self.moment_transfer * self.moment_mul) + (
215- self.moment_transfer.detach() * (1 - self.moment_mul))215+ self.moment_transfer.detach() * (1 - self.moment_mul))
216 moment_width_transfer = moment_transfer[0]216 moment_width_transfer = moment_transfer[0]
217 moment_height_transfer = moment_transfer[1]217 moment_height_transfer = moment_transfer[1]
218 half_width = pts_x_std * torch.exp(moment_width_transfer)218 half_width = pts_x_std * torch.exp(moment_width_transfer)
@@ -221,7 +221,7 @@ class RepPointsHead(nn.Module):
221 pts_x_mean - half_width, pts_y_mean - half_height,221 pts_x_mean - half_width, pts_y_mean - half_height,
222 pts_x_mean + half_width, pts_y_mean + half_height222 pts_x_mean + half_width, pts_y_mean + half_height
223 ],223 ],
224- dim=1)224+ dim=1)
225 else:225 else:
226 raise NotImplementedError226 raise NotImplementedError
227 return bbox227 return bbox
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/retina_head.py+1-1
@@ -59,7 +59,7 @@ class RetinaHead(AnchorHead):
59 self.conv_cfg = conv_cfg59 self.conv_cfg = conv_cfg
60 self.norm_cfg = norm_cfg60 self.norm_cfg = norm_cfg
61 octave_scales = np.array(61 octave_scales = np.array(
62- [2**(i / scales_per_octave) for i in range(scales_per_octave)])62+ [2 ** (i / scales_per_octave) for i in range(scales_per_octave)])
63 anchor_scales = octave_scales * octave_base_scale63 anchor_scales = octave_scales * octave_base_scale
64 super(RetinaHead, self).__init__(64 super(RetinaHead, self).__init__(
65 num_classes, in_channels, anchor_scales=anchor_scales, **kwargs)65 num_classes, in_channels, anchor_scales=anchor_scales, **kwargs)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/retina_sepbn_head.py+1-1
@@ -47,7 +47,7 @@ class RetinaSepBNHead(AnchorHead):
47 self.norm_cfg = norm_cfg47 self.norm_cfg = norm_cfg
48 self.num_ins = num_ins48 self.num_ins = num_ins
49 octave_scales = np.array(49 octave_scales = np.array(
50- [2**(i / scales_per_octave) for i in range(scales_per_octave)])50+ [2 ** (i / scales_per_octave) for i in range(scales_per_octave)])
51 anchor_scales = octave_scales * octave_base_scale51 anchor_scales = octave_scales * octave_base_scale
52 super(RetinaSepBNHead, self).__init__(52 super(RetinaSepBNHead, self).__init__(
53 num_classes, in_channels, anchor_scales=anchor_scales, **kwargs)53 num_classes, in_channels, anchor_scales=anchor_scales, **kwargs)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/solo_head.py+28-22
@@ -25,6 +25,7 @@ from ..utils import bias_init_with_prob, ConvModule
25 25 
26INF = 1e826INF = 1e8
27 27 
28+ 
28def center_of_mass(bitmasks):29def center_of_mass(bitmasks):
29 _, h, w = bitmasks.size()30 _, h, w = bitmasks.size()
30 ys = torch.arange(0, h, dtype=torch.float32, device=bitmasks.device)31 ys = torch.arange(0, h, dtype=torch.float32, device=bitmasks.device)
@@ -37,6 +38,7 @@ def center_of_mass(bitmasks):
37 center_y = m01 / m0038 center_y = m01 / m00
38 return center_x, center_y39 return center_x, center_y
39 40 
41+ 
40def points_nms(heat, kernel=2):42def points_nms(heat, kernel=2):
41 # kernel must be 243 # kernel must be 2
42 hmax = nn.functional.max_pool2d(44 hmax = nn.functional.max_pool2d(
@@ -44,6 +46,7 @@ def points_nms(heat, kernel=2):
44 keep = (hmax[:, :, :-1, :-1] == heat).float()46 keep = (hmax[:, :, :-1, :-1] == heat).float()
45 return heat * keep47 return heat * keep
46 48 
49+ 
47def dice_loss(input, target):50def dice_loss(input, target):
48 input = input.contiguous().view(input.size()[0], -1)51 input = input.contiguous().view(input.size()[0], -1)
49 target = target.contiguous().view(target.size()[0], -1).float()52 target = target.contiguous().view(target.size()[0], -1).float()
@@ -52,7 +55,8 @@ def dice_loss(input, target):
52 b = torch.sum(input * input, 1) + 0.00155 b = torch.sum(input * input, 1) + 0.001
53 c = torch.sum(target * target, 1) + 0.00156 c = torch.sum(target * target, 1) + 0.001
54 d = (2 * a) / (b + c)57 d = (2 * a) / (b + c)
55- return 1-d58+ return 1 - d
59+ 
56 60 
57@HEADS.register_module61@HEADS.register_module
58class SOLOHead(nn.Module):62class SOLOHead(nn.Module):
@@ -123,7 +127,7 @@ class SOLOHead(nn.Module):
123 for seg_num_grid in self.seg_num_grids:127 for seg_num_grid in self.seg_num_grids:
124 self.solo_ins_list.append(128 self.solo_ins_list.append(
125 nn.Conv2d(129 nn.Conv2d(
126- self.seg_feat_channels, seg_num_grid**2, 1))130+ self.seg_feat_channels, seg_num_grid ** 2, 1))
127 131 
128 self.solo_cate = nn.Conv2d(132 self.solo_cate = nn.Conv2d(
129 self.seg_feat_channels, self.cate_out_channels, 3, padding=1)133 self.seg_feat_channels, self.cate_out_channels, 3, padding=1)
@@ -134,7 +138,7 @@ class SOLOHead(nn.Module):
134 for m in self.cate_convs:138 for m in self.cate_convs:
135 normal_init(m.conv, std=0.01)139 normal_init(m.conv, std=0.01)
136 bias_ins = bias_init_with_prob(0.01)140 bias_ins = bias_init_with_prob(0.01)
137- for m in self.solo_ins_list: 141+ for m in self.solo_ins_list:
138 normal_init(m, std=0.01, bias=bias_ins)142 normal_init(m, std=0.01, bias=bias_ins)
139 bias_cate = bias_init_with_prob(0.01)143 bias_cate = bias_init_with_prob(0.01)
140 normal_init(self.solo_cate, std=0.01, bias=bias_cate)144 normal_init(self.solo_cate, std=0.01, bias=bias_cate)
@@ -143,16 +147,16 @@ class SOLOHead(nn.Module):
143 new_feats = self.split_feats(feats)147 new_feats = self.split_feats(feats)
144 featmap_sizes = [featmap.size()[-2:] for featmap in new_feats]148 featmap_sizes = [featmap.size()[-2:] for featmap in new_feats]
145 upsampled_size = (featmap_sizes[0][0] * 2, featmap_sizes[0][1] * 2)149 upsampled_size = (featmap_sizes[0][0] * 2, featmap_sizes[0][1] * 2)
146- ins_pred, cate_pred = multi_apply(self.forward_single, new_feats, 150+ ins_pred, cate_pred = multi_apply(self.forward_single, new_feats,
147 list(range(len(self.seg_num_grids))),151 list(range(len(self.seg_num_grids))),
148 eval=eval, upsampled_size=upsampled_size)152 eval=eval, upsampled_size=upsampled_size)
149 return ins_pred, cate_pred153 return ins_pred, cate_pred
150 154 
151 def split_feats(self, feats):155 def split_feats(self, feats):
152- return (F.interpolate(feats[0], scale_factor=0.5, mode='bilinear'), 156+ return (F.interpolate(feats[0], scale_factor=0.5, mode='bilinear'),
153- feats[1], 157+ feats[1],
154- feats[2], 158+ feats[2],
155- feats[3], 159+ feats[3],
156 F.interpolate(feats[4], size=feats[3].shape[-2:], mode='bilinear'))160 F.interpolate(feats[4], size=feats[3].shape[-2:], mode='bilinear'))
157 161 
158 def forward_single(self, x, idx, eval=False, upsampled_size=None):162 def forward_single(self, x, idx, eval=False, upsampled_size=None):
@@ -216,7 +220,6 @@ class SOLOHead(nn.Module):
216 zip(ins_preds_level, ins_ind_labels_level)], 0)220 zip(ins_preds_level, ins_ind_labels_level)], 0)
217 for ins_preds_level, ins_ind_labels_level in zip(ins_preds, zip(*ins_ind_label_list))]221 for ins_preds_level, ins_ind_labels_level in zip(ins_preds, zip(*ins_ind_label_list))]
218 222 
219- 
220 ins_ind_labels = [223 ins_ind_labels = [
221 torch.cat([ins_ind_labels_level_img.flatten()224 torch.cat([ins_ind_labels_level_img.flatten()
222 for ins_ind_labels_level_img in ins_ind_labels_level])225 for ins_ind_labels_level_img in ins_ind_labels_level])
@@ -256,10 +259,10 @@ class SOLOHead(nn.Module):
256 loss_cate=loss_cate)259 loss_cate=loss_cate)
257 260 
258 def solo_target_single(self,261 def solo_target_single(self,
259- gt_bboxes_raw,262+ gt_bboxes_raw,
260- gt_labels_raw,263+ gt_labels_raw,
261- gt_masks_raw,264+ gt_masks_raw,
262- featmap_sizes=None):265+ featmap_sizes=None):
263 266 
264 device = gt_labels_raw[0].device267 device = gt_labels_raw[0].device
265 268 
@@ -296,9 +299,12 @@ class SOLOHead(nn.Module):
296 valid_mask_flags = gt_masks_pt.sum(dim=-1).sum(dim=-1) > 0299 valid_mask_flags = gt_masks_pt.sum(dim=-1).sum(dim=-1) > 0
297 300 
298 output_stride = stride / 2301 output_stride = stride / 2
299- for seg_mask, gt_label, half_h, half_w, center_h, center_w, valid_mask_flag in zip(gt_masks, gt_labels, half_hs, half_ws, center_hs, center_ws, valid_mask_flags):302+ for seg_mask, gt_label, half_h, half_w, center_h, center_w, valid_mask_flag in zip(gt_masks, gt_labels,
303+ half_hs, half_ws,
304+ center_hs, center_ws,
305+ valid_mask_flags):
300 if not valid_mask_flag:306 if not valid_mask_flag:
301- continue307+ continue
302 upsampled_size = (featmap_sizes[0][0] * 4, featmap_sizes[0][1] * 4)308 upsampled_size = (featmap_sizes[0][0] * 4, featmap_sizes[0][1] * 4)
303 coord_w = int((center_w / upsampled_size[1]) // (1. / num_grid))309 coord_w = int((center_w / upsampled_size[1]) // (1. / num_grid))
304 coord_h = int((center_h / upsampled_size[0]) // (1. / num_grid))310 coord_h = int((center_h / upsampled_size[0]) // (1. / num_grid))
@@ -309,17 +315,17 @@ class SOLOHead(nn.Module):
309 left_box = max(0, int(((center_w - half_w) / upsampled_size[1]) // (1. / num_grid)))315 left_box = max(0, int(((center_w - half_w) / upsampled_size[1]) // (1. / num_grid)))
310 right_box = min(num_grid - 1, int(((center_w + half_w) / upsampled_size[1]) // (1. / num_grid)))316 right_box = min(num_grid - 1, int(((center_w + half_w) / upsampled_size[1]) // (1. / num_grid)))
311 317 
312- top = max(top_box, coord_h-1)318+ top = max(top_box, coord_h - 1)
313- down = min(down_box, coord_h+1)319+ down = min(down_box, coord_h + 1)
314- left = max(coord_w-1, left_box)320+ left = max(coord_w - 1, left_box)
315- right = min(right_box, coord_w+1)321+ right = min(right_box, coord_w + 1)
316 322 
317- cate_label[top:(down+1), left:(right+1)] = gt_label323+ cate_label[top:(down + 1), left:(right + 1)] = gt_label
318 # ins324 # ins
319 seg_mask = mmcv.imrescale(seg_mask, scale=1. / output_stride)325 seg_mask = mmcv.imrescale(seg_mask, scale=1. / output_stride)
320 seg_mask = torch.from_numpy(seg_mask).to(device=device)326 seg_mask = torch.from_numpy(seg_mask).to(device=device)
321- for i in range(top, down+1):327+ for i in range(top, down + 1):
322- for j in range(left, right+1):328+ for j in range(left, right + 1):
323 label = int(i * num_grid + j)329 label = int(i * num_grid + j)
324 ins_label[label, :seg_mask.shape[0], :seg_mask.shape[1]] = seg_mask330 ins_label[label, :seg_mask.shape[0], :seg_mask.shape[1]] = seg_mask
325 ins_ind_label[label] = True331 ins_ind_label[label] = True
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/solov2_head.py+26-16
@@ -23,8 +23,10 @@ from ..builder import build_loss
23from ..registry import HEADS23from ..registry import HEADS
24from ..utils import bias_init_with_prob, ConvModule24from ..utils import bias_init_with_prob, ConvModule
25import numpy as np25import numpy as np
26+ 
26INF = 1e827INF = 1e8
27 28 
29+ 
28def center_of_mass(bitmasks):30def center_of_mass(bitmasks):
29 _, h, w = bitmasks.size()31 _, h, w = bitmasks.size()
30 ys = torch.arange(0, h, dtype=torch.float32, device=bitmasks.device)32 ys = torch.arange(0, h, dtype=torch.float32, device=bitmasks.device)
@@ -37,6 +39,7 @@ def center_of_mass(bitmasks):
37 center_y = m01 / m0039 center_y = m01 / m00
38 return center_x, center_y40 return center_x, center_y
39 41 
42+ 
40def points_nms(heat, kernel=2):43def points_nms(heat, kernel=2):
41 # kernel must be 244 # kernel must be 2
42 hmax = nn.functional.max_pool2d(45 hmax = nn.functional.max_pool2d(
@@ -44,6 +47,7 @@ def points_nms(heat, kernel=2):
44 keep = (hmax[:, :, :-1, :-1] == heat).float()47 keep = (hmax[:, :, :-1, :-1] == heat).float()
45 return heat * keep48 return heat * keep
46 49 
50+ 
47def dice_loss(input, target):51def dice_loss(input, target):
48 input = input.contiguous().view(input.size()[0], -1)52 input = input.contiguous().view(input.size()[0], -1)
49 target = target.contiguous().view(target.size()[0], -1).float()53 target = target.contiguous().view(target.size()[0], -1).float()
@@ -52,7 +56,8 @@ def dice_loss(input, target):
52 b = torch.sum(input * input, 1) + 0.00156 b = torch.sum(input * input, 1) + 0.001
53 c = torch.sum(target * target, 1) + 0.00157 c = torch.sum(target * target, 1) + 0.001
54 d = (2 * a) / (b + c)58 d = (2 * a) / (b + c)
55- return 1-d59+ return 1 - d
60+ 
56 61 
57@HEADS.register_module62@HEADS.register_module
58class SOLOv2Head(nn.Module):63class SOLOv2Head(nn.Module):
@@ -150,8 +155,8 @@ class SOLOv2Head(nn.Module):
150 featmap_sizes = [featmap.size()[-2:] for featmap in new_feats]155 featmap_sizes = [featmap.size()[-2:] for featmap in new_feats]
151 upsampled_size = (featmap_sizes[0][0] * 2, featmap_sizes[0][1] * 2)156 upsampled_size = (featmap_sizes[0][0] * 2, featmap_sizes[0][1] * 2)
152 cate_pred, kernel_pred = multi_apply(self.forward_single, new_feats,157 cate_pred, kernel_pred = multi_apply(self.forward_single, new_feats,
153- list(range(len(self.seg_num_grids))),158+ list(range(len(self.seg_num_grids))),
154- eval=eval, upsampled_size=upsampled_size)159+ eval=eval, upsampled_size=upsampled_size)
155 return cate_pred, kernel_pred160 return cate_pred, kernel_pred
156 161 
157 def split_feats(self, feats):162 def split_feats(self, feats):
@@ -172,7 +177,7 @@ class SOLOv2Head(nn.Module):
172 x = x.expand([ins_kernel_feat.shape[0], 1, -1, -1])177 x = x.expand([ins_kernel_feat.shape[0], 1, -1, -1])
173 coord_feat = torch.cat([x, y], 1)178 coord_feat = torch.cat([x, y], 1)
174 ins_kernel_feat = torch.cat([ins_kernel_feat, coord_feat], 1)179 ins_kernel_feat = torch.cat([ins_kernel_feat, coord_feat], 1)
175- 180+ 
176 # kernel branch181 # kernel branch
177 kernel_feat = ins_kernel_feat182 kernel_feat = ins_kernel_feat
178 seg_num_grid = self.seg_num_grids[idx]183 seg_num_grid = self.seg_num_grids[idx]
@@ -195,7 +200,7 @@ class SOLOv2Head(nn.Module):
195 return cate_pred, kernel_pred200 return cate_pred, kernel_pred
196 201 
197 def loss(self,202 def loss(self,
198- cate_preds, 203+ cate_preds,
199 kernel_preds,204 kernel_preds,
200 ins_pred,205 ins_pred,
201 gt_bbox_list,206 gt_bbox_list,
@@ -203,7 +208,7 @@ class SOLOv2Head(nn.Module):
203 gt_mask_list,208 gt_mask_list,
204 img_metas,209 img_metas,
205 cfg,210 cfg,
206- gt_bboxes_ignore=None): 211+ gt_bboxes_ignore=None):
207 212 
208 # diff213 # diff
209 MAX_LEN = 90214 MAX_LEN = 90
@@ -258,9 +263,9 @@ class SOLOv2Head(nn.Module):
258 continue263 continue
259 cur_ins_pred = ins_pred[idx, ...] # this img‘s pred264 cur_ins_pred = ins_pred[idx, ...] # this img‘s pred
260 H, W = cur_ins_pred.shape[-2:]265 H, W = cur_ins_pred.shape[-2:]
261- N, I = kernel_pred.shape 266+ N, I = kernel_pred.shape
262 cur_ins_pred = cur_ins_pred.unsqueeze(0) # [1, c, msk_pre_h, msk_pre_w] c = N267 cur_ins_pred = cur_ins_pred.unsqueeze(0) # [1, c, msk_pre_h, msk_pre_w] c = N
263- kernel_pred = kernel_pred.permute(1, 0).view(I, -1, 1, 1) 268+ kernel_pred = kernel_pred.permute(1, 0).view(I, -1, 1, 1)
264 cur_ins_pred = F.conv2d(cur_ins_pred, kernel_pred, stride=1).view(-1, H, W) # (n, msk_pre_h, msk_pre_w)269 cur_ins_pred = F.conv2d(cur_ins_pred, kernel_pred, stride=1).view(-1, H, W) # (n, msk_pre_h, msk_pre_w)
265 b_mask_pred.append(cur_ins_pred)270 b_mask_pred.append(cur_ins_pred)
266 if len(b_mask_pred) == 0:271 if len(b_mask_pred) == 0:
@@ -420,7 +425,7 @@ class SOLOv2Head(nn.Module):
420 seg_pred_list = seg_pred[img_id, ...].unsqueeze(0).float().cpu()425 seg_pred_list = seg_pred[img_id, ...].unsqueeze(0).float().cpu()
421 kernel_pred_list = [426 kernel_pred_list = [
422 kernel_preds[i][img_id].permute(1, 2, 0).view(-1, self.kernel_out_channels).detach()427 kernel_preds[i][img_id].permute(1, 2, 0).view(-1, self.kernel_out_channels).detach()
423- for i in range(num_levels)428+ for i in range(num_levels)
424 ]429 ]
425 img_shape = img_metas[img_id]['img_shape']430 img_shape = img_metas[img_id]['img_shape']
426 scale_factor = img_metas[img_id]['scale_factor']431 scale_factor = img_metas[img_id]['scale_factor']
@@ -467,13 +472,18 @@ class SOLOv2Head(nn.Module):
467 n_stage = len(self.seg_num_grids)472 n_stage = len(self.seg_num_grids)
468 strides[:size_trans[0]] *= self.strides[0]473 strides[:size_trans[0]] *= self.strides[0]
469 for ind_ in range(1, n_stage):474 for ind_ in range(1, n_stage):
470- strides[size_trans[ind_-1]:size_trans[ind_]] *= self.strides[ind_]475+ strides[size_trans[ind_ - 1]:size_trans[ind_]] *= self.strides[ind_]
471 strides = strides[inds[:, 0]]476 strides = strides[inds[:, 0]]
472 477 
473 # mask encoding.478 # mask encoding.
474 I, N = kernel_preds.shape479 I, N = kernel_preds.shape
475 kernel_preds = kernel_preds.view(I, N, 1, 1)480 kernel_preds = kernel_preds.view(I, N, 1, 1)
476- seg_preds = F.conv2d(seg_preds, kernel_preds, stride=1).squeeze(0).sigmoid()481+ new_I = ((I // 100) + 1) * 100
482+ 
483+ new_kernel_preds = torch.zeros(new_I, N, 1, 1)
484+ new_kernel_preds[:I] = kernel_preds
485+ seg_preds = F.conv2d(seg_preds.npu().half(), new_kernel_preds.npu().half(), stride=1).squeeze(
486+ 0).sigmoid().cpu().float()[:I, :, :]
477 # mask.487 # mask.
478 seg_masks = seg_preds > cfg.mask_thr488 seg_masks = seg_preds > cfg.mask_thr
479 sum_masks = seg_masks.sum((1, 2)).float()489 sum_masks = seg_masks.sum((1, 2)).float()
@@ -505,7 +515,7 @@ class SOLOv2Head(nn.Module):
505 515 
506 # Matrix NMS516 # Matrix NMS
507 cate_scores = matrix_nms(seg_masks, cate_labels, cate_scores,517 cate_scores = matrix_nms(seg_masks, cate_labels, cate_scores,
508- kernel=cfg.kernel,sigma=cfg.sigma, sum_masks=sum_masks)518+ kernel=cfg.kernel, sigma=cfg.sigma, sum_masks=sum_masks)
509 519 
510 # filter.520 # filter.
511 keep = cate_scores >= cfg.update_thr521 keep = cate_scores >= cfg.update_thr
@@ -524,10 +534,10 @@ class SOLOv2Head(nn.Module):
524 cate_labels = cate_labels[sort_inds]534 cate_labels = cate_labels[sort_inds]
525 535 
526 seg_preds = F.interpolate(seg_preds.unsqueeze(0),536 seg_preds = F.interpolate(seg_preds.unsqueeze(0),
527- size=upsampled_size_out,537+ size=upsampled_size_out,
528- mode='bilinear')[:, :, :h, :w]538+ mode='bilinear')[:, :, :h, :w]
529 seg_masks = F.interpolate(seg_preds,539 seg_masks = F.interpolate(seg_preds,
530- size=ori_shape[:2],540+ size=ori_shape[:2],
531- mode='bilinear').squeeze(0)541+ mode='bilinear').squeeze(0)
532 seg_masks = seg_masks > cfg.mask_thr542 seg_masks = seg_masks > cfg.mask_thr
533 return seg_masks, cate_labels, cate_scores543 return seg_masks, cate_labels, cate_scores
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/anchor_heads/solov2_light_head.py+32-25
@@ -25,6 +25,7 @@ from ..utils import bias_init_with_prob, ConvModule
25 25 
26INF = 1e826INF = 1e8
27 27 
28+ 
28def center_of_mass(bitmasks):29def center_of_mass(bitmasks):
29 _, h, w = bitmasks.size()30 _, h, w = bitmasks.size()
30 ys = torch.arange(0, h, dtype=torch.float32, device=bitmasks.device)31 ys = torch.arange(0, h, dtype=torch.float32, device=bitmasks.device)
@@ -37,6 +38,7 @@ def center_of_mass(bitmasks):
37 center_y = m01 / m0038 center_y = m01 / m00
38 return center_x, center_y39 return center_x, center_y
39 40 
41+ 
40def points_nms(heat, kernel=2):42def points_nms(heat, kernel=2):
41 # kernel must be 243 # kernel must be 2
42 hmax = nn.functional.max_pool2d(44 hmax = nn.functional.max_pool2d(
@@ -44,6 +46,7 @@ def points_nms(heat, kernel=2):
44 keep = (hmax[:, :, :-1, :-1] == heat).float()46 keep = (hmax[:, :, :-1, :-1] == heat).float()
45 return heat * keep47 return heat * keep
46 48 
49+ 
47def dice_loss(input, target):50def dice_loss(input, target):
48 input = input.contiguous().view(input.size()[0], -1)51 input = input.contiguous().view(input.size()[0], -1)
49 target = target.contiguous().view(target.size()[0], -1).float()52 target = target.contiguous().view(target.size()[0], -1).float()
@@ -52,7 +55,8 @@ def dice_loss(input, target):
52 b = torch.sum(input * input, 1) + 0.00155 b = torch.sum(input * input, 1) + 0.001
53 c = torch.sum(target * target, 1) + 0.00156 c = torch.sum(target * target, 1) + 0.001
54 d = (2 * a) / (b + c)57 d = (2 * a) / (b + c)
55- return 1-d58+ return 1 - d
59+ 
56 60 
57@HEADS.register_module61@HEADS.register_module
58class SOLOv2LightHead(nn.Module):62class SOLOv2LightHead(nn.Module):
@@ -150,8 +154,8 @@ class SOLOv2LightHead(nn.Module):
150 featmap_sizes = [featmap.size()[-2:] for featmap in new_feats]154 featmap_sizes = [featmap.size()[-2:] for featmap in new_feats]
151 upsampled_size = (featmap_sizes[0][0] * 2, featmap_sizes[0][1] * 2)155 upsampled_size = (featmap_sizes[0][0] * 2, featmap_sizes[0][1] * 2)
152 cate_pred, kernel_pred = multi_apply(self.forward_single, new_feats,156 cate_pred, kernel_pred = multi_apply(self.forward_single, new_feats,
153- list(range(len(self.seg_num_grids))),157+ list(range(len(self.seg_num_grids))),
154- eval=eval, upsampled_size=upsampled_size)158+ eval=eval, upsampled_size=upsampled_size)
155 return cate_pred, kernel_pred159 return cate_pred, kernel_pred
156 160 
157 def split_feats(self, feats):161 def split_feats(self, feats):
@@ -172,7 +176,7 @@ class SOLOv2LightHead(nn.Module):
172 x = x.expand([ins_kernel_feat.shape[0], 1, -1, -1])176 x = x.expand([ins_kernel_feat.shape[0], 1, -1, -1])
173 coord_feat = torch.cat([x, y], 1)177 coord_feat = torch.cat([x, y], 1)
174 ins_kernel_feat = torch.cat([ins_kernel_feat, coord_feat], 1)178 ins_kernel_feat = torch.cat([ins_kernel_feat, coord_feat], 1)
175- 179+ 
176 # kernel branch180 # kernel branch
177 kernel_feat = ins_kernel_feat181 kernel_feat = ins_kernel_feat
178 seg_num_grid = self.seg_num_grids[idx]182 seg_num_grid = self.seg_num_grids[idx]
@@ -210,7 +214,7 @@ class SOLOv2LightHead(nn.Module):
210 self.solov2_target_single,214 self.solov2_target_single,
211 gt_bbox_list,215 gt_bbox_list,
212 gt_label_list,216 gt_label_list,
213- gt_mask_list, 217+ gt_mask_list,
214 mask_feat_size=mask_feat_size)218 mask_feat_size=mask_feat_size)
215 219 
216 # ins220 # ins
@@ -283,10 +287,10 @@ class SOLOv2LightHead(nn.Module):
283 loss_cate=loss_cate)287 loss_cate=loss_cate)
284 288 
285 def solov2_target_single(self,289 def solov2_target_single(self,
286- gt_bboxes_raw,290+ gt_bboxes_raw,
287- gt_labels_raw,291+ gt_labels_raw,
288- gt_masks_raw,292+ gt_masks_raw,
289- mask_feat_size):293+ mask_feat_size):
290 294 
291 device = gt_labels_raw[0].device295 device = gt_labels_raw[0].device
292 296 
@@ -328,9 +332,12 @@ class SOLOv2LightHead(nn.Module):
328 center_ws, center_hs = center_of_mass(gt_masks_pt)332 center_ws, center_hs = center_of_mass(gt_masks_pt)
329 valid_mask_flags = gt_masks_pt.sum(dim=-1).sum(dim=-1) > 0333 valid_mask_flags = gt_masks_pt.sum(dim=-1).sum(dim=-1) > 0
330 output_stride = 4334 output_stride = 4
331- for seg_mask, gt_label, half_h, half_w, center_h, center_w, valid_mask_flag in zip(gt_masks, gt_labels, half_hs, half_ws, center_hs, center_ws, valid_mask_flags):335+ for seg_mask, gt_label, half_h, half_w, center_h, center_w, valid_mask_flag in zip(gt_masks, gt_labels,
336+ half_hs, half_ws,
337+ center_hs, center_ws,
338+ valid_mask_flags):
332 if not valid_mask_flag:339 if not valid_mask_flag:
333- continue340+ continue
334 upsampled_size = (mask_feat_size[0] * 4, mask_feat_size[1] * 4)341 upsampled_size = (mask_feat_size[0] * 4, mask_feat_size[1] * 4)
335 coord_w = int((center_w / upsampled_size[1]) // (1. / num_grid))342 coord_w = int((center_w / upsampled_size[1]) // (1. / num_grid))
336 coord_h = int((center_h / upsampled_size[0]) // (1. / num_grid))343 coord_h = int((center_h / upsampled_size[0]) // (1. / num_grid))
@@ -341,16 +348,16 @@ class SOLOv2LightHead(nn.Module):
341 left_box = max(0, int(((center_w - half_w) / upsampled_size[1]) // (1. / num_grid)))348 left_box = max(0, int(((center_w - half_w) / upsampled_size[1]) // (1. / num_grid)))
342 right_box = min(num_grid - 1, int(((center_w + half_w) / upsampled_size[1]) // (1. / num_grid)))349 right_box = min(num_grid - 1, int(((center_w + half_w) / upsampled_size[1]) // (1. / num_grid)))
343 350 
344- top = max(top_box, coord_h-1)351+ top = max(top_box, coord_h - 1)
345- down = min(down_box, coord_h+1)352+ down = min(down_box, coord_h + 1)
346- left = max(coord_w-1, left_box)353+ left = max(coord_w - 1, left_box)
347- right = min(right_box, coord_w+1)354+ right = min(right_box, coord_w + 1)
348 355 
349- cate_label[top:(down+1), left:(right+1)] = gt_label356+ cate_label[top:(down + 1), left:(right + 1)] = gt_label
350 seg_mask = mmcv.imrescale(seg_mask, scale=1. / output_stride)357 seg_mask = mmcv.imrescale(seg_mask, scale=1. / output_stride)
351 seg_mask = torch.from_numpy(seg_mask).to(device=device)358 seg_mask = torch.from_numpy(seg_mask).to(device=device)
352- for i in range(top, down+1):359+ for i in range(top, down + 1):
353- for j in range(left, right+1):360+ for j in range(left, right + 1):
354 label = int(i * num_grid + j)361 label = int(i * num_grid + j)
355 362 
356 cur_ins_label = torch.zeros([mask_feat_size[0], mask_feat_size[1]], dtype=torch.uint8,363 cur_ins_label = torch.zeros([mask_feat_size[0], mask_feat_size[1]], dtype=torch.uint8,
@@ -381,7 +388,7 @@ class SOLOv2LightHead(nn.Module):
381 seg_pred_list = seg_pred[img_id, ...].unsqueeze(0)388 seg_pred_list = seg_pred[img_id, ...].unsqueeze(0)
382 kernel_pred_list = [389 kernel_pred_list = [
383 kernel_preds[i][img_id].permute(1, 2, 0).view(-1, self.kernel_out_channels).detach()390 kernel_preds[i][img_id].permute(1, 2, 0).view(-1, self.kernel_out_channels).detach()
384- for i in range(num_levels)391+ for i in range(num_levels)
385 ]392 ]
386 img_shape = img_metas[img_id]['img_shape']393 img_shape = img_metas[img_id]['img_shape']
387 scale_factor = img_metas[img_id]['scale_factor']394 scale_factor = img_metas[img_id]['scale_factor']
@@ -430,7 +437,7 @@ class SOLOv2LightHead(nn.Module):
430 n_stage = len(self.seg_num_grids)437 n_stage = len(self.seg_num_grids)
431 strides[:size_trans[0]] *= self.strides[0]438 strides[:size_trans[0]] *= self.strides[0]
432 for ind_ in range(1, n_stage):439 for ind_ in range(1, n_stage):
433- strides[size_trans[ind_-1]:size_trans[ind_]] *= self.strides[ind_]440+ strides[size_trans[ind_ - 1]:size_trans[ind_]] *= self.strides[ind_]
434 strides = strides[inds[:, 0]]441 strides = strides[inds[:, 0]]
435 442 
436 # mask encoding.443 # mask encoding.
@@ -468,7 +475,7 @@ class SOLOv2LightHead(nn.Module):
468 475 
469 # Matrix NMS476 # Matrix NMS
470 cate_scores = matrix_nms(seg_masks, cate_labels, cate_scores,477 cate_scores = matrix_nms(seg_masks, cate_labels, cate_scores,
471- kernel=cfg.kernel,sigma=cfg.sigma, sum_masks=sum_masks)478+ kernel=cfg.kernel, sigma=cfg.sigma, sum_masks=sum_masks)
472 479 
473 # filter.480 # filter.
474 keep = cate_scores >= cfg.update_thr481 keep = cate_scores >= cfg.update_thr
@@ -487,10 +494,10 @@ class SOLOv2LightHead(nn.Module):
487 cate_labels = cate_labels[sort_inds]494 cate_labels = cate_labels[sort_inds]
488 495 
489 seg_preds = F.interpolate(seg_preds.unsqueeze(0),496 seg_preds = F.interpolate(seg_preds.unsqueeze(0),
490- size=upsampled_size_out,497+ size=upsampled_size_out,
491- mode='bilinear')[:, :, :h, :w]498+ mode='bilinear')[:, :, :h, :w]
492 seg_masks = F.interpolate(seg_preds,499 seg_masks = F.interpolate(seg_preds,
493- size=ori_shape[:2],500+ size=ori_shape[:2],
494- mode='bilinear').squeeze(0)501+ mode='bilinear').squeeze(0)
495 seg_masks = seg_masks > cfg.mask_thr502 seg_masks = seg_masks > cfg.mask_thr
496 return seg_masks, cate_labels, cate_scores503 return seg_masks, cate_labels, cate_scores
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/backbones/hrnet.py+1-1
@@ -148,7 +148,7 @@ class HRModule(nn.Module):
148 bias=False),148 bias=False),
149 build_norm_layer(self.norm_cfg, in_channels[i])[1],149 build_norm_layer(self.norm_cfg, in_channels[i])[1],
150 nn.Upsample(150 nn.Upsample(
151- scale_factor=2**(j - i), mode='nearest')))151+ scale_factor=2 ** (j - i), mode='nearest')))
152 elif j == i:152 elif j == i:
153 fuse_layer.append(None)153 fuse_layer.append(None)
154 else:154 else:
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/backbones/resnet.py+3-3
@@ -424,7 +424,7 @@ class ResNet(nn.Module):
424 dilation = dilations[i]424 dilation = dilations[i]
425 dcn = self.dcn if self.stage_with_dcn[i] else None425 dcn = self.dcn if self.stage_with_dcn[i] else None
426 gcb = self.gcb if self.stage_with_gcb[i] else None426 gcb = self.gcb if self.stage_with_gcb[i] else None
427- planes = 64 * 2**i427+ planes = 64 * 2 ** i
428 res_layer = make_res_layer(428 res_layer = make_res_layer(
429 self.block,429 self.block,
430 self.inplanes,430 self.inplanes,
@@ -447,8 +447,8 @@ class ResNet(nn.Module):
447 447 
448 self._freeze_stages()448 self._freeze_stages()
449 449 
450- self.feat_dim = self.block.expansion * 64 * 2**(450+ self.feat_dim = self.block.expansion * 64 * 2 ** (
451- len(self.stage_blocks) - 1)451+ len(self.stage_blocks) - 1)
452 452 
453 @property453 @property
454 def norm1(self):454 def norm1(self):
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/backbones/resnext.py+1-1
@@ -212,7 +212,7 @@ class ResNeXt(ResNet):
212 dilation = self.dilations[i]212 dilation = self.dilations[i]
213 dcn = self.dcn if self.stage_with_dcn[i] else None213 dcn = self.dcn if self.stage_with_dcn[i] else None
214 gcb = self.gcb if self.stage_with_gcb[i] else None214 gcb = self.gcb if self.stage_with_gcb[i] else None
215- planes = 64 * 2**i215+ planes = 64 * 2 ** i
216 res_layer = make_res_layer(216 res_layer = make_res_layer(
217 self.block,217 self.block,
218 self.inplanes,218 self.inplanes,
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/bbox_heads/bbox_head.py+2-2
@@ -186,7 +186,7 @@ class BBoxHead(nn.Module):
186 186 
187 return det_bboxes, det_labels187 return det_bboxes, det_labels
188 188 
189- @force_fp32(apply_to=('bbox_preds', ))189+ @force_fp32(apply_to=('bbox_preds',))
190 def refine_bboxes(self, rois, labels, bbox_preds, pos_is_gts, img_metas):190 def refine_bboxes(self, rois, labels, bbox_preds, pos_is_gts, img_metas):
191 """Refine bboxes during training.191 """Refine bboxes during training.
192 192 
@@ -264,7 +264,7 @@ class BBoxHead(nn.Module):
264 264 
265 return bboxes_list265 return bboxes_list
266 266 
267- @force_fp32(apply_to=('bbox_pred', ))267+ @force_fp32(apply_to=('bbox_pred',))
268 def regress_by_class(self, rois, label, bbox_pred, img_meta):268 def regress_by_class(self, rois, label, bbox_pred, img_meta):
269 """Regress the bbox for the predicted class. Used in Cascade R-CNN.269 """Regress the bbox for the predicted class. Used in Cascade R-CNN.
270 270 
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/bbox_heads/convfc_bbox_head.py+2-2
@@ -91,7 +91,7 @@ class ConvFCBBoxHead(BBoxHead):
91 self.fc_cls = nn.Linear(self.cls_last_dim, self.num_classes)91 self.fc_cls = nn.Linear(self.cls_last_dim, self.num_classes)
92 if self.with_reg:92 if self.with_reg:
93 out_dim_reg = (4 if self.reg_class_agnostic else 4 *93 out_dim_reg = (4 if self.reg_class_agnostic else 4 *
94- self.num_classes)94+ self.num_classes)
95 self.fc_reg = nn.Linear(self.reg_last_dim, out_dim_reg)95 self.fc_reg = nn.Linear(self.reg_last_dim, out_dim_reg)
96 96 
97 def _add_conv_fc_branch(self,97 def _add_conv_fc_branch(self,
@@ -125,7 +125,7 @@ class ConvFCBBoxHead(BBoxHead):
125 # for shared branch, only consider self.with_avg_pool125 # for shared branch, only consider self.with_avg_pool
126 # for separated branches, also consider self.num_shared_fcs126 # for separated branches, also consider self.num_shared_fcs
127 if (is_shared127 if (is_shared
128- or self.num_shared_fcs == 0) and not self.with_avg_pool:128+ or self.num_shared_fcs == 0) and not self.with_avg_pool:
129 last_layer_dim *= self.roi_feat_area129 last_layer_dim *= self.roi_feat_area
130 for i in range(num_branch_fcs):130 for i in range(num_branch_fcs):
131 fc_in_channels = (131 fc_in_channels = (
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/detectors/base.py+2-2
@@ -37,7 +37,7 @@ class BaseDetector(nn.Module, metaclass=ABCMeta):
37 @property37 @property
38 def with_mask_feat_head(self):38 def with_mask_feat_head(self):
39 return hasattr(self, 'mask_feat_head') and \39 return hasattr(self, 'mask_feat_head') and \
40- self.mask_feat_head is not None40+ self.mask_feat_head is not None
41 41 
42 @property42 @property
43 def with_shared_head(self):43 def with_shared_head(self):
@@ -147,7 +147,7 @@ class BaseDetector(nn.Module, metaclass=ABCMeta):
147 else:147 else:
148 return self.aug_test(imgs, img_metas, **kwargs)148 return self.aug_test(imgs, img_metas, **kwargs)
149 149 
150- @auto_fp16(apply_to=('img', ))150+ @auto_fp16(apply_to=('img',))
151 def forward(self, img, img_meta, return_loss=True, **kwargs):151 def forward(self, img, img_meta, return_loss=True, **kwargs):
152 """152 """
153 Calls either forward_train or forward_test depending on whether153 Calls either forward_train or forward_test depending on whether
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/detectors/cascade_rcnn.py+2-2
@@ -139,7 +139,7 @@ class CascadeRCNN(BaseDetector, RPNTestMixin):
139 # rpn139 # rpn
140 if self.with_rpn:140 if self.with_rpn:
141 rpn_outs = self.rpn_head(x)141 rpn_outs = self.rpn_head(x)
142- outs = outs + (rpn_outs, )142+ outs = outs + (rpn_outs,)
143 proposals = torch.randn(1000, 4).cuda()143 proposals = torch.randn(1000, 4).cuda()
144 # bbox heads144 # bbox heads
145 rois = bbox2roi([proposals])145 rois = bbox2roi([proposals])
@@ -160,7 +160,7 @@ class CascadeRCNN(BaseDetector, RPNTestMixin):
160 if self.with_shared_head:160 if self.with_shared_head:
161 mask_feats = self.shared_head(mask_feats)161 mask_feats = self.shared_head(mask_feats)
162 mask_pred = self.mask_head[i](mask_feats)162 mask_pred = self.mask_head[i](mask_feats)
163- outs = outs + (mask_pred, )163+ outs = outs + (mask_pred,)
164 return outs164 return outs
165 165 
166 def forward_train(self,166 def forward_train(self,
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/detectors/double_head_rcnn.py+1-1
@@ -33,7 +33,7 @@ class DoubleHeadRCNN(TwoStageDetector):
33 # rpn33 # rpn
34 if self.with_rpn:34 if self.with_rpn:
35 rpn_outs = self.rpn_head(x)35 rpn_outs = self.rpn_head(x)
36- outs = outs + (rpn_outs, )36+ outs = outs + (rpn_outs,)
37 proposals = torch.randn(1000, 4).cuda()37 proposals = torch.randn(1000, 4).cuda()
38 # bbox head38 # bbox head
39 rois = bbox2roi([proposals])39 rois = bbox2roi([proposals])
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/detectors/grid_rcnn.py+1-1
@@ -101,7 +101,7 @@ class GridRCNN(TwoStageDetector):
101 # rpn101 # rpn
102 if self.with_rpn:102 if self.with_rpn:
103 rpn_outs = self.rpn_head(x)103 rpn_outs = self.rpn_head(x)
104- outs = outs + (rpn_outs, )104+ outs = outs + (rpn_outs,)
105 proposals = torch.randn(1000, 4).cuda()105 proposals = torch.randn(1000, 4).cuda()
106 # bbox head106 # bbox head
107 rois = bbox2roi([proposals])107 rois = bbox2roi([proposals])
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/detectors/htc.py+3-3
@@ -175,7 +175,7 @@ class HybridTaskCascade(CascadeRCNN):
175 # rpn175 # rpn
176 if self.with_rpn:176 if self.with_rpn:
177 rpn_outs = self.rpn_head(x)177 rpn_outs = self.rpn_head(x)
178- outs = outs + (rpn_outs, )178+ outs = outs + (rpn_outs,)
179 proposals = torch.randn(1000, 4).cuda()179 proposals = torch.randn(1000, 4).cuda()
180 # semantic head180 # semantic head
181 if self.with_semantic:181 if self.with_semantic:
@@ -205,7 +205,7 @@ class HybridTaskCascade(CascadeRCNN):
205 mask_pred, last_feat = mask_head(mask_feats, last_feat)205 mask_pred, last_feat = mask_head(mask_feats, last_feat)
206 else:206 else:
207 mask_pred = mask_head(mask_feats)207 mask_pred = mask_head(mask_feats)
208- outs = outs + (mask_pred, )208+ outs = outs + (mask_pred,)
209 return outs209 return outs
210 210 
211 def forward_train(self,211 def forward_train(self,
@@ -499,7 +499,7 @@ class HybridTaskCascade(CascadeRCNN):
499 mask_semantic_feat = self.semantic_roi_extractor(499 mask_semantic_feat = self.semantic_roi_extractor(
500 [semantic_feat], mask_rois)500 [semantic_feat], mask_rois)
501 if mask_semantic_feat.shape[-2:] != mask_feats.shape[501 if mask_semantic_feat.shape[-2:] != mask_feats.shape[
502- -2:]:502+ -2:]:
503 mask_semantic_feat = F.adaptive_avg_pool2d(503 mask_semantic_feat = F.adaptive_avg_pool2d(
504 mask_semantic_feat, mask_feats.shape[-2:])504 mask_semantic_feat, mask_feats.shape[-2:])
505 mask_feats += mask_semantic_feat505 mask_feats += mask_semantic_feat
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/detectors/single_stage_ins.py+3-4
@@ -91,7 +91,7 @@ class SingleStageInsDetector(BaseDetector):
91 if self.with_mask_feat_head:91 if self.with_mask_feat_head:
92 mask_feat_pred = self.mask_feat_head(92 mask_feat_pred = self.mask_feat_head(
93 x[self.mask_feat_head.93 x[self.mask_feat_head.
94- start_level:self.mask_feat_head.end_level + 1])94+ start_level:self.mask_feat_head.end_level + 1])
95 loss_inputs = outs + (mask_feat_pred, gt_bboxes, gt_labels, gt_masks, img_metas, self.train_cfg)95 loss_inputs = outs + (mask_feat_pred, gt_bboxes, gt_labels, gt_masks, img_metas, self.train_cfg)
96 else:96 else:
97 loss_inputs = outs + (gt_bboxes, gt_labels, gt_masks, img_metas, self.train_cfg)97 loss_inputs = outs + (gt_bboxes, gt_labels, gt_masks, img_metas, self.train_cfg)
@@ -102,19 +102,18 @@ class SingleStageInsDetector(BaseDetector):
102 def simple_test(self, img, img_meta, rescale=False):102 def simple_test(self, img, img_meta, rescale=False):
103 # diff103 # diff
104 img = img.npu()104 img = img.npu()
105-
106 x = self.extract_feat(img)105 x = self.extract_feat(img)
107 outs = self.bbox_head(x, eval=True)106 outs = self.bbox_head(x, eval=True)
108 if self.with_mask_feat_head:107 if self.with_mask_feat_head:
109 mask_feat_pred = self.mask_feat_head(108 mask_feat_pred = self.mask_feat_head(
110 x[self.mask_feat_head.109 x[self.mask_feat_head.
111- start_level:self.mask_feat_head.end_level + 1])110+ start_level:self.mask_feat_head.end_level + 1])
112 seg_inputs = outs + (mask_feat_pred, img_meta, self.test_cfg, rescale)111 seg_inputs = outs + (mask_feat_pred, img_meta, self.test_cfg, rescale)
113 else:112 else:
114 seg_inputs = outs + (img_meta, self.test_cfg, rescale)113 seg_inputs = outs + (img_meta, self.test_cfg, rescale)
115 114 
116 seg_result = self.bbox_head.get_seg(*seg_inputs)115 seg_result = self.bbox_head.get_seg(*seg_inputs)
117- return seg_result 116+ return seg_result
118 117 
119 def aug_test(self, imgs, img_metas, rescale=False):118 def aug_test(self, imgs, img_metas, rescale=False):
120 raise NotImplementedError119 raise NotImplementedError
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/detectors/solov2.py+1-1
@@ -28,4 +28,4 @@ class SOLOv2(SingleStageInsDetector):
28 test_cfg=None,28 test_cfg=None,
29 pretrained=None):29 pretrained=None):
30 super(SOLOv2, self).__init__(backbone, neck, bbox_head, mask_feat_head, train_cfg,30 super(SOLOv2, self).__init__(backbone, neck, bbox_head, mask_feat_head, train_cfg,
31- test_cfg, pretrained)31+ test_cfg, pretrained)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/detectors/test_mixins.py+0-4
@@ -27,9 +27,7 @@ if sys.version_info >= (3, 7):
27 27 
28 28 
29class RPNTestMixin(object):29class RPNTestMixin(object):
30- 
31 if sys.version_info >= (3, 7):30 if sys.version_info >= (3, 7):
32- 
33 async def async_test_rpn(self, x, img_meta, rpn_test_cfg):31 async def async_test_rpn(self, x, img_meta, rpn_test_cfg):
34 sleep_interval = rpn_test_cfg.pop("async_sleep_interval", 0.025)32 sleep_interval = rpn_test_cfg.pop("async_sleep_interval", 0.025)
35 async with completed(33 async with completed(
@@ -72,7 +70,6 @@ class RPNTestMixin(object):
72 70 
73 71 
74class BBoxTestMixin(object):72class BBoxTestMixin(object):
75- 
76 if sys.version_info >= (3, 7):73 if sys.version_info >= (3, 7):
77 74 
78 async def async_test_bboxes(self,75 async def async_test_bboxes(self,
@@ -172,7 +169,6 @@ class BBoxTestMixin(object):
172 169 
173 170 
174class MaskTestMixin(object):171class MaskTestMixin(object):
175- 
176 if sys.version_info >= (3, 7):172 if sys.version_info >= (3, 7):
177 173 
178 async def async_test_mask(self,174 async def async_test_mask(self,
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/detectors/two_stage.py+2-2
@@ -119,7 +119,7 @@ class TwoStageDetector(BaseDetector, RPNTestMixin, BBoxTestMixin,
119 # rpn119 # rpn
120 if self.with_rpn:120 if self.with_rpn:
121 rpn_outs = self.rpn_head(x)121 rpn_outs = self.rpn_head(x)
122- outs = outs + (rpn_outs, )122+ outs = outs + (rpn_outs,)
123 proposals = torch.randn(1000, 4).cuda()123 proposals = torch.randn(1000, 4).cuda()
124 # bbox head124 # bbox head
125 rois = bbox2roi([proposals])125 rois = bbox2roi([proposals])
@@ -138,7 +138,7 @@ class TwoStageDetector(BaseDetector, RPNTestMixin, BBoxTestMixin,
138 if self.with_shared_head:138 if self.with_shared_head:
139 mask_feats = self.shared_head(mask_feats)139 mask_feats = self.shared_head(mask_feats)
140 mask_pred = self.mask_head(mask_feats)140 mask_pred = self.mask_head(mask_feats)
141- outs = outs + (mask_pred, )141+ outs = outs + (mask_pred,)
142 return outs142 return outs
143 143 
144 def forward_train(self,144 def forward_train(self,
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/losses/accuracy.py+2-2
@@ -18,7 +18,7 @@ import torch.nn as nn
18def accuracy(pred, target, topk=1):18def accuracy(pred, target, topk=1):
19 assert isinstance(topk, (int, tuple))19 assert isinstance(topk, (int, tuple))
20 if isinstance(topk, int):20 if isinstance(topk, int):
21- topk = (topk, )21+ topk = (topk,)
22 return_single = True22 return_single = True
23 else:23 else:
24 return_single = False24 return_single = False
@@ -37,7 +37,7 @@ def accuracy(pred, target, topk=1):
37 37 
38class Accuracy(nn.Module):38class Accuracy(nn.Module):
39 39 
40- def __init__(self, topk=(1, )):40+ def __init__(self, topk=(1,)):
41 super().__init__()41 super().__init__()
42 self.topk = topk42 self.topk = topk
43 43 
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/losses/balanced_l1_loss.py+1-1
@@ -31,7 +31,7 @@ def balanced_l1_loss(pred,
31 assert pred.size() == target.size() and target.numel() > 031 assert pred.size() == target.size() and target.numel() > 0
32 32 
33 diff = torch.abs(pred - target)33 diff = torch.abs(pred - target)
34- b = np.e**(gamma / alpha) - 134+ b = np.e ** (gamma / alpha) - 1
35 loss = torch.where(35 loss = torch.where(
36 diff < beta, alpha / b *36 diff < beta, alpha / b *
37 (b * diff + 1) * torch.log(b * diff / beta + 1) - alpha * diff,37 (b * diff + 1) * torch.log(b * diff / beta + 1) - alpha * diff,
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/losses/focal_loss.py+2-1
@@ -15,7 +15,7 @@
15import torch15import torch
16import torch.nn as nn16import torch.nn as nn
17import torch.nn.functional as F17import torch.nn.functional as F
18-#from mmcv.ops import sigmoid_focal_loss as _sigmoid_focal_loss18+# from mmcv.ops import sigmoid_focal_loss as _sigmoid_focal_loss
19 19 
20from ..builder import LOSSES20from ..builder import LOSSES
21from .utils import weight_reduce_loss21from .utils import weight_reduce_loss
@@ -55,6 +55,7 @@ def py_sigmoid_focal_loss(pred,
55 loss = weight_reduce_loss(loss, weight, reduction, avg_factor)55 loss = weight_reduce_loss(loss, weight, reduction, avg_factor)
56 return loss56 return loss
57 57 
58+ 
58def sigmoid_focal_loss(pred,59def sigmoid_focal_loss(pred,
59 target,60 target,
60 weight=None,61 weight=None,
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/losses/ghm_loss.py+2-2
@@ -94,7 +94,7 @@ class GHMC(nn.Module):
94 if num_in_bin > 0:94 if num_in_bin > 0:
95 if mmt > 0:95 if mmt > 0:
96 self.acc_sum[i] = mmt * self.acc_sum[i] \96 self.acc_sum[i] = mmt * self.acc_sum[i] \
97- + (1 - mmt) * num_in_bin97+ + (1 - mmt) * num_in_bin
98 weights[inds] = tot / self.acc_sum[i]98 weights[inds] = tot / self.acc_sum[i]
99 else:99 else:
100 weights[inds] = tot / num_in_bin100 weights[inds] = tot / num_in_bin
@@ -173,7 +173,7 @@ class GHMR(nn.Module):
173 n += 1173 n += 1
174 if mmt > 0:174 if mmt > 0:
175 self.acc_sum[i] = mmt * self.acc_sum[i] \175 self.acc_sum[i] = mmt * self.acc_sum[i] \
176- + (1 - mmt) * num_in_bin176+ + (1 - mmt) * num_in_bin
177 weights[inds] = tot / self.acc_sum[i]177 weights[inds] = tot / self.acc_sum[i]
178 else:178 else:
179 weights[inds] = tot / num_in_bin179 weights[inds] = tot / num_in_bin
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/mask_heads/fcn_mask_head.py+1-1
@@ -125,7 +125,7 @@ class FCNMaskHead(nn.Module):
125 gt_masks, rcnn_train_cfg)125 gt_masks, rcnn_train_cfg)
126 return mask_targets126 return mask_targets
127 127 
128- @force_fp32(apply_to=('mask_pred', ))128+ @force_fp32(apply_to=('mask_pred',))
129 def loss(self, mask_pred, mask_targets, labels):129 def loss(self, mask_pred, mask_targets, labels):
130 loss = dict()130 loss = dict()
131 if self.class_agnostic:131 if self.class_agnostic:
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/mask_heads/fused_semantic_head.py+1-1
@@ -112,7 +112,7 @@ class FusedSemanticHead(nn.Module):
112 x = self.conv_embedding(x)112 x = self.conv_embedding(x)
113 return mask_pred, x113 return mask_pred, x
114 114 
115- @force_fp32(apply_to=('mask_pred', ))115+ @force_fp32(apply_to=('mask_pred',))
116 def loss(self, mask_pred, labels):116 def loss(self, mask_pred, labels):
117 labels = labels.squeeze(1).long()117 labels = labels.squeeze(1).long()
118 loss_semantic_seg = self.criterion(mask_pred, labels)118 loss_semantic_seg = self.criterion(mask_pred, labels)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/mask_heads/grid_head.py+8-8
@@ -267,7 +267,7 @@ class GridHead(nn.Module):
267 1 - y_idx / (self.grid_size - 1)))267 1 - y_idx / (self.grid_size - 1)))
268 268 
269 radius = rcnn_train_cfg.pos_radius269 radius = rcnn_train_cfg.pos_radius
270- radius2 = radius**2270+ radius2 = radius ** 2
271 for i in range(num_rois):271 for i in range(num_rois):
272 # ignore small bboxes272 # ignore small bboxes
273 if (pos_bbox_ws[i] <= self.grid_size273 if (pos_bbox_ws[i] <= self.grid_size
@@ -277,9 +277,9 @@ class GridHead(nn.Module):
277 for j in range(self.grid_points):277 for j in range(self.grid_points):
278 factor_x, factor_y = factors[j]278 factor_x, factor_y = factors[j]
279 gridpoint_x = factor_x * pos_gt_bboxes[i, 0] + (279 gridpoint_x = factor_x * pos_gt_bboxes[i, 0] + (
280- 1 - factor_x) * pos_gt_bboxes[i, 2]280+ 1 - factor_x) * pos_gt_bboxes[i, 2]
281 gridpoint_y = factor_y * pos_gt_bboxes[i, 1] + (281 gridpoint_y = factor_y * pos_gt_bboxes[i, 1] + (
282- 1 - factor_y) * pos_gt_bboxes[i, 3]282+ 1 - factor_y) * pos_gt_bboxes[i, 3]
283 283 
284 cx = int((gridpoint_x - pos_bboxes[i, 0]) / pos_bbox_ws[i] *284 cx = int((gridpoint_x - pos_bboxes[i, 0]) / pos_bbox_ws[i] *
285 map_size)285 map_size)
@@ -289,7 +289,7 @@ class GridHead(nn.Module):
289 for x in range(cx - radius, cx + radius + 1):289 for x in range(cx - radius, cx + radius + 1):
290 for y in range(cy - radius, cy + radius + 1):290 for y in range(cy - radius, cy + radius + 1):
291 if x >= 0 and x < map_size and y >= 0 and y < map_size:291 if x >= 0 and x < map_size and y >= 0 and y < map_size:
292- if (x - cx)**2 + (y - cy)**2 <= radius2:292+ if (x - cx) ** 2 + (y - cy) ** 2 <= radius2:
293 targets[i, j, y, x] = 1293 targets[i, j, y, x] = 1
294 # reduce the target heatmap size by a half294 # reduce the target heatmap size by a half
295 # proposed in Grid R-CNN Plus (https://arxiv.org/abs/1906.05688).295 # proposed in Grid R-CNN Plus (https://arxiv.org/abs/1906.05688).
@@ -356,16 +356,16 @@ class GridHead(nn.Module):
356 # voting of all grid points on some boundary356 # voting of all grid points on some boundary
357 bboxes_x1 = (abs_xs[:, x1_inds] * pred_scores[:, x1_inds]).sum(357 bboxes_x1 = (abs_xs[:, x1_inds] * pred_scores[:, x1_inds]).sum(
358 dim=1, keepdim=True) / (358 dim=1, keepdim=True) / (
359- pred_scores[:, x1_inds].sum(dim=1, keepdim=True))359+ pred_scores[:, x1_inds].sum(dim=1, keepdim=True))
360 bboxes_y1 = (abs_ys[:, y1_inds] * pred_scores[:, y1_inds]).sum(360 bboxes_y1 = (abs_ys[:, y1_inds] * pred_scores[:, y1_inds]).sum(
361 dim=1, keepdim=True) / (361 dim=1, keepdim=True) / (
362- pred_scores[:, y1_inds].sum(dim=1, keepdim=True))362+ pred_scores[:, y1_inds].sum(dim=1, keepdim=True))
363 bboxes_x2 = (abs_xs[:, x2_inds] * pred_scores[:, x2_inds]).sum(363 bboxes_x2 = (abs_xs[:, x2_inds] * pred_scores[:, x2_inds]).sum(
364 dim=1, keepdim=True) / (364 dim=1, keepdim=True) / (
365- pred_scores[:, x2_inds].sum(dim=1, keepdim=True))365+ pred_scores[:, x2_inds].sum(dim=1, keepdim=True))
366 bboxes_y2 = (abs_ys[:, y2_inds] * pred_scores[:, y2_inds]).sum(366 bboxes_y2 = (abs_ys[:, y2_inds] * pred_scores[:, y2_inds]).sum(
367 dim=1, keepdim=True) / (367 dim=1, keepdim=True) / (
368- pred_scores[:, y2_inds].sum(dim=1, keepdim=True))368+ pred_scores[:, y2_inds].sum(dim=1, keepdim=True))
369 369 
370 bbox_res = torch.cat(370 bbox_res = torch.cat(
371 [bboxes_x1, bboxes_y1, bboxes_x2, bboxes_y2, cls_scores], dim=1)371 [bboxes_x1, bboxes_y1, bboxes_x2, bboxes_y2, cls_scores], dim=1)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/mask_heads/mask_feat_head.py+2-2
@@ -63,7 +63,7 @@ class MaskFeatHead(nn.Module):
63 63 
64 for j in range(i):64 for j in range(i):
65 if j == 0:65 if j == 0:
66- chn = self.in_channels+2 if i==3 else self.in_channels66+ chn = self.in_channels + 2 if i == 3 else self.in_channels
67 one_conv = ConvModule(67 one_conv = ConvModule(
68 chn,68 chn,
69 self.out_channels,69 self.out_channels,
@@ -126,7 +126,7 @@ class MaskFeatHead(nn.Module):
126 x = x.expand([input_feat.shape[0], 1, -1, -1])126 x = x.expand([input_feat.shape[0], 1, -1, -1])
127 coord_feat = torch.cat([x, y], 1)127 coord_feat = torch.cat([x, y], 1)
128 input_p = torch.cat([input_p, coord_feat], 1)128 input_p = torch.cat([input_p, coord_feat], 1)
129- 129+ 
130 feature_add_all_level += self.convs_all_levels[i](input_p)130 feature_add_all_level += self.convs_all_levels[i](input_p)
131 131 
132 feature_pred = self.conv_pred(feature_add_all_level)132 feature_pred = self.conv_pred(feature_add_all_level)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/mask_heads/maskiou_head.py+6-6
@@ -102,7 +102,7 @@ class MaskIoUHead(nn.Module):
102 mask_iou = self.fc_mask_iou(x)102 mask_iou = self.fc_mask_iou(x)
103 return mask_iou103 return mask_iou
104 104 
105- @force_fp32(apply_to=('mask_iou_pred', ))105+ @force_fp32(apply_to=('mask_iou_pred',))
106 def loss(self, mask_iou_pred, mask_iou_targets):106 def loss(self, mask_iou_pred, mask_iou_targets):
107 pos_inds = mask_iou_targets > 0107 pos_inds = mask_iou_targets > 0
108 if pos_inds.sum() > 0:108 if pos_inds.sum() > 0:
@@ -112,7 +112,7 @@ class MaskIoUHead(nn.Module):
112 loss_mask_iou = mask_iou_pred * 0112 loss_mask_iou = mask_iou_pred * 0
113 return dict(loss_mask_iou=loss_mask_iou)113 return dict(loss_mask_iou=loss_mask_iou)
114 114 
115- @force_fp32(apply_to=('mask_pred', ))115+ @force_fp32(apply_to=('mask_pred',))
116 def get_target(self, sampling_results, gt_masks, mask_pred, mask_targets,116 def get_target(self, sampling_results, gt_masks, mask_pred, mask_targets,
117 rcnn_train_cfg):117 rcnn_train_cfg):
118 """Compute target of mask IoU.118 """Compute target of mask IoU.
@@ -159,7 +159,7 @@ class MaskIoUHead(nn.Module):
159 gt_full_areas = mask_targets.sum((-1, -2)) / (area_ratios + 1e-7)159 gt_full_areas = mask_targets.sum((-1, -2)) / (area_ratios + 1e-7)
160 160 
161 mask_iou_targets = overlap_areas / (161 mask_iou_targets = overlap_areas / (
162- mask_pred_areas + gt_full_areas - overlap_areas)162+ mask_pred_areas + gt_full_areas - overlap_areas)
163 return mask_iou_targets163 return mask_iou_targets
164 164 
165 def _get_area_ratio(self, pos_proposals, pos_assigned_gt_inds, gt_masks):165 def _get_area_ratio(self, pos_proposals, pos_assigned_gt_inds, gt_masks):
@@ -180,15 +180,15 @@ class MaskIoUHead(nn.Module):
180 gt_mask_in_proposal = gt_mask[y1:y2 + 1, x1:x2 + 1]180 gt_mask_in_proposal = gt_mask[y1:y2 + 1, x1:x2 + 1]
181 181 
182 ratio = gt_mask_in_proposal.sum() / (182 ratio = gt_mask_in_proposal.sum() / (
183- gt_instance_mask_area[pos_assigned_gt_inds[i]] + 1e-7)183+ gt_instance_mask_area[pos_assigned_gt_inds[i]] + 1e-7)
184 area_ratios.append(ratio)184 area_ratios.append(ratio)
185 area_ratios = torch.from_numpy(np.stack(area_ratios)).float().to(185 area_ratios = torch.from_numpy(np.stack(area_ratios)).float().to(
186 pos_proposals.device)186 pos_proposals.device)
187 else:187 else:
188- area_ratios = pos_proposals.new_zeros((0, ))188+ area_ratios = pos_proposals.new_zeros((0,))
189 return area_ratios189 return area_ratios
190 190 
191- @force_fp32(apply_to=('mask_iou_pred', ))191+ @force_fp32(apply_to=('mask_iou_pred',))
192 def get_mask_scores(self, mask_iou_pred, det_bboxes, det_labels):192 def get_mask_scores(self, mask_iou_pred, det_bboxes, det_labels):
193 """Get the mask scores.193 """Get the mask scores.
194 194 
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/necks/hrfpn.py+2-2
@@ -94,7 +94,7 @@ class HRFPN(nn.Module):
94 outs = [inputs[0]]94 outs = [inputs[0]]
95 for i in range(1, self.num_ins):95 for i in range(1, self.num_ins):
96 outs.append(96 outs.append(
97- F.interpolate(inputs[i], scale_factor=2**i, mode='bilinear'))97+ F.interpolate(inputs[i], scale_factor=2 ** i, mode='bilinear'))
98 out = torch.cat(outs, dim=1)98 out = torch.cat(outs, dim=1)
99 if out.requires_grad and self.with_cp:99 if out.requires_grad and self.with_cp:
100 out = checkpoint(self.reduction_conv, out)100 out = checkpoint(self.reduction_conv, out)
@@ -102,7 +102,7 @@ class HRFPN(nn.Module):
102 out = self.reduction_conv(out)102 out = self.reduction_conv(out)
103 outs = [out]103 outs = [out]
104 for i in range(1, self.num_outs):104 for i in range(1, self.num_outs):
105- outs.append(self.pooling(out, kernel_size=2**i, stride=2**i))105+ outs.append(self.pooling(out, kernel_size=2 ** i, stride=2 ** i))
106 outputs = []106 outputs = []
107 107 
108 for i in range(self.num_outs):108 for i in range(self.num_outs):
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/plugins/generalized_attention.py+45-45
@@ -135,15 +135,15 @@ class GeneralizedAttention(nn.Module):
135 for iy in range(max_len):135 for iy in range(max_len):
136 for ix in range(max_len):136 for ix in range(max_len):
137 local_constraint_map[137 local_constraint_map[
138- iy, ix,138+ iy, ix,
139- max((iy - self.spatial_range) //139+ max((iy - self.spatial_range) //
140- self.kv_stride, 0):min((iy + self.spatial_range +140+ self.kv_stride, 0):min((iy + self.spatial_range +
141- 1) // self.kv_stride +141+ 1) // self.kv_stride +
142- 1, max_len),142+ 1, max_len),
143- max((ix - self.spatial_range) //143+ max((ix - self.spatial_range) //
144- self.kv_stride, 0):min((ix + self.spatial_range +144+ self.kv_stride, 0):min((ix + self.spatial_range +
145- 1) // self.kv_stride +145+ 1) // self.kv_stride +
146- 1, max_len)] = 0146+ 1, max_len)] = 0
147 147 
148 self.local_constraint_map = nn.Parameter(148 self.local_constraint_map = nn.Parameter(
149 torch.from_numpy(local_constraint_map).byte(),149 torch.from_numpy(local_constraint_map).byte(),
@@ -196,7 +196,7 @@ class GeneralizedAttention(nn.Module):
196 feat_range = torch.arange(0, feat_dim / 4).cuda(device)196 feat_range = torch.arange(0, feat_dim / 4).cuda(device)
197 197 
198 dim_mat = torch.Tensor([wave_length]).cuda(device)198 dim_mat = torch.Tensor([wave_length]).cuda(device)
199- dim_mat = dim_mat**((4. / feat_dim) * feat_range)199+ dim_mat = dim_mat ** ((4. / feat_dim) * feat_range)
200 dim_mat = dim_mat.view((1, 1, -1))200 dim_mat = dim_mat.view((1, 1, -1))
201 201 
202 embedding_x = torch.cat(202 embedding_x = torch.cat(
@@ -237,15 +237,15 @@ class GeneralizedAttention(nn.Module):
237 h, w, h_kv, w_kv, self.q_stride, self.kv_stride,237 h, w, h_kv, w_kv, self.q_stride, self.kv_stride,
238 x_input.device, self.position_embedding_dim)238 x_input.device, self.position_embedding_dim)
239 # (n, num_heads, w, w_kv, dim)239 # (n, num_heads, w, w_kv, dim)
240- position_feat_x = self.appr_geom_fc_x(position_embed_x).\240+ position_feat_x = self.appr_geom_fc_x(position_embed_x). \
241- view(1, w, w_kv, num_heads, self.qk_embed_dim).\241+ view(1, w, w_kv, num_heads, self.qk_embed_dim). \
242- permute(0, 3, 1, 2, 4).\242+ permute(0, 3, 1, 2, 4). \
243 repeat(n, 1, 1, 1, 1)243 repeat(n, 1, 1, 1, 1)
244 244 
245 # (n, num_heads, h, h_kv, dim)245 # (n, num_heads, h, h_kv, dim)
246- position_feat_y = self.appr_geom_fc_y(position_embed_y).\246+ position_feat_y = self.appr_geom_fc_y(position_embed_y). \
247- view(1, h, h_kv, num_heads, self.qk_embed_dim).\247+ view(1, h, h_kv, num_heads, self.qk_embed_dim). \
248- permute(0, 3, 1, 2, 4).\248+ permute(0, 3, 1, 2, 4). \
249 repeat(n, 1, 1, 1, 1)249 repeat(n, 1, 1, 1, 1)
250 250 
251 position_feat_x /= math.sqrt(2)251 position_feat_x /= math.sqrt(2)
@@ -253,11 +253,11 @@ class GeneralizedAttention(nn.Module):
253 253 
254 # accelerate for saliency only254 # accelerate for saliency only
255 if (np.sum(self.attention_type) == 1) and self.attention_type[2]:255 if (np.sum(self.attention_type) == 1) and self.attention_type[2]:
256- appr_bias = self.appr_bias.\256+ appr_bias = self.appr_bias. \
257- view(1, num_heads, 1, self.qk_embed_dim).\257+ view(1, num_heads, 1, self.qk_embed_dim). \
258 repeat(n, 1, 1, 1)258 repeat(n, 1, 1, 1)
259 259 
260- energy = torch.matmul(appr_bias, proj_key).\260+ energy = torch.matmul(appr_bias, proj_key). \
261 view(n, num_heads, 1, h_kv * w_kv)261 view(n, num_heads, 1, h_kv * w_kv)
262 262 
263 h = 1263 h = 1
@@ -281,35 +281,35 @@ class GeneralizedAttention(nn.Module):
281 # attention_type[3]: bias - position281 # attention_type[3]: bias - position
282 if self.attention_type[0] or self.attention_type[2]:282 if self.attention_type[0] or self.attention_type[2]:
283 if self.attention_type[0] and self.attention_type[2]:283 if self.attention_type[0] and self.attention_type[2]:
284- appr_bias = self.appr_bias.\284+ appr_bias = self.appr_bias. \
285 view(1, num_heads, 1, self.qk_embed_dim)285 view(1, num_heads, 1, self.qk_embed_dim)
286- energy = torch.matmul(proj_query + appr_bias, proj_key).\286+ energy = torch.matmul(proj_query + appr_bias, proj_key). \
287 view(n, num_heads, h, w, h_kv, w_kv)287 view(n, num_heads, h, w, h_kv, w_kv)
288 288 
289 elif self.attention_type[0]:289 elif self.attention_type[0]:
290- energy = torch.matmul(proj_query, proj_key).\290+ energy = torch.matmul(proj_query, proj_key). \
291 view(n, num_heads, h, w, h_kv, w_kv)291 view(n, num_heads, h, w, h_kv, w_kv)
292 292 
293 elif self.attention_type[2]:293 elif self.attention_type[2]:
294- appr_bias = self.appr_bias.\294+ appr_bias = self.appr_bias. \
295- view(1, num_heads, 1, self.qk_embed_dim).\295+ view(1, num_heads, 1, self.qk_embed_dim). \
296 repeat(n, 1, 1, 1)296 repeat(n, 1, 1, 1)
297 297 
298- energy += torch.matmul(appr_bias, proj_key).\298+ energy += torch.matmul(appr_bias, proj_key). \
299 view(n, num_heads, 1, 1, h_kv, w_kv)299 view(n, num_heads, 1, 1, h_kv, w_kv)
300 300 
301 if self.attention_type[1] or self.attention_type[3]:301 if self.attention_type[1] or self.attention_type[3]:
302 if self.attention_type[1] and self.attention_type[3]:302 if self.attention_type[1] and self.attention_type[3]:
303- geom_bias = self.geom_bias.\303+ geom_bias = self.geom_bias. \
304 view(1, num_heads, 1, self.qk_embed_dim)304 view(1, num_heads, 1, self.qk_embed_dim)
305 305 
306- proj_query_reshape = (proj_query + geom_bias).\306+ proj_query_reshape = (proj_query + geom_bias). \
307 view(n, num_heads, h, w, self.qk_embed_dim)307 view(n, num_heads, h, w, self.qk_embed_dim)
308 308 
309 energy_x = torch.matmul(309 energy_x = torch.matmul(
310 proj_query_reshape.permute(0, 1, 3, 2, 4),310 proj_query_reshape.permute(0, 1, 3, 2, 4),
311 position_feat_x.permute(0, 1, 2, 4, 3))311 position_feat_x.permute(0, 1, 2, 4, 3))
312- energy_x = energy_x.\312+ energy_x = energy_x. \
313 permute(0, 1, 3, 2, 4).unsqueeze(4)313 permute(0, 1, 3, 2, 4).unsqueeze(4)
314 314 
315 energy_y = torch.matmul(315 energy_y = torch.matmul(
@@ -320,13 +320,13 @@ class GeneralizedAttention(nn.Module):
320 energy += energy_x + energy_y320 energy += energy_x + energy_y
321 321 
322 elif self.attention_type[1]:322 elif self.attention_type[1]:
323- proj_query_reshape = proj_query.\323+ proj_query_reshape = proj_query. \
324 view(n, num_heads, h, w, self.qk_embed_dim)324 view(n, num_heads, h, w, self.qk_embed_dim)
325- proj_query_reshape = proj_query_reshape.\325+ proj_query_reshape = proj_query_reshape. \
326 permute(0, 1, 3, 2, 4)326 permute(0, 1, 3, 2, 4)
327- position_feat_x_reshape = position_feat_x.\327+ position_feat_x_reshape = position_feat_x. \
328 permute(0, 1, 2, 4, 3)328 permute(0, 1, 2, 4, 3)
329- position_feat_y_reshape = position_feat_y.\329+ position_feat_y_reshape = position_feat_y. \
330 permute(0, 1, 2, 4, 3)330 permute(0, 1, 2, 4, 3)
331 331 
332 energy_x = torch.matmul(proj_query_reshape,332 energy_x = torch.matmul(proj_query_reshape,
@@ -340,14 +340,14 @@ class GeneralizedAttention(nn.Module):
340 energy += energy_x + energy_y340 energy += energy_x + energy_y
341 341 
342 elif self.attention_type[3]:342 elif self.attention_type[3]:
343- geom_bias = self.geom_bias.\343+ geom_bias = self.geom_bias. \
344- view(1, num_heads, self.qk_embed_dim, 1).\344+ view(1, num_heads, self.qk_embed_dim, 1). \
345 repeat(n, 1, 1, 1)345 repeat(n, 1, 1, 1)
346 346 
347- position_feat_x_reshape = position_feat_x.\347+ position_feat_x_reshape = position_feat_x. \
348- view(n, num_heads, w*w_kv, self.qk_embed_dim)348+ view(n, num_heads, w * w_kv, self.qk_embed_dim)
349 349 
350- position_feat_y_reshape = position_feat_y.\350+ position_feat_y_reshape = position_feat_y. \
351 view(n, num_heads, h * h_kv, self.qk_embed_dim)351 view(n, num_heads, h * h_kv, self.qk_embed_dim)
352 352 
353 energy_x = torch.matmul(position_feat_x_reshape, geom_bias)353 energy_x = torch.matmul(position_feat_x_reshape, geom_bias)
@@ -362,9 +362,9 @@ class GeneralizedAttention(nn.Module):
362 362 
363 if self.spatial_range >= 0:363 if self.spatial_range >= 0:
364 cur_local_constraint_map = \364 cur_local_constraint_map = \
365- self.local_constraint_map[:h, :w, :h_kv, :w_kv].\365+ self.local_constraint_map[:h, :w, :h_kv, :w_kv]. \
366- contiguous().\366+ contiguous(). \
367- view(1, 1, h*w, h_kv*w_kv)367+ view(1, 1, h * w, h_kv * w_kv)
368 368 
369 energy = energy.masked_fill_(cur_local_constraint_map,369 energy = energy.masked_fill_(cur_local_constraint_map,
370 float('-inf'))370 float('-inf'))
@@ -372,13 +372,13 @@ class GeneralizedAttention(nn.Module):
372 attention = F.softmax(energy, 3)372 attention = F.softmax(energy, 3)
373 373 
374 proj_value = self.value_conv(x_kv)374 proj_value = self.value_conv(x_kv)
375- proj_value_reshape = proj_value.\375+ proj_value_reshape = proj_value. \
376- view((n, num_heads, self.v_dim, h_kv * w_kv)).\376+ view((n, num_heads, self.v_dim, h_kv * w_kv)). \
377 permute(0, 1, 3, 2)377 permute(0, 1, 3, 2)
378 378 
379- out = torch.matmul(attention, proj_value_reshape).\379+ out = torch.matmul(attention, proj_value_reshape). \
380- permute(0, 1, 3, 2).\380+ permute(0, 1, 3, 2). \
381- contiguous().\381+ contiguous(). \
382 view(n, self.v_dim * self.num_heads, h, w)382 view(n, self.v_dim * self.num_heads, h, w)
383 383 
384 out = self.proj_conv(out)384 out = self.proj_conv(out)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/plugins/non_local.py+1-1
@@ -90,7 +90,7 @@ class NonLocal2D(nn.Module):
90 pairwise_weight = torch.matmul(theta_x, phi_x)90 pairwise_weight = torch.matmul(theta_x, phi_x)
91 if self.use_scale:91 if self.use_scale:
92 # theta_x.shape[-1] is `self.inter_channels`92 # theta_x.shape[-1] is `self.inter_channels`
93- pairwise_weight /= theta_x.shape[-1]**0.593+ pairwise_weight /= theta_x.shape[-1] ** 0.5
94 pairwise_weight = pairwise_weight.softmax(dim=-1)94 pairwise_weight = pairwise_weight.softmax(dim=-1)
95 return pairwise_weight95 return pairwise_weight
96 96 
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/roi_extractors/single_level.py+1-1
@@ -100,7 +100,7 @@ class SingleRoIExtractor(nn.Module):
100 new_rois = torch.stack((rois[:, 0], x1, y1, x2, y2), dim=-1)100 new_rois = torch.stack((rois[:, 0], x1, y1, x2, y2), dim=-1)
101 return new_rois101 return new_rois
102 102 
103- @force_fp32(apply_to=('feats', ), out_fp16=True)103+ @force_fp32(apply_to=('feats',), out_fp16=True)
104 def forward(self, feats, rois, roi_scale_factor=None):104 def forward(self, feats, rois, roi_scale_factor=None):
105 if len(feats) == 1:105 if len(feats) == 1:
106 return self.roi_layers[0](feats[0], rois)106 return self.roi_layers[0](feats[0], rois)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/models/shared_heads/res_layer.py+2-2
@@ -42,8 +42,8 @@ class ResLayer(nn.Module):
42 self.fp16_enabled = False42 self.fp16_enabled = False
43 block, stage_blocks = ResNet.arch_settings[depth]43 block, stage_blocks = ResNet.arch_settings[depth]
44 stage_block = stage_blocks[stage]44 stage_block = stage_blocks[stage]
45- planes = 64 * 2**stage45+ planes = 64 * 2 ** stage
46- inplanes = 64 * 2**(stage - 1) * block.expansion46+ inplanes = 64 * 2 ** (stage - 1) * block.expansion
47 47 
48 res_layer = make_res_layer(48 res_layer = make_res_layer(
49 block,49 block,
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/ops/context_block.py+1-1
@@ -30,7 +30,7 @@ class ContextBlock(nn.Module):
30 inplanes,30 inplanes,
31 ratio,31 ratio,
32 pooling_type='att',32 pooling_type='att',
33- fusion_types=('channel_add', )):33+ fusion_types=('channel_add',)):
34 super(ContextBlock, self).__init__()34 super(ContextBlock, self).__init__()
35 assert pooling_type in ['avg', 'att']35 assert pooling_type in ['avg', 'att']
36 assert isinstance(fusion_types, (list, tuple))36 assert isinstance(fusion_types, (list, tuple))
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/ops/dcn/deform_conv.py+3-1
@@ -18,6 +18,7 @@ from torch.autograd import Function
18from torch.nn.modules.utils import _pair, _single18from torch.nn.modules.utils import _pair, _single
19import math19import math
20 20 
21+ 
21class ModulatedDeformConv2dFunction(Function):22class ModulatedDeformConv2dFunction(Function):
22 23 
23 @staticmethod24 @staticmethod
@@ -198,10 +199,11 @@ class ModulatedDeformConvPack(ModulatedDeformConv2d):
198 self.stride, self.padding, self.dilation,199 self.stride, self.padding, self.dilation,
199 self.groups, self.deformable_groups)200 self.groups, self.deformable_groups)
200 201 
202+ 
201DCNv2 = ModulatedDeformConvPack203DCNv2 = ModulatedDeformConvPack
202 204 
203if __name__ == "__main__":205if __name__ == "__main__":
204- x = torch.randn(2,32,4,4)206+ x = torch.randn(2, 32, 4, 4)
205 model = DCNv2(32, 32, 1)207 model = DCNv2(32, 32, 1)
206 208 
207 torch.npu.set_device(0)209 torch.npu.set_device(0)
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/ops/masked_conv/masked_conv.py+1-1
@@ -69,7 +69,7 @@ class MaskedConv2dFunction(Function):
69 @staticmethod69 @staticmethod
70 @once_differentiable70 @once_differentiable
71 def backward(ctx, grad_output):71 def backward(ctx, grad_output):
72- return (None, ) * 572+ return (None,) * 5
73 73 
74 74 
75masked_conv2d = MaskedConv2dFunction.apply75masked_conv2d = MaskedConv2dFunction.apply
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/ops/nms/nms_wrapper.py+1-0
@@ -15,6 +15,7 @@
15import numpy as np15import numpy as np
16import torch16import torch
17 17 
18+ 
18# from . import nms_cpu, nms_cuda19# from . import nms_cpu, nms_cuda
19# from .soft_nms_cpu import soft_nms_cpu20# from .soft_nms_cpu import soft_nms_cpu
20 21 
MPyTorch/contrib/cv/detection/SOLOv2/mmdet/utils/flops_counter.py+14-16
@@ -82,21 +82,21 @@ def get_model_complexity_info(model,
82 82 
83def flops_to_string(flops, units='GMac', precision=2):83def flops_to_string(flops, units='GMac', precision=2):
84 if units is None:84 if units is None:
85- if flops // 10**9 > 0:85+ if flops // 10 ** 9 > 0:
86- return str(round(flops / 10.**9, precision)) + ' GMac'86+ return str(round(flops / 10. ** 9, precision)) + ' GMac'
87- elif flops // 10**6 > 0:87+ elif flops // 10 ** 6 > 0:
88- return str(round(flops / 10.**6, precision)) + ' MMac'88+ return str(round(flops / 10. ** 6, precision)) + ' MMac'
89- elif flops // 10**3 > 0:89+ elif flops // 10 ** 3 > 0:
90- return str(round(flops / 10.**3, precision)) + ' KMac'90+ return str(round(flops / 10. ** 3, precision)) + ' KMac'
91 else:91 else:
92 return str(flops) + ' Mac'92 return str(flops) + ' Mac'
93 else:93 else:
94 if units == 'GMac':94 if units == 'GMac':
95- return str(round(flops / 10.**9, precision)) + ' ' + units95+ return str(round(flops / 10. ** 9, precision)) + ' ' + units
96 elif units == 'MMac':96 elif units == 'MMac':
97- return str(round(flops / 10.**6, precision)) + ' ' + units97+ return str(round(flops / 10. ** 6, precision)) + ' ' + units
98 elif units == 'KMac':98 elif units == 'KMac':
99- return str(round(flops / 10.**3, precision)) + ' ' + units99+ return str(round(flops / 10. ** 3, precision)) + ' ' + units
100 else:100 else:
101 return str(flops) + ' Mac'101 return str(flops) + ' Mac'
102 102 
@@ -114,10 +114,10 @@ def params_to_string(params_num):
114 >>> params_to_string(3e-9)114 >>> params_to_string(3e-9)
115 '3e-09'115 '3e-09'
116 """116 """
117- if params_num // 10**6 > 0:117+ if params_num // 10 ** 6 > 0:
118- return str(round(params_num / 10**6, 2)) + ' M'118+ return str(round(params_num / 10 ** 6, 2)) + ' M'
119- elif params_num // 10**3:119+ elif params_num // 10 ** 3:
120- return str(round(params_num / 10**3, 2)) + ' k'120+ return str(round(params_num / 10 ** 3, 2)) + ' k'
121 else:121 else:
122 return str(params_num)122 return str(params_num)
123 123 
@@ -237,7 +237,6 @@ def reset_flops_count(self):
237 237 
238 238 
239def add_flops_mask(module, mask):239def add_flops_mask(module, mask):
240- 
241 def add_flops_mask_func(module):240 def add_flops_mask_func(module):
242 if isinstance(module, torch.nn.Conv2d):241 if isinstance(module, torch.nn.Conv2d):
243 module.__mask__ = mask242 module.__mask__ = mask
@@ -319,7 +318,7 @@ def deconv_flops_counter_hook(conv_module, input, output):
319 318 
320 filters_per_channel = out_channels // groups319 filters_per_channel = out_channels // groups
321 conv_per_position_flops = (320 conv_per_position_flops = (
322- kernel_height * kernel_width * in_channels * filters_per_channel)321+ kernel_height * kernel_width * in_channels * filters_per_channel)
323 322 
324 active_elements_count = batch_size * input_height * input_width323 active_elements_count = batch_size * input_height * input_width
325 overall_conv_flops = conv_per_position_flops * active_elements_count324 overall_conv_flops = conv_per_position_flops * active_elements_count
@@ -362,7 +361,6 @@ def conv_flops_counter_hook(conv_module, input, output):
362 bias_flops = 0361 bias_flops = 0
363 362 
364 if conv_module.bias is not None:363 if conv_module.bias is not None:
365- 
366 bias_flops = out_channels * active_elements_count364 bias_flops = out_channels * active_elements_count
367 365 
368 overall_flops = overall_conv_flops + bias_flops366 overall_flops = overall_conv_flops + bias_flops
MPyTorch/contrib/cv/detection/SOLOv2/paddlepaddle/__init__.py+1-1
@@ -15,4 +15,4 @@
15# Author: Acer Zhang15# Author: Acer Zhang
16# Datetime: 2021/9/1 16# Datetime: 2021/9/1
17# Copyright belongs to the author.17# Copyright belongs to the author.
18-# Please indicate the source for reprinting.18+# Please indicate the source for reprinting.
MPyTorch/contrib/cv/detection/SOLOv2/setup.py+1-3
@@ -12,7 +12,7 @@
12# See the License for the specific language governing permissions and12# See the License for the specific language governing permissions and
13# limitations under the License.13# limitations under the License.
14 14 
15-#!/usr/bin/env python15+# !/usr/bin/env python
16# -*- coding: utf-8 -*-16# -*- coding: utf-8 -*-
17import os17import os
18import platform18import platform
@@ -48,7 +48,6 @@ version_file = 'mmdet/version.py'
48 48 
49 49 
50def get_git_hash():50def get_git_hash():
51- 
52 def _minimal_ext_cmd(cmd):51 def _minimal_ext_cmd(cmd):
53 # construct minimal environment52 # construct minimal environment
54 env = {}53 env = {}
@@ -131,7 +130,6 @@ def make_cuda_ext(name, module, sources):
131 define_macros=define_macros,130 define_macros=define_macros,
132 extra_compile_args=extra_compile_args)131 extra_compile_args=extra_compile_args)
133 132 
134- 
135 # define_macros = []133 # define_macros = []
136 # extra_compile_args = {'cxx': []}134 # extra_compile_args = {'cxx': []}
137 #135 #
MPyTorch/contrib/cv/detection/SOLOv2/test/train_eval_1p.sh+2-2
@@ -11,7 +11,7 @@ batch_size=1
11# 训练使用的npu卡数11# 训练使用的npu卡数
12export RANK_SIZE=112export RANK_SIZE=1
13data_path=""13data_path=""
14-MODEL="./work_dirs/solov2_release_r50_fpn_8gpu_1x/latest.pth"14+MODEL="./work_dirs/solov2_release_r50_fpn_8gpu_1x/epoch_12.pth"
15device_id=015device_id=0
16 16 
17#参数校验,不需要修改17#参数校验,不需要修改
@@ -70,7 +70,7 @@ end_time=$(date +%s)
70e2e_time=$(( $end_time - $start_time ))70e2e_time=$(( $end_time - $start_time ))
71 71 
72# 输出训练精度,需要模型审视修改 # eval.log | awk -F ',' '{print $1}' | awk '{print $2}' | awk ' END {print}'72# 输出训练精度,需要模型审视修改 # eval.log | awk -F ',' '{print $1}' | awk '{print $2}' | awk ' END {print}'
73-train_accuracy=`grep -a 'maxDets' $cur_path/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $13}'|head -n 1`73+train_accuracy=`grep -a 'maxDets' $cur_path/output/${ASCEND_DEVICE_ID}/eval_${ASCEND_DEVICE_ID}.log|awk -F " " '{print $13}'|head -n 1`
74# 打印,不需要修改74# 打印,不需要修改
75echo "Final Train Accuracy : ${train_accuracy}"75echo "Final Train Accuracy : ${train_accuracy}"
76echo "E2E Training Duration sec : $e2e_time"76echo "E2E Training Duration sec : $e2e_time"
MPyTorch/contrib/cv/detection/SOLOv2/test/train_full_1p.sh+1-1
@@ -14,7 +14,7 @@ Network="SOLOv2"
14 14 
15#训练batch_size,,需要模型审视修改15#训练batch_size,,需要模型审视修改
16batch_size=216batch_size=2
17-device_id=117+device_id=0
18 18 
19#参数校验,不需要修改19#参数校验,不需要修改
20for para in $*20for para in $*
MPyTorch/contrib/cv/detection/SOLOv2/test/train_full_8p.sh+1-1
@@ -14,7 +14,7 @@ Network="SOLOv2"
14 14 
15#训练batch_size,,需要模型审视修改15#训练batch_size,,需要模型审视修改
16batch_size=1616batch_size=16
17-device_id=117+device_id=0
18 18 
19#参数校验,不需要修改19#参数校验,不需要修改
20for para in $*20for para in $*
MPyTorch/contrib/cv/detection/SOLOv2/test/train_performance_1p.sh+2-5
@@ -14,7 +14,7 @@ Network="SOLOv2"
14 14 
15#训练batch_size,,需要模型审视修改15#训练batch_size,,需要模型审视修改
16batch_size=216batch_size=2
17-device_id=117+device_id=0
18 18 
19#参数校验,不需要修改19#参数校验,不需要修改
20for para in $*20for para in $*
@@ -68,10 +68,7 @@ fi
68export NPUID=068export NPUID=0
69export RANK=069export RANK=0
70python3.7 tools/train.py configs/solov2/solov2_r50_fpn_8gpu_1x.py --opt-level $apex --autoscale-lr --seed 0 --total_epochs 1 \70python3.7 tools/train.py configs/solov2/solov2_r50_fpn_8gpu_1x.py --opt-level $apex --autoscale-lr --seed 0 --total_epochs 1 \
71- --data_root=$data_path --gpu-ids 0 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &71+ --data_root=$data_path --gpu-ids 0 --train_performance=True > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
72-wait
73-python3.7 tools/test_ins.py configs/solov2/solov2_r50_fpn_8gpu_1x.py work_dirs/solov2_release_r50_fpn_8gpu_1x/latest.pth --show \
74- --out results_solo.pkl --eval segm --data_root=$data_path >> ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
75wait72wait
76 73 
77#训练结束时间,不需要修改74#训练结束时间,不需要修改
MPyTorch/contrib/cv/detection/SOLOv2/test/train_performance_8p.sh+3-6
@@ -14,7 +14,7 @@ Network="SOLOv2"
14 14 
15#训练batch_size,,需要模型审视修改15#训练batch_size,,需要模型审视修改
16batch_size=1616batch_size=16
17-device_id=117+device_id=0
18 18 
19#参数校验,不需要修改19#参数校验,不需要修改
20for para in $*20for para in $*
@@ -82,7 +82,7 @@ do
82 --gpus 8 \82 --gpus 8 \
83 --autoscale-lr \83 --autoscale-lr \
84 --seed 0 \84 --seed 0 \
85- --data_root=$data_path \85+ --data_root=$data_path --train_performance=True \
86 --total_epochs 1 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &86 --total_epochs 1 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
87 else87 else
88 python3.7 ./tools/train.py configs/solov2/solov2_r50_fpn_8gpu_1x.py \88 python3.7 ./tools/train.py configs/solov2/solov2_r50_fpn_8gpu_1x.py \
@@ -91,14 +91,11 @@ do
91 --gpus 8 \91 --gpus 8 \
92 --autoscale-lr \92 --autoscale-lr \
93 --seed 0 \93 --seed 0 \
94- --data_root=$data_path \94+ --data_root=$data_path --train_performance=True \
95 --total_epochs 1 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &95 --total_epochs 1 > ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
96 fi96 fi
97done97done
98wait98wait
99-python3.7 tools/test_ins.py configs/solov2/solov2_r50_fpn_8gpu_1x.py work_dirs/solov2_release_r50_fpn_8gpu_1x/latest.pth --show \
100- --out results_solo.pkl --eval segm --data_root=$data_path >> ${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
101-wait
102#训练结束时间,不需要修改99#训练结束时间,不需要修改
103end_time=$(date +%s)100end_time=$(date +%s)
104e2e_time=$(( $end_time - $start_time ))101e2e_time=$(( $end_time - $start_time ))
MPyTorch/contrib/cv/detection/SOLOv2/tests/test_assigner.py+1-1
@@ -118,7 +118,7 @@ def test_max_iou_assigner_with_empty_boxes():
118 # Test with gt_labels118 # Test with gt_labels
119 assign_result = self.assign(bboxes, gt_bboxes, gt_labels=gt_labels)119 assign_result = self.assign(bboxes, gt_bboxes, gt_labels=gt_labels)
120 assert len(assign_result.gt_inds) == 0120 assert len(assign_result.gt_inds) == 0
121- assert tuple(assign_result.labels.shape) == (0, )121+ assert tuple(assign_result.labels.shape) == (0,)
122 122 
123 # Test without gt_labels123 # Test without gt_labels
124 assign_result = self.assign(bboxes, gt_bboxes, gt_labels=None)124 assign_result = self.assign(bboxes, gt_bboxes, gt_labels=None)
MPyTorch/contrib/cv/detection/SOLOv2/tests/test_async.py+0-1
@@ -73,7 +73,6 @@ class MaskRCNNDetector:
73 73 
74 74 
75class AsyncInferenceTestCase(AsyncTestCase):75class AsyncInferenceTestCase(AsyncTestCase):
76- 
77 if sys.version_info >= (3, 7):76 if sys.version_info >= (3, 7):
78 77 
79 async def test_simple_inference(self):78 async def test_simple_inference(self):
MPyTorch/contrib/cv/detection/SOLOv2/tests/test_heads.py+5-5
@@ -54,7 +54,7 @@ def test_anchor_head_loss():
54 54 
55 # Anchor head expects a multiple levels of features per image55 # Anchor head expects a multiple levels of features per image
56 feat = [56 feat = [
57- torch.rand(1, 1, s // (2**(i + 2)), s // (2**(i + 2)))57+ torch.rand(1, 1, s // (2 ** (i + 2)), s // (2 ** (i + 2)))
58 for i in range(len(self.anchor_generators))58 for i in range(len(self.anchor_generators))
59 ]59 ]
60 cls_scores, bbox_preds = self.forward(feat)60 cls_scores, bbox_preds = self.forward(feat)
@@ -330,14 +330,14 @@ def _demodata_refine_boxes(n_roi, n_img, rng=0):
330 roi_boxes = random_boxes(n_roi, scale=scale, rng=rng)330 roi_boxes = random_boxes(n_roi, scale=scale, rng=rng)
331 if n_img == 0:331 if n_img == 0:
332 assert n_roi == 0, 'cannot have any rois if there are no images'332 assert n_roi == 0, 'cannot have any rois if there are no images'
333- img_ids = torch.empty((0, ), dtype=torch.long)333+ img_ids = torch.empty((0,), dtype=torch.long)
334 roi_boxes = torch.empty((0, 4), dtype=torch.float32)334 roi_boxes = torch.empty((0, 4), dtype=torch.float32)
335 else:335 else:
336- img_ids = rng.randint(0, n_img, (n_roi, ))336+ img_ids = rng.randint(0, n_img, (n_roi,))
337 img_ids = torch.from_numpy(img_ids)337 img_ids = torch.from_numpy(img_ids)
338 rois = torch.cat([img_ids[:, None].float(), roi_boxes], dim=1)338 rois = torch.cat([img_ids[:, None].float(), roi_boxes], dim=1)
339 # Create other args339 # Create other args
340- labels = rng.randint(0, 2, (n_roi, ))340+ labels = rng.randint(0, 2, (n_roi,))
341 labels = torch.from_numpy(labels).long()341 labels = torch.from_numpy(labels).long()
342 bbox_preds = random_boxes(n_roi, scale=scale, rng=rng)342 bbox_preds = random_boxes(n_roi, scale=scale, rng=rng)
343 # For each image, pretend random positive boxes are gts343 # For each image, pretend random positive boxes are gts
@@ -346,7 +346,7 @@ def _demodata_refine_boxes(n_roi, n_img, rng=0):
346 pos_per_img = [sum(lbl_per_img.get(gid, [])) for gid in range(n_img)]346 pos_per_img = [sum(lbl_per_img.get(gid, [])) for gid in range(n_img)]
347 # randomly generate with numpy then sort with torch347 # randomly generate with numpy then sort with torch
348 _pos_is_gts = [348 _pos_is_gts = [
349- rng.randint(0, 2, (npos, )).astype(np.uint8) for npos in pos_per_img349+ rng.randint(0, 2, (npos,)).astype(np.uint8) for npos in pos_per_img
350 ]350 ]
351 pos_is_gts = [351 pos_is_gts = [
352 torch.from_numpy(p).sort(descending=True)[0] for p in _pos_is_gts352 torch.from_numpy(p).sort(descending=True)[0] for p in _pos_is_gts
MPyTorch/contrib/cv/detection/SOLOv2/tests/test_sampler.py+3-5
@@ -124,7 +124,6 @@ def _context_for_ohem():
124 124 
125 125 
126def test_ohem_sampler():126def test_ohem_sampler():
127- 
128 assigner = MaxIoUAssigner(127 assigner = MaxIoUAssigner(
129 pos_iou_thr=0.5,128 pos_iou_thr=0.5,
130 neg_iou_thr=0.5,129 neg_iou_thr=0.5,
@@ -160,7 +159,7 @@ def test_ohem_sampler():
160 neg_pos_ub=-1,159 neg_pos_ub=-1,
161 add_gt_as_proposals=True)160 add_gt_as_proposals=True)
162 161 
163- feats = [torch.rand(1, 256, int(2**i), int(2**i)) for i in [6, 5, 4, 3, 2]]162+ feats = [torch.rand(1, 256, int(2 ** i), int(2 ** i)) for i in [6, 5, 4, 3, 2]]
164 sample_result = sampler.sample(163 sample_result = sampler.sample(
165 assign_result, bboxes, gt_bboxes, gt_labels, feats=feats)164 assign_result, bboxes, gt_bboxes, gt_labels, feats=feats)
166 165 
@@ -169,7 +168,6 @@ def test_ohem_sampler():
169 168 
170 169 
171def test_ohem_sampler_empty_gt():170def test_ohem_sampler_empty_gt():
172- 
173 assigner = MaxIoUAssigner(171 assigner = MaxIoUAssigner(
174 pos_iou_thr=0.5,172 pos_iou_thr=0.5,
175 neg_iou_thr=0.5,173 neg_iou_thr=0.5,
@@ -200,7 +198,7 @@ def test_ohem_sampler_empty_gt():
200 neg_pos_ub=-1,198 neg_pos_ub=-1,
201 add_gt_as_proposals=True)199 add_gt_as_proposals=True)
202 200 
203- feats = [torch.rand(1, 256, int(2**i), int(2**i)) for i in [6, 5, 4, 3, 2]]201+ feats = [torch.rand(1, 256, int(2 ** i), int(2 ** i)) for i in [6, 5, 4, 3, 2]]
204 202 
205 sample_result = sampler.sample(203 sample_result = sampler.sample(
206 assign_result, bboxes, gt_bboxes, gt_labels, feats=feats)204 assign_result, bboxes, gt_bboxes, gt_labels, feats=feats)
@@ -240,7 +238,7 @@ def test_ohem_sampler_empty_pred():
240 neg_pos_ub=-1,238 neg_pos_ub=-1,
241 add_gt_as_proposals=True)239 add_gt_as_proposals=True)
242 240 
243- feats = [torch.rand(1, 256, int(2**i), int(2**i)) for i in [6, 5, 4, 3, 2]]241+ feats = [torch.rand(1, 256, int(2 ** i), int(2 ** i)) for i in [6, 5, 4, 3, 2]]
244 242 
245 sample_result = sampler.sample(243 sample_result = sampler.sample(
246 assign_result, bboxes, gt_bboxes, gt_labels, feats=feats)244 assign_result, bboxes, gt_bboxes, gt_labels, feats=feats)
MPyTorch/contrib/cv/detection/SOLOv2/tools/analyze_logs.py+1-1
@@ -146,7 +146,7 @@ def add_time_parser(subparsers):
146 '--include-outliers',146 '--include-outliers',
147 action='store_true',147 action='store_true',
148 help='include the first value of every epoch when computing '148 help='include the first value of every epoch when computing '
149- 'the average time')149+ 'the average time')
150 150 
151 151 
152def parse_args():152def parse_args():
MPyTorch/contrib/cv/detection/SOLOv2/tools/convert_datasets/pascal_voc.py+2-2
@@ -54,13 +54,13 @@ def parse_xml(args):
54 labels.append(label)54 labels.append(label)
55 if not bboxes:55 if not bboxes:
56 bboxes = np.zeros((0, 4))56 bboxes = np.zeros((0, 4))
57- labels = np.zeros((0, ))57+ labels = np.zeros((0,))
58 else:58 else:
59 bboxes = np.array(bboxes, ndmin=2) - 159 bboxes = np.array(bboxes, ndmin=2) - 1
60 labels = np.array(labels)60 labels = np.array(labels)
61 if not bboxes_ignore:61 if not bboxes_ignore:
62 bboxes_ignore = np.zeros((0, 4))62 bboxes_ignore = np.zeros((0, 4))
63- labels_ignore = np.zeros((0, ))63+ labels_ignore = np.zeros((0,))
64 else:64 else:
65 bboxes_ignore = np.array(bboxes_ignore, ndmin=2) - 165 bboxes_ignore = np.array(bboxes_ignore, ndmin=2) - 1
66 labels_ignore = np.array(labels_ignore)66 labels_ignore = np.array(labels_ignore)
MPyTorch/contrib/cv/detection/SOLOv2/tools/dist_test.sh+1-1
@@ -14,7 +14,7 @@
14 14 
15#!/usr/bin/env bash15#!/usr/bin/env bash
16 16 
17-PYTHON=${PYTHON:-"python"}17+PYTHON=${PYTHON:-"python3.7"}
18 18 
19CONFIG=$119CONFIG=$1
20CHECKPOINT=$220CHECKPOINT=$2
MPyTorch/contrib/cv/detection/SOLOv2/tools/get_flops.py+2-3
@@ -34,13 +34,12 @@ def parse_args():
34 34 
35 35 
36def main():36def main():
37- 
38 args = parse_args()37 args = parse_args()
39 38 
40 if len(args.shape) == 1:39 if len(args.shape) == 1:
41 input_shape = (3, args.shape[0], args.shape[0])40 input_shape = (3, args.shape[0], args.shape[0])
42 elif len(args.shape) == 2:41 elif len(args.shape) == 2:
43- input_shape = (3, ) + tuple(args.shape)42+ input_shape = (3,) + tuple(args.shape)
44 else:43 else:
45 raise ValueError('invalid input shape')44 raise ValueError('invalid input shape')
46 45 
@@ -54,7 +53,7 @@ def main():
54 else:53 else:
55 raise NotImplementedError(54 raise NotImplementedError(
56 'FLOPs counter is currently not currently supported with {}'.55 'FLOPs counter is currently not currently supported with {}'.
57- format(model.__class__.__name__))56+ format(model.__class__.__name__))
58 57 
59 flops, params = get_model_complexity_info(model, input_shape)58 flops, params = get_model_complexity_info(model, input_shape)
60 split_line = '=' * 3059 split_line = '=' * 30
MPyTorch/contrib/cv/detection/SOLOv2/tools/robustness_eval.py+1-5
@@ -20,7 +20,6 @@ import numpy as np
20 20 
21 21 
22def print_coco_results(results):22def print_coco_results(results):
23- 
24 def _print(result, ap=1, iouThr=None, areaRng='all', maxDets=100):23 def _print(result, ap=1, iouThr=None, areaRng='all', maxDets=100):
25 iStr = ' {:<18} {} @[ IoU={:<9} | \24 iStr = ' {:<18} {} @[ IoU={:<9} | \
26 area={:>6s} | maxDets={:>3d} ] = {:0.3f}'25 area={:>6s} | maxDets={:>3d} ] = {:0.3f}'
@@ -31,7 +30,7 @@ def print_coco_results(results):
31 if iouThr is None else '{:0.2f}'.format(iouThr)30 if iouThr is None else '{:0.2f}'.format(iouThr)
32 print(iStr.format(titleStr, typeStr, iouStr, areaRng, maxDets, result))31 print(iStr.format(titleStr, typeStr, iouStr, areaRng, maxDets, result))
33 32 
34- stats = np.zeros((12, ))33+ stats = np.zeros((12,))
35 stats[0] = _print(results[0], 1)34 stats[0] = _print(results[0], 1)
36 stats[1] = _print(results[1], 1, iouThr=.5)35 stats[1] = _print(results[1], 1, iouThr=.5)
37 stats[2] = _print(results[2], 1, iouThr=.75)36 stats[2] = _print(results[2], 1, iouThr=.75)
@@ -51,7 +50,6 @@ def get_coco_style_results(filename,
51 metric=None,50 metric=None,
52 prints='mPC',51 prints='mPC',
53 aggregate='benchmark'):52 aggregate='benchmark'):
54- 
55 assert aggregate in ['benchmark', 'all']53 assert aggregate in ['benchmark', 'all']
56 54 
57 if prints == 'all':55 if prints == 'all':
@@ -127,7 +125,6 @@ def get_coco_style_results(filename,
127 125 
128 126 
129def get_voc_style_results(filename, prints='mPC', aggregate='benchmark'):127def get_voc_style_results(filename, prints='mPC', aggregate='benchmark'):
130- 
131 assert aggregate in ['benchmark', 'all']128 assert aggregate in ['benchmark', 'all']
132 129 
133 if prints == 'all':130 if prints == 'all':
@@ -201,7 +198,6 @@ def get_results(filename,
201 198 
202 199 
203def get_distortions_from_file(filename):200def get_distortions_from_file(filename):
204- 
205 eval_output = mmcv.load(filename)201 eval_output = mmcv.load(filename)
206 202 
207 return get_distortions_from_results(eval_output)203 return get_distortions_from_results(eval_output)
MPyTorch/contrib/cv/detection/SOLOv2/tools/test.py+1-1
@@ -98,7 +98,7 @@ def collect_results_cpu(result_part, size, tmpdir=None):
98 if tmpdir is None:98 if tmpdir is None:
99 MAX_LEN = 51299 MAX_LEN = 512
100 # 32 is whitespace100 # 32 is whitespace
101- dir_tensor = torch.full((MAX_LEN, ),101+ dir_tensor = torch.full((MAX_LEN,),
102 32,102 32,
103 dtype=torch.uint8,103 dtype=torch.uint8,
104 device='cuda')104 device='cuda')
MPyTorch/contrib/cv/detection/SOLOv2/tools/test_ins.py+125-17
@@ -15,15 +15,23 @@
15import argparse15import argparse
16import os16import os
17import os.path as osp17import os.path as osp
18+import pickle
18import shutil19import shutil
19import tempfile20import tempfile
20 21 
21import mmcv22import mmcv
23+import apex
24+import time
25+from apex import amp
22import torch26import torch
27+ 
28+if torch.__version__ >= '1.8.1':
29+ import torch_npu
23import torch.nn.functional as F30import torch.nn.functional as F
24import torch.distributed as dist31import torch.distributed as dist
25from mmcv.parallel import MMDataParallel, MMDistributedDataParallel32from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
26from mmcv.runner import init_dist, get_dist_info, load_checkpoint33from mmcv.runner import init_dist, get_dist_info, load_checkpoint
34+from mmcv.runner import DistSamplerSeedHook, Runner, obj_from_dict
27 35 
28from mmdet.core import coco_eval, results2json, results2json_segm, wrap_fp16_model, tensor2imgs, get_classes36from mmdet.core import coco_eval, results2json, results2json_segm, wrap_fp16_model, tensor2imgs, get_classes
29from mmdet.datasets import build_dataloader, build_dataset37from mmdet.datasets import build_dataloader, build_dataset
@@ -65,7 +73,7 @@ def single_gpu_test(model, data_loader, show=False, verbose=True):
65 seg_result = model(return_loss=False, rescale=not show, **data)73 seg_result = model(return_loss=False, rescale=not show, **data)
66 result = get_masks(seg_result, num_classes=num_classes)74 result = get_masks(seg_result, num_classes=num_classes)
67 results.append(result)75 results.append(result)
68- 76+ 
69 batch_size = data['img'][0].size(0)77 batch_size = data['img'][0].size(0)
70 for _ in range(batch_size):78 for _ in range(batch_size):
71 prog_bar.update()79 prog_bar.update()
@@ -80,10 +88,13 @@ def multi_gpu_test(model, data_loader, tmpdir=None):
80 88 
81 rank, world_size = get_dist_info()89 rank, world_size = get_dist_info()
82 if rank == 0:90 if rank == 0:
83- prog_bar = mmcv.ProgressBar(len(dataset))91+ prog_bar = mmcv.ProgressBar(16)
84 for i, data in enumerate(data_loader):92 for i, data in enumerate(data_loader):
93+ if i >= 2:
94+ break
85 with torch.no_grad():95 with torch.no_grad():
86 seg_result = model(return_loss=False, rescale=True, **data)96 seg_result = model(return_loss=False, rescale=True, **data)
97+ torch.npu.synchronize()
87 result = get_masks(seg_result, num_classes=num_classes)98 result = get_masks(seg_result, num_classes=num_classes)
88 results.append(result)99 results.append(result)
89 100 
@@ -93,7 +104,7 @@ def multi_gpu_test(model, data_loader, tmpdir=None):
93 prog_bar.update()104 prog_bar.update()
94 105 
95 # collect results from all ranks106 # collect results from all ranks
96- results = collect_results(results, len(dataset), tmpdir)107+ results = collect_results(results, 16, tmpdir)
97 108 
98 return results109 return results
99 110 
@@ -104,14 +115,14 @@ def collect_results(result_part, size, tmpdir=None):
104 if tmpdir is None:115 if tmpdir is None:
105 MAX_LEN = 512116 MAX_LEN = 512
106 # 32 is whitespace117 # 32 is whitespace
107- dir_tensor = torch.full((MAX_LEN, ),118+ dir_tensor = torch.full((MAX_LEN,),
108 32,119 32,
109 dtype=torch.uint8,120 dtype=torch.uint8,
110- device='cuda')121+ device='npu')
111 if rank == 0:122 if rank == 0:
112 tmpdir = tempfile.mkdtemp()123 tmpdir = tempfile.mkdtemp()
113 tmpdir = torch.tensor(124 tmpdir = torch.tensor(
114- bytearray(tmpdir.encode()), dtype=torch.uint8, device='cuda')125+ bytearray(tmpdir.encode()), dtype=torch.uint8, device='npu')
115 dir_tensor[:len(tmpdir)] = tmpdir126 dir_tensor[:len(tmpdir)] = tmpdir
116 dist.broadcast(dir_tensor, 0)127 dist.broadcast(dir_tensor, 0)
117 tmpdir = dir_tensor.cpu().numpy().tobytes().decode().rstrip()128 tmpdir = dir_tensor.cpu().numpy().tobytes().decode().rstrip()
@@ -179,19 +190,104 @@ def parse_args():
179 return args190 return args
180 191 
181 192 
193+def build_optimizer(model, optimizer_cfg):
194+ """Build optimizer from configs.
195+ 
196+ Args:
197+ model (:obj:`nn.Module`): The model with parameters to be optimized.
198+ optimizer_cfg (dict): The config dict of the optimizer.
199+ Positional fields are:
200+ - type: class name of the optimizer.
201+ - lr: base learning rate.
202+ Optional fields are:
203+ - any arguments of the corresponding optimizer type, e.g.,
204+ weight_decay, momentum, etc.
205+ - paramwise_options: a dict with 3 accepted fileds
206+ (bias_lr_mult, bias_decay_mult, norm_decay_mult).
207+ `bias_lr_mult` and `bias_decay_mult` will be multiplied to
208+ the lr and weight decay respectively for all bias parameters
209+ (except for the normalization layers), and
210+ `norm_decay_mult` will be multiplied to the weight decay
211+ for all weight and bias parameters of normalization layers.
212+ 
213+ Returns:
214+ torch.optim.Optimizer: The initialized optimizer.
215+ 
216+ Example:
217+ >>> model = torch.nn.modules.Conv1d(1, 1, 1)
218+ >>> optimizer_cfg = dict(type='SGD', lr=0.01, momentum=0.9,
219+ >>> weight_decay=0.0001)
220+ >>> optimizer = build_optimizer(model, optimizer_cfg)
221+ """
222+ if hasattr(model, 'module'):
223+ model = model.module
224+ 
225+ optimizer_cfg = optimizer_cfg.copy()
226+ paramwise_options = optimizer_cfg.pop('paramwise_options', None)
227+ # if no paramwise option is specified, just use the global setting
228+ if paramwise_options is None:
229+ return obj_from_dict(optimizer_cfg, torch.optim,
230+ dict(params=model.parameters()))
231+ else:
232+ assert isinstance(paramwise_options, dict)
233+ # get base lr and weight decay
234+ base_lr = optimizer_cfg['lr']
235+ base_wd = optimizer_cfg.get('weight_decay', None)
236+ # weight_decay must be explicitly specified if mult is specified
237+ if ('bias_decay_mult' in paramwise_options
238+ or 'norm_decay_mult' in paramwise_options):
239+ assert base_wd is not None
240+ # get param-wise options
241+ bias_lr_mult = paramwise_options.get('bias_lr_mult', 1.)
242+ bias_decay_mult = paramwise_options.get('bias_decay_mult', 1.)
243+ norm_decay_mult = paramwise_options.get('norm_decay_mult', 1.)
244+ # set param-wise lr and weight decay
245+ params = []
246+ for name, param in model.named_parameters():
247+ param_group = {'params': [param]}
248+ if not param.requires_grad:
249+ # FP16 training needs to copy gradient/weight between master
250+ # weight copy and model weight, it is convenient to keep all
251+ # parameters here to align with model.parameters()
252+ params.append(param_group)
253+ continue
254+ 
255+ # for norm layers, overwrite the weight decay of weight and bias
256+ # TODO: obtain the norm layer prefixes dynamically
257+ if re.search(r'(bn|gn)(\d+)?.(weight|bias)', name):
258+ if base_wd is not None:
259+ param_group['weight_decay'] = base_wd * norm_decay_mult
260+ # for other layers, overwrite both lr and weight decay of bias
261+ elif name.endswith('.bias'):
262+ param_group['lr'] = base_lr * bias_lr_mult
263+ if base_wd is not None:
264+ param_group['weight_decay'] = base_wd * bias_decay_mult
265+ # otherwise use the global settings
266+ 
267+ params.append(param_group)
268+ 
269+ optimizer_cls = getattr(torch.optim, optimizer_cfg.pop('type'))
270+ return optimizer_cls(params, **optimizer_cfg)
271+ 
272+ 
182def main():273def main():
183 args = parse_args()274 args = parse_args()
275+ option = {}
276+ option["ACL_OP_COMPILER_CACHE_MODE"] = 'enable'
277+ option["ACL_OP_COMPILER_CACHE_DIR"] = './cache'
184 278 
279+ option["ACL_OP_SELECT_IMPL_MODE"] = 'high_precision'
280+ option['ACL_OPTYPELIST_FOR_IMPLMODE'] = 'Sqrt'
281+ print('option', option)
282+ torch.npu.set_option(option)
185 assert args.out or args.show or args.json_out, \283 assert args.out or args.show or args.json_out, \
186 ('Please specify at least one operation (save or show the results) '284 ('Please specify at least one operation (save or show the results) '
187 'with the argument "--out" or "--show" or "--json_out"')285 'with the argument "--out" or "--show" or "--json_out"')
188- 
189 if args.out is not None and not args.out.endswith(('.pkl', '.pickle')):286 if args.out is not None and not args.out.endswith(('.pkl', '.pickle')):
190 raise ValueError('The output file must be a pkl file.')287 raise ValueError('The output file must be a pkl file.')
191 288 
192 if args.json_out is not None and args.json_out.endswith('.json'):289 if args.json_out is not None and args.json_out.endswith('.json'):
193 args.json_out = args.json_out[:-5]290 args.json_out = args.json_out[:-5]
194- 
195 cfg = mmcv.Config.fromfile(args.config)291 cfg = mmcv.Config.fromfile(args.config)
196 if args.data_root:292 if args.data_root:
197 cfg.data_root = args.data_root293 cfg.data_root = args.data_root
@@ -205,12 +301,15 @@ def main():
205 if args.gpu_ids is not None:301 if args.gpu_ids is not None:
206 torch.npu.set_device(args.gpu_ids[0])302 torch.npu.set_device(args.gpu_ids[0])
207 # init distributed env first, since logger depends on the dist info.303 # init distributed env first, since logger depends on the dist info.
208- if args.launcher == 'none':304+ if "WORLD_SIZE" in os.environ and int(os.environ["WORLD_SIZE"]) > 1:
209- distributed = False
210- else:
211 distributed = True305 distributed = True
212- init_dist(args.launcher, **cfg.dist_params)306+ rank = int(os.environ['RANK'])
213- 307+ num_gpus = torch.npu.device_count()
308+ torch.npu.set_device(rank % num_gpus)
309+ torch.distributed.init_process_group(backend='hccl', init_method='env://',
310+ world_size=int(os.environ['WORLD_SIZE']), rank=args.local_rank)
311+ else:
312+ distributed = False
214 # build the dataloader313 # build the dataloader
215 # TODO: support multiple images per gpu (only minor changes are needed)314 # TODO: support multiple images per gpu (only minor changes are needed)
216 print('arg data root', cfg.data_root)315 print('arg data root', cfg.data_root)
@@ -225,10 +324,11 @@ def main():
225 # build the model and load checkpoint324 # build the model and load checkpoint
226 model = build_detector(cfg.model, train_cfg=None, test_cfg=cfg.test_cfg)325 model = build_detector(cfg.model, train_cfg=None, test_cfg=cfg.test_cfg)
227 fp16_cfg = cfg.get('fp16', None)326 fp16_cfg = cfg.get('fp16', None)
228- if fp16_cfg is not None:327+ # if fp16_cfg is not None:
229- wrap_fp16_model(model)328+ # wrap_fp16_model(model)
230 329 
231 while not osp.isfile(args.checkpoint):330 while not osp.isfile(args.checkpoint):
331+ print(args.checkpoint)
232 print('Waiting for {} to exist...'.format(args.checkpoint))332 print('Waiting for {} to exist...'.format(args.checkpoint))
233 time.sleep(60)333 time.sleep(60)
234 334 
@@ -241,10 +341,18 @@ def main():
241 model.CLASSES = dataset.CLASSES341 model.CLASSES = dataset.CLASSES
242 342 
243 if not distributed:343 if not distributed:
244- model = MMDataParallel(model.npu(), device_ids=[0])344+ amp.register_float_function(torch, 'sigmoid')
345+ optimizer = build_optimizer(model, cfg.optimizer)
346+ model, optimizer = amp.initialize(model.npu(), optimizer,
347+ opt_level='O1', loss_scale=128.0, combine_grad=True)
348+ model = MMDataParallel(model, device_ids=[0])
245 outputs = single_gpu_test(model, data_loader)349 outputs = single_gpu_test(model, data_loader)
246 else:350 else:
247- model = MMDistributedDataParallel(model.npu())351+ amp.register_float_function(torch, 'sigmoid')
352+ optimizer = build_optimizer(model, cfg.optimizer)
353+ model, optimizer = amp.initialize(model.npu(), optimizer,
354+ opt_level='O1', loss_scale=128.0, combine_grad=True)
355+ model = MMDistributedDataParallel(model)
248 outputs = multi_gpu_test(model, data_loader, args.tmpdir)356 outputs = multi_gpu_test(model, data_loader, args.tmpdir)
249 357 
250 rank, _ = get_dist_info()358 rank, _ = get_dist_info()
MPyTorch/contrib/cv/detection/SOLOv2/tools/test_ins_vis.py+11-9
@@ -32,6 +32,7 @@ import cv2
32import numpy as np32import numpy as np
33import matplotlib.cm as cm33import matplotlib.cm as cm
34 34 
35+ 
35def vis_seg(data, result, img_norm_cfg, data_id, colors, score_thr, save_dir):36def vis_seg(data, result, img_norm_cfg, data_id, colors, score_thr, save_dir):
36 img_tensor = data['img'][0]37 img_tensor = data['img'][0]
37 img_metas = data['img_meta'][0].data[0]38 img_metas = data['img_meta'][0].data[0]
@@ -44,7 +45,7 @@ def vis_seg(data, result, img_norm_cfg, data_id, colors, score_thr, save_dir):
44 continue45 continue
45 h, w, _ = img_meta['img_shape']46 h, w, _ = img_meta['img_shape']
46 img_show = img[:h, :w, :]47 img_show = img[:h, :w, :]
47- 48+ 
48 seg_label = cur_result[0]49 seg_label = cur_result[0]
49 seg_label = seg_label.cpu().numpy().astype(np.uint8)50 seg_label = seg_label.cpu().numpy().astype(np.uint8)
50 cate_label = cur_result[1]51 cate_label = cur_result[1]
@@ -70,12 +71,12 @@ def vis_seg(data, result, img_norm_cfg, data_id, colors, score_thr, save_dir):
70 71 
71 seg_show = img_show.copy()72 seg_show = img_show.copy()
72 for idx in range(num_mask):73 for idx in range(num_mask):
73- idx = -(idx+1)74+ idx = -(idx + 1)
74- cur_mask = seg_label[idx, :,:]75+ cur_mask = seg_label[idx, :, :]
75 cur_mask = mmcv.imresize(cur_mask, (w, h))76 cur_mask = mmcv.imresize(cur_mask, (w, h))
76 cur_mask = (cur_mask > 0.5).astype(np.uint8)77 cur_mask = (cur_mask > 0.5).astype(np.uint8)
77 if cur_mask.sum() == 0:78 if cur_mask.sum() == 0:
78- continue79+ continue
79 color_mask = np.random.randint(80 color_mask = np.random.randint(
80 0, 256, (1, 3), dtype=np.uint8)81 0, 256, (1, 3), dtype=np.uint8)
81 cur_mask_bool = cur_mask.astype(np.bool)82 cur_mask_bool = cur_mask.astype(np.bool)
@@ -85,7 +86,7 @@ def vis_seg(data, result, img_norm_cfg, data_id, colors, score_thr, save_dir):
85 cur_score = cate_score[idx]86 cur_score = cate_score[idx]
86 87 
87 label_text = class_names[cur_cate]88 label_text = class_names[cur_cate]
88- #label_text += '|{:.02f}'.format(cur_score)89+ # label_text += '|{:.02f}'.format(cur_score)
89 # center90 # center
90 center_y, center_x = ndimage.measurements.center_of_mass(cur_mask)91 center_y, center_x = ndimage.measurements.center_of_mass(cur_mask)
91 vis_pos = (max(int(center_x) - 10, 0), int(center_y))92 vis_pos = (max(int(center_x) - 10, 0), int(center_y))
@@ -99,8 +100,8 @@ def single_gpu_test(model, data_loader, args, cfg=None, verbose=True):
99 results = []100 results = []
100 dataset = data_loader.dataset101 dataset = data_loader.dataset
101 102 
102- class_num = 1000 # ins103+ class_num = 1000 # ins
103- colors = [(np.random.random((1, 3)) * 255).tolist()[0] for i in range(class_num)] 104+ colors = [(np.random.random((1, 3)) * 255).tolist()[0] for i in range(class_num)]
104 105 
105 prog_bar = mmcv.ProgressBar(len(dataset))106 prog_bar = mmcv.ProgressBar(len(dataset))
106 for i, data in enumerate(data_loader):107 for i, data in enumerate(data_loader):
@@ -110,7 +111,8 @@ def single_gpu_test(model, data_loader, args, cfg=None, verbose=True):
110 results.append(result)111 results.append(result)
111 112 
112 if verbose:113 if verbose:
113- vis_seg(data, seg_result, cfg.img_norm_cfg, data_id=i, colors=colors, score_thr=args.score_thr, save_dir=args.save_dir)114+ vis_seg(data, seg_result, cfg.img_norm_cfg, data_id=i, colors=colors, score_thr=args.score_thr,
115+ save_dir=args.save_dir)
114 116 
115 batch_size = data['img'][0].size(0)117 batch_size = data['img'][0].size(0)
116 for _ in range(batch_size):118 for _ in range(batch_size):
@@ -147,7 +149,7 @@ def collect_results(result_part, size, tmpdir=None):
147 if tmpdir is None:149 if tmpdir is None:
148 MAX_LEN = 512150 MAX_LEN = 512
149 # 32 is whitespace151 # 32 is whitespace
150- dir_tensor = torch.full((MAX_LEN, ),152+ dir_tensor = torch.full((MAX_LEN,),
151 32,153 32,
152 dtype=torch.uint8,154 dtype=torch.uint8,
153 device='cuda')155 device='cuda')
MPyTorch/contrib/cv/detection/SOLOv2/tools/test_robustness.py+3-3
@@ -162,7 +162,7 @@ def collect_results(result_part, size, tmpdir=None):
162 if tmpdir is None:162 if tmpdir is None:
163 MAX_LEN = 512163 MAX_LEN = 512
164 # 32 is whitespace164 # 32 is whitespace
165- dir_tensor = torch.full((MAX_LEN, ),165+ dir_tensor = torch.full((MAX_LEN,),
166 32,166 32,
167 dtype=torch.uint8,167 dtype=torch.uint8,
168 device='cuda')168 device='cuda')
@@ -395,8 +395,8 @@ def main():
395 rank, _ = get_dist_info()395 rank, _ = get_dist_info()
396 if args.out and rank == 0:396 if args.out and rank == 0:
397 eval_results_filename = (397 eval_results_filename = (
398- osp.splitext(args.out)[0] + '_results' +398+ osp.splitext(args.out)[0] + '_results' +
399- osp.splitext(args.out)[1])399+ osp.splitext(args.out)[1])
400 mmcv.dump(outputs, args.out)400 mmcv.dump(outputs, args.out)
401 eval_types = args.eval401 eval_types = args.eval
402 if cfg.dataset_type == 'VOCDataset':402 if cfg.dataset_type == 'VOCDataset':
MPyTorch/contrib/cv/detection/SOLOv2/tools/train.py+17-3
@@ -20,6 +20,9 @@ import time
20 20 
21import mmcv21import mmcv
22import torch22import torch
23+ 
24+if torch.__version__ >= '1.8.1':
25+ import torch_npu
23from mmcv import Config26from mmcv import Config
24from mmcv.runner import init_dist, load_state_dict27from mmcv.runner import init_dist, load_state_dict
25 28 
@@ -29,6 +32,7 @@ from mmdet.datasets import build_dataset
29from mmdet.models import build_detector32from mmdet.models import build_detector
30from mmdet.utils import get_root_logger33from mmdet.utils import get_root_logger
31 34 
35+ 
32def parse_args():36def parse_args():
33 parser = argparse.ArgumentParser(description='Train a detector')37 parser = argparse.ArgumentParser(description='Train a detector')
34 parser.add_argument('config', help='train config file path')38 parser.add_argument('config', help='train config file path')
@@ -44,7 +48,7 @@ def parse_args():
44 type=int,48 type=int,
45 default=1,49 default=1,
46 help='number of gpus to use '50 help='number of gpus to use '
47- '(only applicable to non-distributed training)')51+ '(only applicable to non-distributed training)')
48 parser.add_argument(52 parser.add_argument(
49 '--data_root',53 '--data_root',
50 help='the path of dataset',54 help='the path of dataset',
@@ -61,6 +65,7 @@ def parse_args():
61 action='store_true',65 action='store_true',
62 help='whether fine-tune model, change class num + 1')66 help='whether fine-tune model, change class num + 1')
63 parser.add_argument('--total_epochs', type=int, default=12, help='random seed')67 parser.add_argument('--total_epochs', type=int, default=12, help='random seed')
68+ parser.add_argument('--train_performance', type=bool, default=False, help='train performace')
64 parser.add_argument(69 parser.add_argument(
65 '--deterministic',70 '--deterministic',
66 action='store_true',71 action='store_true',
@@ -88,6 +93,14 @@ def parse_args():
88 93 
89 94 
90def main():95def main():
96+ option = {}
97+ option["ACL_OP_COMPILER_CACHE_MODE"] = 'enable'
98+ option["ACL_OP_COMPILER_CACHE_DIR"] = './cache'
99+ 
100+ option["ACL_OP_SELECT_IMPL_MODE"] = 'high_precision'
101+ option['ACL_OPTYPELIST_FOR_IMPLMODE'] = 'Sqrt'
102+ print('option', option)
103+ torch.npu.set_option(option)
91 os.environ['MASTER_ADDR'] = '127.0.0.1'104 os.environ['MASTER_ADDR'] = '127.0.0.1'
92 os.environ['MASTER_PORT'] = '29688'105 os.environ['MASTER_PORT'] = '29688'
93 args = parse_args()106 args = parse_args()
@@ -177,8 +190,9 @@ def main():
177 cfg,190 cfg,
178 distributed=distributed,191 distributed=distributed,
179 validate=args.validate,192 validate=args.validate,
180- timestamp=timestamp)193+ timestamp=timestamp,
194+ train_performance=args.train_performance)
181 195 
182 196 
183if __name__ == '__main__':197if __name__ == '__main__':
184- main()198+ main()