数学基本知识2-卷积输入输出通道计算
卷积的计算,涉及输入通道,输出通道,步长,卷积核大小等,在神经网络的计算中,计算输入输出的通道是设计网络的关键。本文主要介绍了卷积输入输出的主要方法和采用tensorboardx查看网络模型的介绍。
一、nn.Conv1d 一维卷积计算
(1)一维的卷积能处理多维数据
nn.Conv2d(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True))
参数:
in_channel: 输入数据的通道数,例RGB图片通道数为3;
out_channel: 输出数据的通道数,这个根据模型调整;
kennel_size: 卷积核大小,可以是int,或tuple;kennel_size=2,意味着卷积大小2, kennel_size=(2,3),意味着卷积在第一维度大小为2,在第二维度大小为3;
stride:步长,默认为1,与kennel_size类似,stride=2,意味在所有维度步长为2, stride=(2,3),意味着在第一维度步长为2,意味着在第二维度步长为3;
padding: 零填充
(2)代码示例
// An highlighted block
import torch
import torch.nn as nn
import torch.nn.functional as F
from tensorboardX import SummaryWriter
x = torch.randn(10, 16, 30, 32, 34)
# batch, channel , height , width
print(x.shape)
class Net_1D(nn.Module):
def __init__(self):
super(Net_1D, self).__init__()
self.layers = nn.Sequential(
nn.Conv1d(in_channels=16, out_channels=