MCPcopy
hub / github.com/microsoft/Cream / RemapLayer

Class RemapLayer

TinyViT/models/remap_layer.py:10–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class RemapLayer(nn.Module):
11 def __init__(self, fname):
12 super().__init__()
13 with open(fname) as fin:
14 self.mapping = torch.Tensor(
15 list(map(int, fin.readlines()))).to(torch.long)
16
17 def forward(self, x):
18 '''
19 x: [batch_size, class]
20 '''
21 B = len(x)
22 dummy_cls = x.new_zeros((B, 1))
23 expand_x = torch.cat([x, dummy_cls], dim=1)
24 return expand_x[:, self.mapping]

Callers 2

save_logits.pyFile · 0.90
main.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected