torch.nn.modules.linear—Bilinear

本文介绍了PyTorch中的Bilinear模块,用于执行双线性变换。该模块接受两个输入,其最后一个维度应匹配参数设置。输出同样保持其他维度不变。内容包括功能描述、形状规则和实例应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

功能描述

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)
module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.1 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'. If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2. Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\python\anaconda3\envs\yolov8\lib\site-packages\torch\__init__.py", line 643, in <module> from .functional import * # noqa: F403 File "D:\python\anaconda3\envs\yolov8\lib\site-packages\torch\functional.py", line 6, in <module> import torch.nn.functional as F File "D:\python\anaconda3\envs\yolov8\lib\site-packages\torch\nn\__init__.py", line 1, in <module> from .modules import * # noqa: F403 File "D:\python\anaconda3\envs\yolov8\lib\site-packages\torch\nn\modules\__init__.py", line 2, in <module> from .linear import Identity, Linear, Bilinear, LazyLinear File "D:\python\anaconda3\envs\yolov8\lib\site-packages\torch\nn\modules\linear.py", line 6, in <module> from .. import functional as F File "D:\python\anaconda3\envs\yolov8\lib\site-packages\torch\nn\functional.py", line 11, in <module> from .._jit_internal import boolean_dispatch, _overload, BroadcastingList1, BroadcastingList2, BroadcastingList3 File "D:\python\anaconda3\envs\yolov8\lib\site-packages\torch\_jit_internal.py", line 28, in <module> import torch.package._mangling as package_mangling File "D:\python\anaconda3\envs\yolov8\lib\site-packages\torch\package\__init__.py", line 12, in <module> from .package_importer import PackageImporter File "D:\python\anaconda3\envs\yolov8\lib\site-packages\torch\package\package_importer.py", line 16, in <module> from ._directory_reader import DirectoryReader File "D:\python\anaconda3\envs\yolov8\lib\site-packages\torch\package\_
03-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值