文章目录
1. conv1d
conv1d的作用是进行一维的卷积计算,将卷积核沿着输入矩阵进行一维卷积,具体参考如下excel
通过网盘分享的文件:conv1d.xlsx
链接: https://pan.baidu.com/s/1WIM4Pp5nwa-uP67TMP-m8Q?pwd=uti7 提取码: uti7
2. pytorch 源码
import torch
import torch.nn as nn
import torch.nn.functional as F
torch.set_printoptions(precision=3, sci_mode=False)
if __name__ == "__main__":
run_code = 0
# in_channels: int,
# out_channels: int,
# kernel_size: _size_1_t,
# stride: _size_1_t = 1,
# padding: Union[str, _size_1_t] = 0,
# dilation: _size_1_t = 1,
# groups: int = 1,
# bias: bool = True,
# padding_mode: str = 'zeros', # TODO: refine this type
# device = None,
# dtype = None
in_channels = 3
out_channels = 4
kernel_size = 2
stride = 1
my_weight_total = out_channels * in_channels * kernel_size
my_weight = torch.arange(my_weight_total).reshape((out_channels, in_channels, kernel_size)).to(torch.float32)
my_conv1d = nn.Conv1d(in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride=stride)
my_bias = torch.arange(out_channels).to(torch.float32)
print(my_conv1d)
print(my_conv1d.weight.shape)
my_conv1d.weight = nn.Parameter(my_weight)
my_conv1d.bias = nn.Parameter(my_bias)
for p in my_conv1d.named_parameters():
print(p)
batch_size =

最低0.47元/天 解锁文章
1031

被折叠的 条评论
为什么被折叠?



