首页 > 其他 > 详细

linear_func

时间:2019-09-25 19:46:51      阅读:81      评论:0      收藏:0      [点我收藏+]
‘‘‘


class torch.nn.Linear(in_features,out_features,bias = True )[来源]

技术分享图片

 

 

参数:


in_features - 每个输入样本的大小
out_features - 每个输出样本的大小
bias - 如果设置为False,则图层不会学习附加偏差。默认值:True
‘‘‘



import torch


x = torch.randn(3, 2) # 输入的维度是(3,2)
m = torch.nn.Linear(2, 4) # 2,4是指维度
output = m(x)
print("x",x)
print(‘m.weight.shape:\n ‘, m.weight.shape,m.weight)
print(‘m.bias.shape:\n‘, m.bias.shape,m.bias)
print(‘output.shape:\n‘, output.shape,output)
‘‘‘
x tensor([[-0.4972, 1.2745],
[ 1.2993, -0.6580],
[-0.2165, 0.8603]])

m.weight.shape:torch.Size([4, 2]) Parameter containing:
tensor([[-0.5528, -0.1309],
[ 0.6907, 0.5723],
[-0.2242, 0.1904],
[ 0.1678, -0.6903]], requires_grad=True)

m.bias.shape:torch.Size([4]) Parameter containing:
tensor([-0.1663, -0.0111, 0.4852, 0.5688], requires_grad=True)

output.shape:torch.Size([3, 4])
tensor([[-0.0584, 0.3749, 0.8394, -0.3944],
[-0.7984, 0.5097, 0.0685, 1.2410],
[-0.1593, 0.3317, 0.6975, -0.0614]], grad_fn=<AddmmBackward>)


-0.4972*-0.5528+1.2745* -0.1309+-0.1663=-0.0584
‘‘‘

linear_func

原文:https://www.cnblogs.com/hapyygril/p/11586860.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!