Skip to content

Commit 194a105

Browse files
authored
Remove py2 compatibility (tusen-ai#109)
1 parent fed9f50 commit 194a105

23 files changed

+90
-89
lines changed

core/detection_input.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ReadRoiRecord(DetectionAugmentation):
2929
"""
3030

3131
def __init__(self, gt_select):
32-
super(ReadRoiRecord, self).__init__()
32+
super().__init__()
3333
self.gt_select = gt_select
3434

3535
def apply(self, input_record):
@@ -52,7 +52,7 @@ class Norm2DImage(DetectionAugmentation):
5252
"""
5353

5454
def __init__(self, pNorm):
55-
super(Norm2DImage, self).__init__()
55+
super().__init__()
5656
self.p = pNorm # type: NormParam
5757

5858
def apply(self, input_record):
@@ -76,7 +76,7 @@ class Resize2DImageBbox(DetectionAugmentation):
7676
"""
7777

7878
def __init__(self, pResize):
79-
super(Resize2DImageBbox, self).__init__()
79+
super().__init__()
8080
self.p = pResize # type: ResizeParam
8181

8282
def apply(self, input_record):
@@ -116,7 +116,7 @@ class Resize2DImageBboxByRoidb(DetectionAugmentation):
116116
"""
117117

118118
def __init__(self):
119-
super(Resize2DImageBboxByRoidb, self).__init__()
119+
super().__init__()
120120
class ResizeParam:
121121
long = None
122122
short = None
@@ -139,7 +139,7 @@ class RandResize2DImageBbox(DetectionAugmentation):
139139
"""
140140

141141
def __init__(self, pRandResize):
142-
super(RandResize2DImageBbox, self).__init__()
142+
super().__init__()
143143
self.p = pRandResize
144144
class ResizeParam:
145145
long = None
@@ -164,7 +164,7 @@ class Flip2DImageBbox(DetectionAugmentation):
164164
"""
165165

166166
def __init__(self):
167-
super(Flip2DImageBbox, self).__init__()
167+
super().__init__()
168168

169169
def apply(self, input_record):
170170
if input_record["flipped"]:
@@ -181,7 +181,7 @@ def apply(self, input_record):
181181

182182
class RandCrop2DImageBbox(DetectionAugmentation):
183183
def __init__(self, pCrop):
184-
super(RandCrop2DImageBbox, self).__init__()
184+
super().__init__()
185185
self.p = pCrop
186186
assert pCrop.mode in ["center", "random"], "The {} crop mode is not supported".format(pCrop.mode)
187187

@@ -265,7 +265,7 @@ class Pad2DImageBbox(DetectionAugmentation):
265265
"""
266266

267267
def __init__(self, pPad):
268-
super(Pad2DImageBbox, self).__init__()
268+
super().__init__()
269269
self.p = pPad # type: PadParam
270270

271271
def apply(self, input_record):
@@ -289,7 +289,7 @@ def apply(self, input_record):
289289

290290
class ConvertImageFromHwcToChw(DetectionAugmentation):
291291
def __init__(self):
292-
super(ConvertImageFromHwcToChw, self).__init__()
292+
super().__init__()
293293

294294
def apply(self, input_record):
295295
input_record["image"] = input_record["image"].transpose((2, 0, 1))
@@ -305,7 +305,7 @@ class AnchorTarget2D(DetectionAugmentation):
305305
"""
306306

307307
def __init__(self, pAnchor):
308-
super(AnchorTarget2D, self).__init__()
308+
super().__init__()
309309
self.p = pAnchor # type: AnchorTarget2DParam
310310

311311
self.__base_anchor = None
@@ -512,7 +512,7 @@ def apply(self, input_record):
512512

513513
class RenameRecord(DetectionAugmentation):
514514
def __init__(self, mapping):
515-
super(RenameRecord, self).__init__()
515+
super().__init__()
516516
self.mapping = mapping
517517

518518
def apply(self, input_record):
@@ -539,7 +539,7 @@ def __init__(self, roidb, transform, data_name, label_name, batch_size=1,
539539
:param shuffle: bool
540540
:return: Loader
541541
"""
542-
super(Loader, self).__init__(batch_size=batch_size)
542+
super().__init__(batch_size=batch_size)
543543

544544
if kv:
545545
(self.rank, self.num_worker) = (kv.rank, kv.num_workers)
@@ -674,7 +674,7 @@ def collector(self):
674674

675675
class SequentialLoader(mx.io.DataIter):
676676
def __init__(self, iters):
677-
super(SequentialLoader, self).__init__()
677+
super().__init__()
678678
self.iters = iters
679679
self.exhausted = [False] * len(iters)
680680

@@ -714,7 +714,7 @@ class AnchorLoader(mx.io.DataIter):
714714
def __init__(self, roidb, transform, data_name, label_name, batch_size=1,
715715
shuffle=False, num_worker=12, num_collector=4, worker_queue_depth=4,
716716
collector_queue_depth=4, kv=None):
717-
super(AnchorLoader, self).__init__(batch_size=batch_size)
717+
super().__init__(batch_size=batch_size)
718718

719719
v_roidb, h_roidb = self.roidb_aspect_group(roidb)
720720

core/detection_metric.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class LossWithIgnore(mx.metric.EvalMetric):
66
def __init__(self, name, output_names, label_names, ignore_label=-1):
7-
super(LossWithIgnore, self).__init__(name, output_names, label_names)
7+
super().__init__(name, output_names, label_names)
88
self.ignore_label = ignore_label
99

1010
def update(self, labels, preds):
@@ -13,7 +13,7 @@ def update(self, labels, preds):
1313

1414
class FgLossWithIgnore(LossWithIgnore):
1515
def __init__(self, name, output_names, label_names, bg_label=0, ignore_label=-1):
16-
super(FgLossWithIgnore, self).__init__(name, output_names, label_names, ignore_label)
16+
super().__init__(name, output_names, label_names, ignore_label)
1717
self.bg_label = bg_label
1818

1919
def update(self, labels, preds):
@@ -22,7 +22,7 @@ def update(self, labels, preds):
2222

2323
class AccWithIgnore(LossWithIgnore):
2424
def __init__(self, name, output_names, label_names, ignore_label=-1):
25-
super(AccWithIgnore, self).__init__(name, output_names, label_names, ignore_label)
25+
super().__init__(name, output_names, label_names, ignore_label)
2626

2727
def update(self, labels, preds):
2828
if len(preds) == 1 and len(labels) == 1:
@@ -51,7 +51,7 @@ def update(self, labels, preds):
5151

5252
class FgAccWithIgnore(FgLossWithIgnore):
5353
def __init__(self, name, output_names, label_names, bg_label=0, ignore_label=-1):
54-
super(FgAccWithIgnore, self).__init__(name, output_names, label_names, bg_label, ignore_label)
54+
super().__init__(name, output_names, label_names, bg_label, ignore_label)
5555

5656
def update(self, labels, preds):
5757
pred = preds[0]
@@ -70,7 +70,7 @@ def update(self, labels, preds):
7070

7171
class CeWithIgnore(LossWithIgnore):
7272
def __init__(self, name, output_names, label_names, ignore_label=-1):
73-
super(CeWithIgnore, self).__init__(name, output_names, label_names, ignore_label)
73+
super().__init__(name, output_names, label_names, ignore_label)
7474

7575
def update(self, labels, preds):
7676
pred = preds[0]
@@ -93,7 +93,7 @@ def update(self, labels, preds):
9393

9494
class FgCeWithIgnore(FgLossWithIgnore):
9595
def __init__(self, name, output_names, label_names, bg_label=0, ignore_label=-1):
96-
super(FgCeWithIgnore, self).__init__(name, output_names, label_names, bg_label, ignore_label)
96+
super().__init__(name, output_names, label_names, bg_label, ignore_label)
9797

9898
def update(self, labels, preds):
9999
pred = preds[0]
@@ -116,7 +116,7 @@ def update(self, labels, preds):
116116

117117
class L1(FgLossWithIgnore):
118118
def __init__(self, name, output_names, label_names, bg_label=0, ignore_label=-1):
119-
super(L1, self).__init__(name, output_names, label_names, bg_label, ignore_label)
119+
super().__init__(name, output_names, label_names, bg_label, ignore_label)
120120

121121
def update(self, labels, preds):
122122
if len(preds) == 1 and len(labels) == 1:
@@ -141,7 +141,7 @@ def update(self, labels, preds):
141141

142142
class SigmoidCrossEntropy(mx.metric.EvalMetric):
143143
def __init__(self, name, output_names, label_names):
144-
super(SigmoidCrossEntropy, self).__init__(name, output_names, label_names)
144+
super().__init__(name, output_names, label_names)
145145

146146
def update(self, labels, preds):
147147
x = preds[0].reshape(-1) # logit

core/detection_module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class DetModule(BaseModule):
7878
"""
7979
def __init__(self, symbol, data_names=None, label_names=None, logger=logging, context=ctx.cpu(),
8080
fixed_param=None, excluded_param=None):
81-
super(DetModule, self).__init__(logger=logger)
81+
super().__init__(logger=logger)
8282

8383
if isinstance(context, ctx.Context):
8484
context = [context]

models/FPN/assign_layer_fpn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class AssignLayerFPNOperator(mx.operator.CustomOp):
1111
def __init__(self, rcnn_stride, roi_canonical_scale, roi_canonical_level):
12-
super(AssignLayerFPNOperator, self).__init__()
12+
super().__init__()
1313
self.rcnn_stride = rcnn_stride
1414
self.roi_canonical_scale = roi_canonical_scale
1515
self.roi_canonical_level = roi_canonical_level
@@ -46,7 +46,7 @@ def backward(self, req, out_grad, in_data, out_data, in_grad, aux):
4646
@mx.operator.register('assign_layer_fpn')
4747
class AssignLayerFPNProp(mx.operator.CustomOpProp):
4848
def __init__(self, rcnn_stride, roi_canonical_scale, roi_canonical_level):
49-
super(AssignLayerFPNProp, self).__init__(need_top_grad=False)
49+
super().__init__(need_top_grad=False)
5050
self.rcnn_stride = eval(rcnn_stride)
5151
self.roi_canonical_scale = int(roi_canonical_scale)
5252
self.roi_canonical_level = int(roi_canonical_level)

models/FPN/builder.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class FPNBbox2fcHead(BboxHead):
1111
def __init__(self, pBbox):
12-
super(FPNBbox2fcHead, self).__init__(pBbox)
12+
super().__init__(pBbox)
1313

1414
def add_norm(self, sym):
1515
p = self.p
@@ -42,7 +42,7 @@ def _get_bbox_head_logit(self, conv_feat):
4242

4343
class FPNRpnHead(RpnHead):
4444
def __init__(self, pRpn):
45-
super(RpnHead, self).__init__(pRpn)
45+
super().__init__(pRpn)
4646

4747
self.cls_logit_dict = None
4848
self.bbox_delta_dict = None
@@ -304,7 +304,7 @@ def get_sampled_proposal(self, conv_fpn_feat, gt_bbox, im_info):
304304

305305
class MSRAResNet50V1FPN(Backbone):
306306
def __init__(self, pBackbone):
307-
super(MSRAResNet50V1FPN, self).__init__(pBackbone)
307+
super().__init__(pBackbone)
308308
from mxnext.backbone.resnet_v1 import Builder
309309
b = Builder()
310310
self.symbol = b.get_backbone("msra", 50, "fpn", pBackbone.normalizer, pBackbone.fp16)
@@ -318,7 +318,7 @@ def get_rcnn_feature(self):
318318

319319
class MSRAResNet101V1FPN(Backbone):
320320
def __init__(self, pBackbone):
321-
super(MSRAResNet101V1FPN, self).__init__(pBackbone)
321+
super().__init__(pBackbone)
322322
from mxnext.backbone.resnet_v1 import Builder
323323
b = Builder()
324324
self.symbol = b.get_backbone("msra", 101, "fpn", pBackbone.normalizer, pBackbone.fp16)
@@ -332,7 +332,7 @@ def get_rcnn_feature(self):
332332

333333
class FPNNeck(Neck):
334334
def __init__(self, pNeck):
335-
super(FPNNeck, self).__init__(pNeck)
335+
super().__init__(pNeck)
336336
self.fpn_feat = None
337337

338338
def add_norm(self, sym):
@@ -495,7 +495,7 @@ def get_rcnn_feature(self, rcnn_feat):
495495

496496
class FPNRoiAlign(RoiAlign):
497497
def __init__(self, pRoi):
498-
super(FPNRoiAlign, self).__init__(pRoi)
498+
super().__init__(pRoi)
499499

500500
def get_roi_feature(self, conv_fpn_feat, proposal):
501501
p = self.p

models/FPN/get_top_proposal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class GetTopProposalOperator(mx.operator.CustomOp):
1111
def __init__(self, top_n):
12-
super(GetTopProposalOperator, self).__init__()
12+
super().__init__()
1313
self.top_n = top_n
1414

1515
def forward(self, is_train, req, in_data, out_data, aux):
@@ -47,7 +47,7 @@ def backward(self, req, out_grad, in_data, out_data, in_grad, aux):
4747
@mx.operator.register('get_top_proposal')
4848
class GetTopProposalProp(mx.operator.CustomOpProp):
4949
def __init__(self, top_n):
50-
super(GetTopProposalProp, self).__init__(need_top_grad=False)
50+
super().__init__(need_top_grad=False)
5151
self.top_n = int(top_n)
5252

5353
def list_arguments(self):

models/FPN/input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class PyramidAnchorTarget2D(PyramidAnchorTarget2DBase):
6262
"""
6363

6464
def __init__(self, pAnchor):
65-
super(PyramidAnchorTarget2D, self).__init__(pAnchor)
65+
super().__init__(pAnchor)
6666

6767
self.pyramid_levels = len(self.p.generate.stride)
6868
self.p_list = [copy.deepcopy(self.p) for _ in range(self.pyramid_levels)]

models/cascade_rcnn/builder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def get_refined_proposal(backbone, neck, rpn_head, roi_extractor, bbox_head, bbo
167167

168168
class CascadeNeck(Neck):
169169
def __init__(self, pNeck):
170-
super(CascadeNeck, self).__init__(pNeck)
170+
super().__init__(pNeck)
171171

172172
def get_rcnn_feature(self, rcnn_feat):
173173
p = self.p
@@ -189,7 +189,7 @@ def get_rcnn_feature(self, rcnn_feat):
189189
"""
190190
class CascadeRoiAlign(RoiAlign):
191191
def __init__(self, pRoi):
192-
super(CascadeRoiAlign, self).__init__(pRoi)
192+
super().__init__(pRoi)
193193

194194
def get_roi_feature(self, rcnn_feat, proposal, stage):
195195
p = self.p
@@ -220,7 +220,7 @@ def get_roi_feature(self, rcnn_feat, proposal, stage):
220220
"""
221221
class CascadeBbox2fcHead(Bbox2fcHead):
222222
def __init__(self, pBbox):
223-
super(CascadeBbox2fcHead, self).__init__(pBbox)
223+
super().__init__(pBbox)
224224

225225
self.stage = pBbox.stage
226226
self._cls_logit = None

models/maskrcnn/bbox_post_processing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def multiclass_nms(nms, cls_score, bbox_xyxy, min_det_score, max_det_per_image):
3434

3535
class BboxPostProcessingOperator(mx.operator.CustomOp):
3636
def __init__(self, max_det_per_image, min_det_score, nms_type, nms_thr):
37-
super(BboxPostProcessingOperator, self).__init__()
37+
super().__init__()
3838
self.max_det_per_image = max_det_per_image
3939
self.min_det_score = min_det_score
4040
self.nms_type = nms_type
@@ -79,7 +79,7 @@ def backward(self, req, out_grad, in_data, out_data, in_grad, aux):
7979
@mx.operator.register("BboxPostProcessing")
8080
class BboxPostProcessingProp(mx.operator.CustomOpProp):
8181
def __init__(self, max_det_per_image, min_det_score, nms_type, nms_thr):
82-
super(BboxPostProcessingProp, self).__init__(need_top_grad=False)
82+
super().__init__(need_top_grad=False)
8383
self.max_det_per_image = int(max_det_per_image)
8484
self.min_det_score = float(min_det_score)
8585
self.nms_type = str(nms_type)

models/maskrcnn/builder.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def get_post_processing(self, cls_score, bbox_xyxy):
8585

8686
class MaskRpnHead(RpnHead):
8787
def __init__(self, pRpn, pMask):
88-
super(MaskRpnHead, self).__init__(pRpn)
89-
self.pMask = patch_config_as_no_throw(pMask)
88+
super().__init__(pRpn)
89+
self.pMask = patch_config_as_nothrow(pMask)
9090

9191
def get_sampled_proposal(self, conv_fpn_feat, gt_bbox, gt_poly, im_info):
9292
p = self.p
@@ -149,8 +149,8 @@ def get_sampled_proposal(self, conv_fpn_feat, gt_bbox, gt_poly, im_info):
149149

150150
class MaskFPNRpnHead(FPNRpnHead):
151151
def __init__(self, pRpn, pMask):
152-
super(MaskFPNRpnHead, self).__init__(pRpn)
153-
self.pMask = patch_config_as_no_throw(pMask)
152+
super().__init__(pRpn)
153+
self.pMask = patch_config_as_nothrow(pMask)
154154

155155
def get_sampled_proposal(self, conv_fpn_feat, gt_bbox, gt_poly, im_info):
156156
p = self.p
@@ -213,9 +213,9 @@ def get_sampled_proposal(self, conv_fpn_feat, gt_bbox, gt_poly, im_info):
213213

214214
class MaskFasterRcnnHead(object):
215215
def __init__(self, pBbox, pMask, pMaskRoi):
216-
self.pBbox = patch_config_as_no_throw(pBbox)
217-
self.pMask = patch_config_as_no_throw(pMask)
218-
self.pMaskRoi = patch_config_as_no_throw(pMaskRoi)
216+
self.pBbox = patch_config_as_nothrow(pBbox)
217+
self.pMask = patch_config_as_nothrow(pMask)
218+
self.pMaskRoi = patch_config_as_nothrow(pMaskRoi)
219219

220220
self._head_feat = None
221221

@@ -284,7 +284,7 @@ def get_loss(self, conv_feat, mask_target):
284284

285285
class MaskFasterRcnn4ConvHead(MaskFasterRcnnHead):
286286
def __init__(self, pBbox, pMask, pMaskRoi):
287-
super(MaskFasterRcnn4ConvHead, self).__init__(pBbox, pMask, pMaskRoi)
287+
super().__init__(pBbox, pMask, pMaskRoi)
288288

289289
def _get_mask_head_logit(self, conv_feat):
290290
if self._head_feat is not None:

0 commit comments

Comments
 (0)