功能描述
Applies a bilinear transformation to the incoming data: math:`y = x_1^T A x_2 + b`
Shape:
Input1: (N, *, Hin1) where Hin1 = in1_features and * means any number of additional dimensions. All but the last dimension of the inputs should be the same.
Input2: (N, *, Hin2) where Hin2 = in2_features.
Output: (N, *, Hout) where Hout = out_features and all but the last dimension are the same shape as the input.
该函数主要的作用是对于输入的数据进行双线性的变换,它有两个输入,并且对于输入、输出的最后一个维度应该和nn.Bilinear(in1_features,in2_features,out_features)是相同的。在该函数中bias服从均匀分布
examples:# 导入所需要的包 import torch import torch.nn as nn # 对于输入数据进行双线性变换 math:`y = x_1^T A x_2 + b` # ['in1_features', 'in2_features', 'out_features'] m=nn.Bilinear(50,20,10) input1 = torch.randn(256,50) input2 = torch.randn(256,20) output = m(input1,input2) print("output is {}".format(output)) print(output.size())
result:
output is tensor([[ 2.1250, -1.6710, 0.4189, ..., -3.0687, -1.3695, -2.9742], [-0.4245, -3.0566, -2.1428, ..., 4.7407, 4.0031, -4.6528], [ 0.7700, 2.9252, -1.7279, ..., 1.9816, -0.4914, -1.9483], ..., [ 2.7378, -0.9335, 2.3370, ..., 1.3155, -6.5961, -2.6716], [-4.0953, 4.5987, -4.3022, ..., -0.6784, -1.0126, -0.6979], [ 0.4568, 1.4662, 0.3095, ..., -0.3748, 4.5659, 2.3969]], grad_fn=) torch.Size([256, 10])
官方文档:Bilinear — PyTorch 1.10.0 documentationhttps://pytorch.org/docs/stable/generated/torch.nn.Bilinear.html?highlight=bilinear#torch.nn.Bilinear
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)