手动计算conv1d 及pytorch源码

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 = 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值