Skip to content

Commit

Permalink
[Fix] Twice softmax bug in bbox_head & evaluation bug in dense head.
Browse files Browse the repository at this point in the history
  • Loading branch information
SakiRinn committed Mar 17, 2023
1 parent 0151eef commit 8fcbbb8
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ work_dirs/
*.sh~

*.slurm
slurm_*
slurm_*
slurm-*
2 changes: 1 addition & 1 deletion configs/_base_/datasets/coco_LHC.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
])
]
data = dict(
samples_per_gpu=6, # 原为2,20220328修改(imgs_per_gpu)
samples_per_gpu=4,
workers_per_gpu=2,
train=dict(
type=dataset_type,
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/models/faster_rcnn_r50_fpn_locount.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
loss_weight=1.0)),
roi_head=dict(
type='StandardRoIHeadWithCount',
cnt_loss_weight=0.25,
cnt_loss_weight=0.1,
bbox_roi_extractor=dict(
type='SingleRoIExtractor',
roi_layer=dict(type='RoIAlign', output_size=7, sampling_ratio=0),
Expand Down
11 changes: 4 additions & 7 deletions configs/_base_/models/retinanet_r50_fpn_locount.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
in_channels=256,
stacked_convs=4,
feat_channels=256,
cnt_loss_weight=0.25,
cnt_loss_weight=0.1,
anchor_generator=dict(
type='AnchorGenerator',
octave_base_scale=4,
Expand All @@ -43,14 +43,11 @@
alpha=0.25,
loss_weight=1.0),
loss_bbox=dict(
type='SmoothL1Loss',
beta=1.0,
type='L1Loss',
loss_weight=1.0),
loss_cnt=dict(
type='FocalLoss',
use_sigmoid=True,
gamma=2.0,
alpha=0.25,
type='CrossEntropyLoss',
use_sigmoid=False,
loss_weight=1.0)),
# model training and testing settings
train_cfg=dict(
Expand Down
40 changes: 38 additions & 2 deletions configs/locount/CLCNet_s2d10_r50_fpn_1x_locount.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
bbox_coder=dict(
type='DeltaXYWHBBoxCoder',
target_means=[0., 0., 0., 0.],
target_stds=[0.05, 0.05, 0.1, 0.1]),
target_stds=[0.033, 0.033, 0.067, 0.067]),
reg_class_agnostic=True,
loss_cls=dict(
type='CrossEntropyLoss',
Expand All @@ -62,5 +62,41 @@
use_sigmoid=False,
loss_weight=1.0)),
]
)
),
train_cfg=dict(
rcnn=[
dict(
assigner=dict(
type='MaxIoUAssignerWithCount',
pos_iou_thr=0.5,
neg_iou_thr=0.5,
min_pos_iou=0.5,
match_low_quality=False,
ignore_iof_thr=-1),
sampler=dict(
type='RandomSamplerWithCount',
num=512,
pos_fraction=0.25,
neg_pos_ub=-1,
add_gt_as_proposals=True),
pos_weight=-1,
debug=False),
dict(
assigner=dict(
type='MaxIoUAssignerWithCount',
pos_iou_thr=0.7,
neg_iou_thr=0.7,
min_pos_iou=0.7,
match_low_quality=False,
ignore_iof_thr=-1),
sampler=dict(
type='RandomSamplerWithCount',
num=512,
pos_fraction=0.25,
neg_pos_ub=-1,
add_gt_as_proposals=True),
pos_weight=-1,
debug=False)
]
),
)
266 changes: 266 additions & 0 deletions configs/locount/CLCNet_s6d2_r50_fpn_1x_locount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
_base_ = [
'../_base_/models/cascade_rcnn_r50_fpn_locount.py',
'../_base_/datasets/coco_LHC.py',
'../_base_/schedules/schedule_1x.py',
'../_base_/default_runtime.py'
]
model = dict(
roi_head=dict(
num_stages=6,
stage_loss_weights=[1, 0.833, 0.667, 0.5, 0.333, 0.167], # TODO
stage_cnt_loss_weights=[0.1, 0.1, 0.1, 0.1, 0.1, 0.1], # TODO
base=2,
bbox_head=[
dict(
type='FCBBoxHeadWithCount',
num_shared_fcs=2,
in_channels=256,
fc_out_channels=1024,
roi_feat_size=7,
num_classes=140,
num_counts=56,
bbox_coder=dict(
type='DeltaXYWHBBoxCoder',
target_means=[0., 0., 0., 0.],
target_stds=[0.1, 0.1, 0.2, 0.2]),
reg_class_agnostic=True,
loss_cls=dict(
type='CrossEntropyLoss',
use_sigmoid=False,
loss_weight=1.0),
loss_bbox=dict(
type='SmoothL1Loss',
beta=1.0,
loss_weight=1.0),
loss_cnt=dict(
type='CrossEntropyLoss',
use_sigmoid=False,
loss_weight=1.0)),
dict(
type='FCBBoxHeadWithCount',
num_shared_fcs=2,
in_channels=256,
fc_out_channels=1024,
roi_feat_size=7,
num_classes=140,
num_counts=56,
bbox_coder=dict(
type='DeltaXYWHBBoxCoder',
target_means=[0., 0., 0., 0.],
target_stds=[0.083, 0.083, 0.167, 0.167]), # TODO
reg_class_agnostic=True,
loss_cls=dict(
type='CrossEntropyLoss',
use_sigmoid=False,
loss_weight=1.0),
loss_bbox=dict(
type='SmoothL1Loss',
beta=1.0,
loss_weight=1.0),
loss_cnt=dict(
type='CrossEntropyLoss',
use_sigmoid=False,
loss_weight=1.0)),
dict(
type='FCBBoxHeadWithCount',
num_shared_fcs=2,
in_channels=256,
fc_out_channels=1024,
roi_feat_size=7,
num_classes=140,
num_counts=56,
bbox_coder=dict(
type='DeltaXYWHBBoxCoder',
target_means=[0., 0., 0., 0.],
target_stds=[0.067, 0.067, 0.133, 0.133]), # TODO
reg_class_agnostic=True,
loss_cls=dict(
type='CrossEntropyLoss',
use_sigmoid=False,
loss_weight=1.0),
loss_bbox=dict(
type='SmoothL1Loss',
beta=1.0,
loss_weight=1.0),
loss_cnt=dict(
type='CrossEntropyLoss',
use_sigmoid=False,
loss_weight=1.0)),
dict(
type='FCBBoxHeadWithCount',
num_shared_fcs=2,
in_channels=256,
fc_out_channels=1024,
roi_feat_size=7,
num_classes=140,
num_counts=56,
bbox_coder=dict(
type='DeltaXYWHBBoxCoder',
target_means=[0., 0., 0., 0.],
target_stds=[0.05, 0.05, 0.1, 0.1]),
reg_class_agnostic=True,
loss_cls=dict(
type='CrossEntropyLoss',
use_sigmoid=False,
loss_weight=1.0),
loss_bbox=dict(
type='SmoothL1Loss',
beta=1.0,
loss_weight=1.0),
loss_cnt=dict(
type='CrossEntropyLoss',
use_sigmoid=False,
loss_weight=1.0)),
dict(
type='FCBBoxHeadWithCount',
num_shared_fcs=2,
in_channels=256,
fc_out_channels=1024,
roi_feat_size=7,
num_classes=140,
num_counts=56,
bbox_coder=dict(
type='DeltaXYWHBBoxCoder',
target_means=[0., 0., 0., 0.],
target_stds=[0.033, 0.033, 0.067, 0.067]),
reg_class_agnostic=True,
loss_cls=dict(
type='CrossEntropyLoss',
use_sigmoid=False,
loss_weight=1.0),
loss_bbox=dict(
type='SmoothL1Loss',
beta=1.0,
loss_weight=1.0),
loss_cnt=dict(
type='CrossEntropyLoss',
use_sigmoid=False,
loss_weight=1.0)),
dict(
type='FCBBoxHeadWithCount',
num_shared_fcs=2,
in_channels=256,
fc_out_channels=1024,
roi_feat_size=7,
num_classes=140,
num_counts=56,
bbox_coder=dict(
type='DeltaXYWHBBoxCoder',
target_means=[0., 0., 0., 0.],
target_stds=[0.017, 0.017, 0.033, 0.033]), # TODO
reg_class_agnostic=True,
loss_cls=dict(
type='CrossEntropyLoss',
use_sigmoid=False,
loss_weight=1.0),
loss_bbox=dict(
type='SmoothL1Loss',
beta=1.0,
loss_weight=1.0),
loss_cnt=dict(
type='CrossEntropyLoss',
use_sigmoid=False,
loss_weight=1.0)),
]
),
train_cfg=dict(
rcnn=[
dict(
assigner=dict(
type='MaxIoUAssignerWithCount',
pos_iou_thr=0.5,
neg_iou_thr=0.5,
min_pos_iou=0.5,
match_low_quality=False,
ignore_iof_thr=-1),
sampler=dict(
type='RandomSamplerWithCount',
num=512,
pos_fraction=0.25,
neg_pos_ub=-1,
add_gt_as_proposals=True),
pos_weight=-1,
debug=False),
dict(
assigner=dict(
type='MaxIoUAssignerWithCount',
pos_iou_thr=0.55,
neg_iou_thr=0.55,
min_pos_iou=0.55,
match_low_quality=False,
ignore_iof_thr=-1),
sampler=dict(
type='RandomSamplerWithCount',
num=512,
pos_fraction=0.25,
neg_pos_ub=-1,
add_gt_as_proposals=True),
pos_weight=-1,
debug=False),
dict(
assigner=dict(
type='MaxIoUAssignerWithCount',
pos_iou_thr=0.6,
neg_iou_thr=0.6,
min_pos_iou=0.6,
match_low_quality=False,
ignore_iof_thr=-1),
sampler=dict(
type='RandomSamplerWithCount',
num=512,
pos_fraction=0.25,
neg_pos_ub=-1,
add_gt_as_proposals=True),
pos_weight=-1,
debug=False),
dict(
assigner=dict(
type='MaxIoUAssignerWithCount',
pos_iou_thr=0.65,
neg_iou_thr=0.65,
min_pos_iou=0.65,
match_low_quality=False,
ignore_iof_thr=-1),
sampler=dict(
type='RandomSamplerWithCount',
num=512,
pos_fraction=0.25,
neg_pos_ub=-1,
add_gt_as_proposals=True),
pos_weight=-1,
debug=False),
dict(
assigner=dict(
type='MaxIoUAssignerWithCount',
pos_iou_thr=0.7,
neg_iou_thr=0.7,
min_pos_iou=0.7,
match_low_quality=False,
ignore_iof_thr=-1),
sampler=dict(
type='RandomSamplerWithCount',
num=512,
pos_fraction=0.25,
neg_pos_ub=-1,
add_gt_as_proposals=True),
pos_weight=-1,
debug=False),
dict(
assigner=dict(
type='MaxIoUAssignerWithCount',
pos_iou_thr=0.75,
neg_iou_thr=0.75,
min_pos_iou=0.75,
match_low_quality=False,
ignore_iof_thr=-1),
sampler=dict(
type='RandomSamplerWithCount',
num=512,
pos_fraction=0.25,
neg_pos_ub=-1,
add_gt_as_proposals=True),
pos_weight=-1,
debug=False)
]
),
)
2 changes: 1 addition & 1 deletion mmdet/models/dense_heads/anchor_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ def loss_single(self, cls_score, bbox_pred, cnt_score, anchors, labels, label_we
counts = counts.reshape(-1)
count_weights = count_weights.reshape(-1)
cnt_score = cnt_score.permute(0, 2, 3, 1).reshape(-1, self.cnt_out_channels)
loss_cnt = self.cnt_loss_weight * self.loss_cnt(
loss_cnt = self.cnt_loss_weight * self.loss_cnt( # ADD weight
cnt_score, counts, count_weights, avg_factor=num_total_samples)
# bbox
bbox_targets = bbox_targets.reshape(-1, 4)
Expand Down
Loading

0 comments on commit 8fcbbb8

Please sign in to comment.