MCPcopy Create free account
hub / github.com/294coder/Dif-PAN / PositionalEncoding

Class PositionalEncoding

models/sr3.py:211–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209
210# PositionalEncoding Source: https://github.com/lmnt-com/wavegrad/blob/master/src/wavegrad/model.py
211class PositionalEncoding(nn.Module):
212 def __init__(self, dim):
213 super().__init__()
214 self.dim = dim
215
216 def forward(self, noise_level):
217 count = self.dim // 2
218 step = (
219 torch.arange(count, dtype=noise_level.dtype, device=noise_level.device)
220 / count
221 )
222 encoding = noise_level.unsqueeze(1) * torch.exp(
223 -math.log(1e4) * step.unsqueeze(0)
224 )
225 encoding = torch.cat([torch.sin(encoding), torch.cos(encoding)], dim=-1)
226 return encoding
227
228
229class FeatureWiseAffine(nn.Module):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected