MCPcopy Create free account
hub / github.com/WeChatCV/WeVisionOne / RandomBoxPerturber

Class RandomBoxPerturber

WeVisionOne/pixel_decoder/groundingdino/utils.py:118–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116
117
118class RandomBoxPerturber:
119 def __init__(
120 self, x_noise_scale=0.2, y_noise_scale=0.2, w_noise_scale=0.2, h_noise_scale=0.2
121 ) -> None:
122 self.noise_scale = torch.Tensor(
123 [x_noise_scale, y_noise_scale, w_noise_scale, h_noise_scale]
124 )
125
126 def __call__(self, refanchors: Tensor) -> Tensor:
127 nq, bs, query_dim = refanchors.shape
128 device = refanchors.device
129
130 noise_raw = torch.rand_like(refanchors)
131 noise_scale = self.noise_scale.to(device)[:query_dim]
132
133 new_refanchors = refanchors * (1 + (noise_raw - 0.5) * noise_scale)
134 return new_refanchors.clamp_(0, 1)
135
136
137class MLP(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected