栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

torch.nn.modules.linear—Bilinear

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

torch.nn.modules.linear—Bilinear

功能描述

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/589338.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号