Title: Convolution Layers — PyTorch main documentation
Description: Convolution layers in PyTorch C++ — Conv1d, Conv2d, Conv3d, and transposed convolutions.
Keywords:
Domain: docs.pytorch.org
{
"@context": "https://schema.org",
"@type": "Article",
"name": "Convolution Layers",
"headline": "Convolution Layers",
"description": "Convolution layers in PyTorch C++ \u2014 Conv1d, Conv2d, Conv3d, and transposed convolutions.",
"url": "/api/nn/convolution.html",
"articleBody": "Convolution Layers# Convolutional layers apply learnable filters to input data, extracting local features through sliding window operations. They are fundamental to CNNs for image, audio, and sequential data processing. Conv1d/2d/3d: Standard convolution for 1D sequences, 2D images, or 3D volumes ConvTranspose1d/2d/3d: Transposed convolution (deconvolution) for upsampling Key parameters: in_channels: Number of input channels out_channels: Number of output channels (number of filters) kernel_size: Size of the convolving kernel stride: Stride of the convolution (default: 1) padding: Zero-padding added to input (default: 0) dilation: Spacing between kernel elements (default: 1) groups: Number of blocked connections (default: 1, use in_channels for depthwise) Conv1d# Applies 1D convolution over an input signal composed of several input planes. class Conv1d : public torch::nn::ModuleHolder\u003cConv1dImpl\u003e# A ModuleHolder subclass for Conv1dImpl. See the documentation for Conv1dImpl class to learn what methods it provides, and examples of how to use Conv1d with torch::nn::Conv1dOptions. See the documentation for ModuleHolder to learn about PyTorch\u2019s module storage semantics. Public Types using Impl = Conv1dImpl# class Conv1dImpl : public torch::nn::ConvNdImpl\u003c1, Conv1dImpl\u003e# Applies convolution over a 1-D input. See https://pytorch.org/docs/main/nn.html#torch.nn.Conv1d to learn about the exact behavior of this module. See the documentation for torch::nn::Conv1dOptions class to learn what constructor arguments are supported for this module. Example: Conv1d model(Conv1dOptions(3, 2, 3).stride(1).bias(false)); Public Functions inline Conv1dImpl(int64_t input_channels, int64_t output_channels, ExpandingArray\u003c1\u003e kernel_size)# explicit Conv1dImpl(Conv1dOptions options_)# Tensor forward(const Tensor \u0026input)# Conv2d# Applies 2D convolution over an input image. The most commonly used layer for image processing tasks. class Conv2d : public torch::nn::ModuleHolder\u003cConv2dImpl\u003e# A ModuleHolder subclass for Conv2dImpl. See the documentation for Conv2dImpl class to learn what methods it provides, and examples of how to use Conv2d with torch::nn::Conv2dOptions. See the documentation for ModuleHolder to learn about PyTorch\u2019s module storage semantics. Public Types using Impl = Conv2dImpl# class Conv2dImpl : public torch::nn::ConvNdImpl\u003c2, Conv2dImpl\u003e# Applies convolution over a 2-D input. See https://pytorch.org/docs/main/nn.html#torch.nn.Conv2d to learn about the exact behavior of this module. See the documentation for torch::nn::Conv2dOptions class to learn what constructor arguments are supported for this module. Example: Conv2d model(Conv2dOptions(3, 2, 3).stride(1).bias(false)); Public Functions inline Conv2dImpl(int64_t input_channels, int64_t output_channels, ExpandingArray\u003c2\u003e kernel_size)# explicit Conv2dImpl(Conv2dOptions options_)# Tensor forward(const Tensor \u0026input)# Example: // Create Conv2d: 3 input channels, 64 output channels, 3x3 kernel auto conv = torch::nn::Conv2d( torch::nn::Conv2dOptions(3, 64, 3) .stride(1) .padding(1) .bias(true)); auto output = conv-\u003eforward(input); // input: [N, 3, H, W] Conv3d# Applies 3D convolution over an input volume (e.g., video frames or 3D medical images). class Conv3d : public torch::nn::ModuleHolder\u003cConv3dImpl\u003e# A ModuleHolder subclass for Conv3dImpl. See the documentation for Conv3dImpl class to learn what methods it provides, and examples of how to use Conv3d with torch::nn::Conv3dOptions. See the documentation for ModuleHolder to learn about PyTorch\u2019s module storage semantics. Public Types using Impl = Conv3dImpl# class Conv3dImpl : public torch::nn::ConvNdImpl\u003c3, Conv3dImpl\u003e# Applies convolution over a 3-D input. See https://pytorch.org/docs/main/nn.html#torch.nn.Conv3d to learn about the exact behavior of this module. See the documentation for torch::nn::Conv3dOptions class to learn what constructor arguments are supported for this module. Example: Conv3d model(Conv3dOptions(3, 2, 3).stride(1).bias(false)); Public Functions inline Conv3dImpl(int64_t input_channels, int64_t output_channels, ExpandingArray\u003c3\u003e kernel_size)# explicit Conv3dImpl(Conv3dOptions options_)# Tensor forward(const Tensor \u0026input)# ConvTranspose1d# Applies 1D transposed convolution (fractionally-strided convolution) for upsampling. class ConvTranspose1d : public torch::nn::ModuleHolder\u003cConvTranspose1dImpl\u003e# A ModuleHolder subclass for ConvTranspose1dImpl. See the documentation for ConvTranspose1dImpl class to learn what methods it provides, and examples of how to use ConvTranspose1d with torch::nn::ConvTranspose1dOptions. See the documentation for ModuleHolder to learn about PyTorch\u2019s module storage semantics. Public Types using Impl = ConvTranspose1dImpl# class ConvTranspose1dImpl : public torch::nn::ConvTransposeNdImpl\u003c1, ConvTranspose1dImpl\u003e# Applies the ConvTranspose1d function. See https://pytorch.org/docs/main/nn.html#torch.nn.ConvTranspose1d to learn about the exact behavior of this module. See the documentation for torch::nn::ConvTranspose1dOptions class to learn what constructor arguments are supported for this module. Example: ConvTranspose1d model(ConvTranspose1dOptions(3, 2, 3).stride(1).bias(false)); Public Functions inline ConvTranspose1dImpl(int64_t input_channels, int64_t output_channels, ExpandingArray\u003c1\u003e kernel_size)# explicit ConvTranspose1dImpl(ConvTranspose1dOptions options_)# Tensor forward(const Tensor \u0026input, const std::optional\u003cat::IntArrayRef\u003e \u0026output_size = std::nullopt)# Friends friend struct torch::nn::AnyModuleHolder ConvTranspose2d# Applies 2D transposed convolution for upsampling. Commonly used in decoder networks and generative models. class ConvTranspose2d : public torch::nn::ModuleHolder\u003cConvTranspose2dImpl\u003e# A ModuleHolder subclass for ConvTranspose2dImpl. See the documentation for ConvTranspose2dImpl class to learn what methods it provides, and examples of how to use ConvTranspose2d with torch::nn::ConvTranspose2dOptions. See the documentation for ModuleHolder to learn about PyTorch\u2019s module storage semantics. Public Types using Impl = ConvTranspose2dImpl# class ConvTranspose2dImpl : public torch::nn::ConvTransposeNdImpl\u003c2, ConvTranspose2dImpl\u003e# Applies the ConvTranspose2d function. See https://pytorch.org/docs/main/nn.html#torch.nn.ConvTranspose2d to learn about the exact behavior of this module. See the documentation for torch::nn::ConvTranspose2dOptions class to learn what constructor arguments are supported for this module. Example: ConvTranspose2d model(ConvTranspose2dOptions(3, 2, 3).stride(1).bias(false)); Public Functions inline ConvTranspose2dImpl(int64_t input_channels, int64_t output_channels, ExpandingArray\u003c2\u003e kernel_size)# explicit ConvTranspose2dImpl(ConvTranspose2dOptions options_)# Tensor forward(const Tensor \u0026input, const std::optional\u003cat::IntArrayRef\u003e \u0026output_size = std::nullopt)# Friends friend struct torch::nn::AnyModuleHolder Example: // Create ConvTranspose2d for upsampling auto conv_transpose = torch::nn::ConvTranspose2d( torch::nn::ConvTranspose2dOptions(64, 32, 4) .stride(2) .padding(1)); ConvTranspose3d# Applies 3D transposed convolution for upsampling volumetric data. class ConvTranspose3d : public torch::nn::ModuleHolder\u003cConvTranspose3dImpl\u003e# A ModuleHolder subclass for ConvTranspose3dImpl. See the documentation for ConvTranspose3dImpl class to learn what methods it provides, and examples of how to use ConvTranspose3d with torch::nn::ConvTranspose3dOptions. See the documentation for ModuleHolder to learn about PyTorch\u2019s module storage semantics. Public Types using Impl = ConvTranspose3dImpl# class ConvTranspose3dImpl : public torch::nn::ConvTransposeNdImpl\u003c3, ConvTranspose3dImpl\u003e# Applies the ConvTranspose3d function. See https://pytorch.org/docs/main/nn.html#torch.nn.ConvTranspose3d to learn about the exact behavior of this module. See the documentation for torch::nn::ConvTranspose3dOptions class to learn what constructor arguments are supported for this module. Example: ConvTranspose3d model(ConvTranspose3dOptions(2, 2, 2).stride(1).bias(false)); Public Functions inline ConvTranspose3dImpl(int64_t input_channels, int64_t output_channels, ExpandingArray\u003c3\u003e kernel_size)# explicit ConvTranspose3dImpl(ConvTranspose3dOptions options_)# Tensor forward(const Tensor \u0026input, const std::optional\u003cat::IntArrayRef\u003e \u0026output_size = std::nullopt)# Friends friend struct torch::nn::AnyModuleHolder",
"author": {
"@type": "Organization",
"name": "PyTorch Contributors",
"url": "https://pytorch.org"
},
"image": "https://pytorch.org/docs/stable/_static/img/pytorch_seo.png",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "/api/nn/convolution.html"
},
"datePublished": "2023-01-01T00:00:00Z",
"dateModified": "2023-01-01T00:00:00Z"
}
| docsearch:language | en |
| llm:site-type | documentation |
| llm:framework | PyTorch |
| llm:description | Convolution layers in PyTorch C++ — Conv1d, Conv2d, Conv3d, and transposed convolutions. |
| llm:navigation-file | https://pytorch.org/docs/stable/llms.txt |
| llm:sitemap | https://pytorch.org/docs/stable/sitemap.xml |
| llm:version | main |
| llm:project | PyTorch |
| llm:page-type | documentation |
| og:image | https://docs.pytorch.org/docs/stable/_static/img/pytorch_seo.png |
| None | 3 |
Links:
Viewport: width=device-width, initial-scale=1