MCPcopy Create free account
hub / github.com/YXB-NKU/Strip-R-CNN / CSLCoder

Class CSLCoder

mmrotate/core/bbox/coder/angle_coder.py:11–114  ·  view source on GitHub ↗

Circular Smooth Label Coder. `Circular Smooth Label (CSL) `_ . Args: angle_version (str): Angle definition. omega (float, optional): Angle discretization granularity. Default: 1. window

Source from the content-addressed store, hash-verified

9
10@ROTATED_BBOX_CODERS.register_module()
11class CSLCoder(BaseBBoxCoder):
12 """Circular Smooth Label Coder.
13
14 `Circular Smooth Label (CSL)
15 <https://link.springer.com/chapter/10.1007/978-3-030-58598-3_40>`_ .
16
17 Args:
18 angle_version (str): Angle definition.
19 omega (float, optional): Angle discretization granularity.
20 Default: 1.
21 window (str, optional): Window function. Default: gaussian.
22 radius (int/float): window radius, int type for
23 ['triangle', 'rect', 'pulse'], float type for
24 ['gaussian']. Default: 6.
25 """
26
27 def __init__(self, angle_version, omega=1, window='gaussian', radius=6):
28 super().__init__()
29 self.angle_version = angle_version
30 assert angle_version in ['oc', 'le90', 'le135']
31 assert window in ['gaussian', 'triangle', 'rect', 'pulse']
32 self.angle_range = 90 if angle_version == 'oc' else 180
33 self.angle_offset_dict = {'oc': 0, 'le90': 90, 'le135': 45}
34 self.angle_offset = self.angle_offset_dict[angle_version]
35 self.omega = omega
36 self.window = window
37 self.radius = radius
38 self.coding_len = int(self.angle_range // omega)
39
40 def encode(self, angle_targets):
41 """Circular Smooth Label Encoder.
42
43 Args:
44 angle_targets (Tensor): Angle offset for each scale level
45 Has shape (num_anchors * H * W, 1)
46
47 Returns:
48 list[Tensor]: The csl encoding of angle offset for each
49 scale level. Has shape (num_anchors * H * W, coding_len)
50 """
51
52 # radius to degree
53 angle_targets_deg = angle_targets * (180 / math.pi)
54 # empty label
55 smooth_label = torch.zeros_like(angle_targets).repeat(
56 1, self.coding_len)
57 angle_targets_deg = (angle_targets_deg +
58 self.angle_offset) / self.omega
59 # Float to Int
60 angle_targets_long = angle_targets_deg.long()
61
62 if self.window == 'pulse':
63 radius_range = angle_targets_long % self.coding_len
64 smooth_value = 1.0
65 elif self.window == 'rect':
66 base_radius_range = torch.arange(
67 -self.radius, self.radius, device=angle_targets_long.device)
68 radius_range = (base_radius_range +

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected