MCPcopy Create free account
hub / github.com/ChunmingHe/WS-SAM / SoftPositionEmbed

Class SoftPositionEmbed

lib/Slot.py:20–37  ·  view source on GitHub ↗

Adds soft positional embedding with learnable projection.

Source from the content-addressed store, hash-verified

18
19
20class SoftPositionEmbed(nn.Module):
21 """Adds soft positional embedding with learnable projection."""
22
23 def __init__(self, hidden_size, resolution):
24 """Builds the soft position embedding layer.
25
26 Args:
27 hidden_size: Size of input feature dimension.
28 resolution: Tuple of integers specifying width and height of grid.
29 """
30 super(SoftPositionEmbed, self).__init__()
31 self.proj = nn.Linear(4, hidden_size)
32 self.grid = build_grid(resolution)
33
34 def forward(self, inputs):
35 device = inputs.device
36 self.grid = self.grid.to(device)
37 return inputs + self.proj(self.grid)
38
39
40def spatial_broadcast(slots, resolution):

Callers 4

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.85
Slot.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected