MCPcopy Create free account
hub / github.com/MotrixLab/MotionDiffuse / PositionalEncoding

Class PositionalEncoding

text2motion/datasets/evaluator_models.py:62–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60
61
62class PositionalEncoding(nn.Module):
63
64 def __init__(self, d_model, max_len=300):
65 super(PositionalEncoding, self).__init__()
66
67 pe = torch.zeros(max_len, d_model)
68 position = torch.arange(0, max_len, dtype=torch.float).unsqueeze(1)
69 div_term = torch.exp(torch.arange(0, d_model, 2).float() * (-math.log(10000.0) / d_model))
70 pe[:, 0::2] = torch.sin(position * div_term)
71 pe[:, 1::2] = torch.cos(position * div_term)
72 # pe = pe.unsqueeze(0).transpose(0, 1)
73 self.register_buffer('pe', pe)
74
75 def forward(self, pos):
76 return self.pe[pos]
77
78
79class MovementConvEncoder(nn.Module):

Callers 2

__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected