Skip to content

Commit 27bfde8

Browse files
authored
Fix unittest error of pretrain cfg (open-mmlab#5561)
* fix unittest of pretrain cfg * add init_weights * delete pretrained
1 parent a28199d commit 27bfde8

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

configs/fast_rcnn/fast_rcnn_r101_caffe_fpn_1x_coco.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
_base_ = './fast_rcnn_r50_caffe_fpn_1x_coco.py'
22
model = dict(
3-
pretrained='open-mmlab://detectron2/resnet101_caffe',
43
backbone=dict(
54
depth=101,
65
init_cfg=dict(

tests/test_models/test_forward.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _get_detector_cfg(fname):
4545
def test_sparse_rcnn_forward():
4646
config_path = 'sparse_rcnn/sparse_rcnn_r50_fpn_1x_coco.py'
4747
model = _get_detector_cfg(config_path)
48-
model['pretrained'] = None
48+
model.backbone.init_cfg = None
4949
from mmdet.models import build_detector
5050
detector = build_detector(model)
5151
detector.init_weights()
@@ -54,8 +54,6 @@ def test_sparse_rcnn_forward():
5454
imgs = mm_inputs.pop('imgs')
5555
img_metas = mm_inputs.pop('img_metas')
5656
# Test forward train with non-empty truth batch
57-
detector = detector
58-
imgs = imgs
5957
detector.train()
6058
gt_bboxes = mm_inputs['gt_bboxes']
6159
gt_bboxes = [item for item in gt_bboxes]
@@ -75,7 +73,6 @@ def test_sparse_rcnn_forward():
7573
# Test forward train with an empty truth batch
7674
mm_inputs = _demo_mm_inputs(input_shape, num_items=[0])
7775
imgs = mm_inputs.pop('imgs')
78-
imgs = imgs
7976
img_metas = mm_inputs.pop('img_metas')
8077
gt_bboxes = mm_inputs['gt_bboxes']
8178
gt_bboxes = [item for item in gt_bboxes]
@@ -105,7 +102,7 @@ def test_sparse_rcnn_forward():
105102

106103
def test_rpn_forward():
107104
model = _get_detector_cfg('rpn/rpn_r50_fpn_1x_coco.py')
108-
model['pretrained'] = None
105+
model.backbone.init_cfg = None
109106

110107
from mmdet.models import build_detector
111108
detector = build_detector(model)
@@ -151,7 +148,7 @@ def test_single_stage_forward_gpu(cfg_file):
151148
pytest.skip('test requires GPU and torch+cuda')
152149

153150
model = _get_detector_cfg(cfg_file)
154-
model['pretrained'] = None
151+
model.backbone.init_cfg = None
155152

156153
from mmdet.models import build_detector
157154
detector = build_detector(model)
@@ -188,7 +185,7 @@ def test_single_stage_forward_gpu(cfg_file):
188185
def test_faster_rcnn_ohem_forward():
189186
model = _get_detector_cfg(
190187
'faster_rcnn/faster_rcnn_r50_fpn_ohem_1x_coco.py')
191-
model['pretrained'] = None
188+
model.backbone.init_cfg = None
192189

193190
from mmdet.models import build_detector
194191
detector = build_detector(model)
@@ -250,7 +247,7 @@ def test_two_stage_forward(cfg_file):
250247
with_semantic = False
251248

252249
model = _get_detector_cfg(cfg_file)
253-
model['pretrained'] = None
250+
model.backbone.init_cfg = None
254251

255252
# Save cost
256253
if cfg_file in [
@@ -305,7 +302,7 @@ def test_two_stage_forward(cfg_file):
305302
'cfg_file', ['ghm/retinanet_ghm_r50_fpn_1x_coco.py', 'ssd/ssd300_coco.py'])
306303
def test_single_stage_forward_cpu(cfg_file):
307304
model = _get_detector_cfg(cfg_file)
308-
model['pretrained'] = None
305+
model.backbone.init_cfg = None
309306

310307
from mmdet.models import build_detector
311308
detector = build_detector(model)
@@ -417,7 +414,7 @@ def _demo_mm_inputs(input_shape=(1, 3, 300, 300),
417414

418415
def test_yolact_forward():
419416
model = _get_detector_cfg('yolact/yolact_r50_1x8_coco.py')
420-
model['pretrained'] = None
417+
model.backbone.init_cfg = None
421418

422419
from mmdet.models import build_detector
423420
detector = build_detector(model)
@@ -456,7 +453,7 @@ def test_yolact_forward():
456453

457454
def test_detr_forward():
458455
model = _get_detector_cfg('detr/detr_r50_8x2_150e_coco.py')
459-
model['pretrained'] = None
456+
model.backbone.init_cfg = None
460457

461458
from mmdet.models import build_detector
462459
detector = build_detector(model)
@@ -511,7 +508,7 @@ def test_detr_forward():
511508

512509
def test_kd_single_stage_forward():
513510
model = _get_detector_cfg('ld/ld_r18_gflv1_r101_fpn_coco_1x.py')
514-
model['pretrained'] = None
511+
model.backbone.init_cfg = None
515512

516513
from mmdet.models import build_detector
517514
detector = build_detector(model)
@@ -573,7 +570,6 @@ def test_inference_detector():
573570
num_class = 3
574571
model_dict = dict(
575572
type='RetinaNet',
576-
pretrained=None,
577573
backbone=dict(
578574
type='ResNet',
579575
depth=18,

0 commit comments

Comments
 (0)