Skip to content

Commit e1599e7

Browse files
authored
Enable to use mmcv.jit in parrots environment (open-mmlab#4192)
* add mmcv.jit * only use derivate and coderize * fix for isort * small modify for decorator order
1 parent 7b3fae6 commit e1599e7

15 files changed

+43
-0
lines changed

mmdet/core/bbox/coder/bucketing_bbox_coder.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import mmcv
12
import numpy as np
23
import torch
34
import torch.nn.functional as F
@@ -90,6 +91,7 @@ def decode(self, bboxes, pred_bboxes, max_shape=None):
9091
return decoded_bboxes
9192

9293

94+
@mmcv.jit(coderize=True)
9395
def generat_buckets(proposals, num_buckets, scale_factor=1.0):
9496
"""Generate buckets w.r.t bucket number and scale factor of proposals.
9597
@@ -138,6 +140,7 @@ def generat_buckets(proposals, num_buckets, scale_factor=1.0):
138140
return bucket_w, bucket_h, l_buckets, r_buckets, t_buckets, d_buckets
139141

140142

143+
@mmcv.jit(coderize=True)
141144
def bbox2bucket(proposals,
142145
gt,
143146
num_buckets,
@@ -261,6 +264,7 @@ def bbox2bucket(proposals,
261264
return offsets, offsets_weights, bucket_labels, bucket_cls_weights
262265

263266

267+
@mmcv.jit(coderize=True)
264268
def bucket2bbox(proposals,
265269
cls_preds,
266270
offset_preds,

mmdet/core/bbox/coder/delta_xywh_bbox_coder.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import mmcv
12
import numpy as np
23
import torch
34

@@ -75,6 +76,7 @@ def decode(self,
7576
return decoded_bboxes
7677

7778

79+
@mmcv.jit(coderize=True)
7880
def bbox2delta(proposals, gt, means=(0., 0., 0., 0.), stds=(1., 1., 1., 1.)):
7981
"""Compute deltas of proposals w.r.t. gt.
8082
@@ -120,6 +122,7 @@ def bbox2delta(proposals, gt, means=(0., 0., 0., 0.), stds=(1., 1., 1., 1.)):
120122
return deltas
121123

122124

125+
@mmcv.jit(coderize=True)
123126
def delta2bbox(rois,
124127
deltas,
125128
means=(0., 0., 0., 0.),

mmdet/core/bbox/coder/legacy_delta_xywh_bbox_coder.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import mmcv
12
import numpy as np
23
import torch
34

@@ -79,6 +80,7 @@ def decode(self,
7980
return decoded_bboxes
8081

8182

83+
@mmcv.jit(coderize=True)
8284
def legacy_bbox2delta(proposals,
8385
gt,
8486
means=(0., 0., 0., 0.),
@@ -127,6 +129,7 @@ def legacy_bbox2delta(proposals,
127129
return deltas
128130

129131

132+
@mmcv.jit(coderize=True)
130133
def legacy_delta2bbox(rois,
131134
deltas,
132135
means=(0., 0., 0., 0.),

mmdet/core/bbox/coder/tblr_bbox_coder.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import mmcv
12
import torch
23

34
from ..builder import BBOX_CODERS
@@ -68,6 +69,7 @@ def decode(self, bboxes, pred_bboxes, max_shape=None):
6869
return decoded_bboxes
6970

7071

72+
@mmcv.jit(coderize=True)
7173
def bboxes2tblr(priors, gts, normalizer=4.0, normalize_by_wh=True):
7274
"""Encode ground truth boxes to tblr coordinate.
7375
@@ -114,6 +116,7 @@ def bboxes2tblr(priors, gts, normalizer=4.0, normalize_by_wh=True):
114116
return loc / normalizer
115117

116118

119+
@mmcv.jit(coderize=True)
117120
def tblr2bboxes(priors,
118121
tblr,
119122
normalizer=4.0,

mmdet/core/bbox/coder/yolo_bbox_coder.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import mmcv
12
import torch
23

34
from ..builder import BBOX_CODERS
@@ -21,6 +22,7 @@ def __init__(self, eps=1e-6):
2122
super(BaseBBoxCoder, self).__init__()
2223
self.eps = eps
2324

25+
@mmcv.jit(coderize=True)
2426
def encode(self, bboxes, gt_bboxes, stride):
2527
"""Get box regression transformation deltas that can be used to
2628
transform the ``bboxes`` into the ``gt_bboxes``.
@@ -55,6 +57,7 @@ def encode(self, bboxes, gt_bboxes, stride):
5557
[x_center_target, y_center_target, w_target, h_target], dim=-1)
5658
return encoded_bboxes
5759

60+
@mmcv.jit(coderize=True)
5861
def decode(self, bboxes, pred_bboxes, stride):
5962
"""Apply transformation `pred_bboxes` to `boxes`.
6063

mmdet/models/losses/accuracy.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import mmcv
12
import torch.nn as nn
23

34

5+
@mmcv.jit(coderize=True)
46
def accuracy(pred, target, topk=1, thresh=None):
57
"""Calculate accuracy according to the prediction and target.
68

mmdet/models/losses/ae_loss.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import mmcv
12
import torch
23
import torch.nn as nn
34
import torch.nn.functional as F
45

56
from ..builder import LOSSES
67

78

9+
@mmcv.jit(derivate=True, coderize=True)
810
def ae_loss_per_image(tl_preds, br_preds, match):
911
"""Associative Embedding Loss in one image.
1012

mmdet/models/losses/balanced_l1_loss.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import mmcv
12
import numpy as np
23
import torch
34
import torch.nn as nn
@@ -6,6 +7,7 @@
67
from .utils import weighted_loss
78

89

10+
@mmcv.jit(derivate=True, coderize=True)
911
@weighted_loss
1012
def balanced_l1_loss(pred,
1113
target,

mmdet/models/losses/gaussian_focal_loss.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import mmcv
12
import torch.nn as nn
23

34
from ..builder import LOSSES
45
from .utils import weighted_loss
56

67

8+
@mmcv.jit(derivate=True, coderize=True)
79
@weighted_loss
810
def gaussian_focal_loss(pred, gaussian_target, alpha=2.0, gamma=4.0):
911
"""`Focal Loss <https://arxiv.org/abs/1708.02002>`_ for targets in gaussian

mmdet/models/losses/gfocal_loss.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import mmcv
12
import torch.nn as nn
23
import torch.nn.functional as F
34

45
from ..builder import LOSSES
56
from .utils import weighted_loss
67

78

9+
@mmcv.jit(derivate=True, coderize=True)
810
@weighted_loss
911
def quality_focal_loss(pred, target, beta=2.0):
1012
r"""Quality Focal Loss (QFL) is from `Generalized Focal Loss: Learning
@@ -49,6 +51,7 @@ def quality_focal_loss(pred, target, beta=2.0):
4951
return loss
5052

5153

54+
@mmcv.jit(derivate=True, coderize=True)
5255
@weighted_loss
5356
def distribution_focal_loss(pred, label):
5457
r"""Distribution Focal Loss (DFL) is from `Generalized Focal Loss: Learning

mmdet/models/losses/iou_loss.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import math
22

3+
import mmcv
34
import torch
45
import torch.nn as nn
56

@@ -8,6 +9,7 @@
89
from .utils import weighted_loss
910

1011

12+
@mmcv.jit(derivate=True, coderize=True)
1113
@weighted_loss
1214
def iou_loss(pred, target, linear=False, eps=1e-6):
1315
"""IoU loss.
@@ -34,6 +36,7 @@ def iou_loss(pred, target, linear=False, eps=1e-6):
3436
return loss
3537

3638

39+
@mmcv.jit(derivate=True, coderize=True)
3740
@weighted_loss
3841
def bounded_iou_loss(pred, target, beta=0.2, eps=1e-3):
3942
"""BIoULoss.
@@ -79,6 +82,7 @@ def bounded_iou_loss(pred, target, beta=0.2, eps=1e-3):
7982
return loss
8083

8184

85+
@mmcv.jit(derivate=True, coderize=True)
8286
@weighted_loss
8387
def giou_loss(pred, target, eps=1e-7):
8488
r"""`Generalized Intersection over Union: A Metric and A Loss for Bounding
@@ -98,6 +102,7 @@ def giou_loss(pred, target, eps=1e-7):
98102
return loss
99103

100104

105+
@mmcv.jit(derivate=True, coderize=True)
101106
@weighted_loss
102107
def diou_loss(pred, target, eps=1e-7):
103108
r"""`Implementation of Distance-IoU Loss: Faster and Better
@@ -152,6 +157,7 @@ def diou_loss(pred, target, eps=1e-7):
152157
return loss
153158

154159

160+
@mmcv.jit(derivate=True, coderize=True)
155161
@weighted_loss
156162
def ciou_loss(pred, target, eps=1e-7):
157163
r"""`Implementation of paper `Enhancing Geometric Factors into

mmdet/models/losses/pisa_loss.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import mmcv
12
import torch
23

34
from mmdet.core import bbox_overlaps
45

56

7+
@mmcv.jit(derivate=True, coderize=True)
68
def isr_p(cls_score,
79
bbox_pred,
810
bbox_targets,
@@ -116,6 +118,7 @@ def isr_p(cls_score,
116118
return bbox_targets
117119

118120

121+
@mmcv.jit(derivate=True, coderize=True)
119122
def carl_loss(cls_score,
120123
labels,
121124
bbox_pred,

mmdet/models/losses/smooth_l1_loss.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import mmcv
12
import torch
23
import torch.nn as nn
34

45
from ..builder import LOSSES
56
from .utils import weighted_loss
67

78

9+
@mmcv.jit(derivate=True, coderize=True)
810
@weighted_loss
911
def smooth_l1_loss(pred, target, beta=1.0):
1012
"""Smooth L1 loss.
@@ -26,6 +28,7 @@ def smooth_l1_loss(pred, target, beta=1.0):
2628
return loss
2729

2830

31+
@mmcv.jit(derivate=True, coderize=True)
2932
@weighted_loss
3033
def l1_loss(pred, target):
3134
"""L1 loss.

mmdet/models/losses/utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22

3+
import mmcv
34
import torch.nn.functional as F
45

56

@@ -23,6 +24,7 @@ def reduce_loss(loss, reduction):
2324
return loss.sum()
2425

2526

27+
@mmcv.jit(derivate=True, coderize=True)
2628
def weight_reduce_loss(loss, weight=None, reduction='mean', avg_factor=None):
2729
"""Apply element-wise weight and reduce loss.
2830

mmdet/models/losses/varifocal_loss.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import mmcv
12
import torch.nn as nn
23
import torch.nn.functional as F
34

45
from ..builder import LOSSES
56
from .utils import weight_reduce_loss
67

78

9+
@mmcv.jit(derivate=True, coderize=True)
810
def varifocal_loss(pred,
911
target,
1012
weight=None,

0 commit comments

Comments
 (0)