Apply the Fourier feature transformation to the input tensor. Args: x (torch.Tensor): The input tensor. gain (float, optional): An additional gain factor applied during the forward pass. Defaults to 1. Returns: torch.Tensor: The transfor
(self, x: torch.Tensor, gain: float = 1.0)
| 770 | self.phases = 2 * np.pi * torch.rand(self.num_channels, generator=generator).to(self.freqs.device) |
| 771 | |
| 772 | def forward(self, x: torch.Tensor, gain: float = 1.0) -> torch.Tensor: |
| 773 | """ |
| 774 | Apply the Fourier feature transformation to the input tensor. |
| 775 | |
| 776 | Args: |
| 777 | x (torch.Tensor): The input tensor. |
| 778 | gain (float, optional): An additional gain factor applied during the forward pass. Defaults to 1. |
| 779 | |
| 780 | Returns: |
| 781 | torch.Tensor: The transformed tensor, with Fourier features applied. |
| 782 | """ |
| 783 | in_dtype = x.dtype |
| 784 | x = x.to(torch.float32).ger(self.freqs.to(torch.float32)).add(self.phases.to(torch.float32)) |
| 785 | x = x.cos().mul(self.gain * gain).to(in_dtype) |
| 786 | return x |
| 787 | |
| 788 | |
| 789 | class PatchEmbed(nn.Module): |