当前位置:网站首页>torch. nn. Simple understanding of parameter / / to be continued. Let me understand this paragraph
torch. nn. Simple understanding of parameter / / to be continued. Let me understand this paragraph
2022-06-10 20:57:00 【Thinking and Practice】
# ########## fourier layer #############
class FourierBlock(nn.Module):
def __init__(self, in_channels, out_channels, seq_len, modes=0, mode_select_method='random'):
super(FourierBlock, self).__init__()
print('fourier enhanced block used!')
"""
1D Fourier block. It performs representation learning on frequency domain,
it does FFT, linear transform, and Inverse FFT.
"""
# get modes on frequency domain
self.index = get_frequency_modes(seq_len, modes=modes, mode_select_method=mode_select_method)# Get the randomly selected basis , Follow up DFT operation
print('modes={}, index={}'.format(modes, self.index))
self.scale = (1 / (in_channels * out_channels))
self.weights1 = nn.Parameter(
self.scale * torch.rand(8, in_channels // 8, out_channels // 8, len(self.index), dtype=torch.cfloat))
# Complex multiplication Complex multiplication
def compl_mul1d(self, input, weights):
# (batch, in_channel, x ), (in_channel, out_channel, x) -> (batch, out_channel, x)
return torch.einsum("bhi,hio->bho", input, weights)# Calculation of high dimensional tensors
# Understand this torch.einsum operation !!!
def forward(self, q, k, v, mask):
# size = [B, L, H, E]
B, L, H, E = q.shape
x = q.permute(0, 2, 3, 1)
# Compute Fourier coefficients
x_ft = torch.fft.rfft(x, dim=-1)
# Perform Fourier neural operations
out_ft = torch.zeros(B, H, E, L // 2 + 1, device=x.device, dtype=torch.cfloat)
for wi, i in enumerate(self.index):
out_ft[:, :, :, wi] = self.compl_mul1d(x_ft[:, :, :, i], self.weights1[:, :, :, wi])
# Return to time domain
x = torch.fft.irfft(out_ft, n=x.size(-1))
return (x, None)
torch.nn.Parameter understand _Stoneplay26 The blog of -CSDN Blog _torch.nn.parameter
PyTorch Inside torch.nn.Parameter()_ J-choice . The blog of -CSDN Blog _torch.nn.parameter
Reference material
torch.nn.Parameter()_chenzy_hust The blog of -CSDN Blog _nn.parameter()
边栏推荐
- Node (express) implements interfaces such as adding, deleting, modifying, and paging
- vulnhub-The Planets: Earth
- Mixin -- mixed
- 2 pcs share a set of keyboard and mouse
- Li Kou 10821084 solution_ Question of SQL query type
- 玩艺术也得学数学?
- 自定义日期组件,左右按钮控制向前或向后翻年、翻月、翻周、翻日
- H5 van popup full screen pop-up window, simulates the page fallback effect, supports the return button in the upper left corner, and is suitable for physical return, side sliding and bottom return key
- Diablo immortal wiki address Diablo immortal database address sharing
- Microsoft Word 教程「5」,如何在 Word 中更改页边距、创建新闻稿栏?
猜你喜欢

详解三级缓存解决循环依赖

自定义日期组件,左右按钮控制向前或向后翻年、翻月、翻周、翻日

An old programmer of about 10 years said: simple crud function enters the era of codeless development 1. Adding, deleting, modifying and checking interface information

玩艺术也得学数学?
![js基础及常考面试题之 [] == ![]结果为true, []==[]结果为false 详解](/img/42/bcda46a9297a544b44fea31be3f686.png)
js基础及常考面试题之 [] == ![]结果为true, []==[]结果为false 详解

安全隐患?意义有限?挡不住真煮迷你厨具火爆618

2 pcs share a set of keyboard and mouse

synergy: server refused client with our name

Microsoft Word tutorial "5", how to change the margins and create a newsletter column in word?

Arduino中Serial.print()与Serial.write()函数的区别,以及串口通信中十六进制与字符串的收发格式问题和转换过程详解
随机推荐
C语言 浮点数 储存形式
农产品期货开户的条件是什么?现在开户的手续费是多少?
How to use Diablo immortal database
【legendre】多项式
NetWorkX使用方法及 nx.draw()相关参数
Is Jiuzhou futures regular? Is it safe to open an account
Diablo immortal wiki address Diablo immortal database address sharing
連接mysql報錯 errorCode 1129, state HY000, Host ‘xxx‘ is blocked because of many connection errors
72. 编辑距离 ●●●
【Educational Codeforces Round 120 (Rated for Div. 2)】C. Set or Decrease
H5 van popup full screen pop-up window, simulates the page fallback effect, supports the return button in the upper left corner, and is suitable for physical return, side sliding and bottom return key
canvas 高级功能(中)
H5 van-popup全屏弹窗,模拟页面回退效果,支持左上角返回按钮,适用物理返回,侧滑与底部返回键
Networkx usage and nx Draw() related parameters
[FAQ] summary of common problems and solutions during the use of rest API interface of sports health service
Cloud native community boss blog
View play and earn will lead crypto games astray
在阿里云国际上使用 OSS 和 CDN 部署静态网站
获取列表中最大最小值的前n个数值的位置索引的四种方法
canvas 高级功能(上)