pub struct Conv1d { /* private fields */ }Expand description
1D Convolution layer.
Applies a 1D convolution over an input signal composed of several input planes.
§Shape
- Input:
(N, C_in, L)where N is batch size,C_inis input channels, L is length - Output:
(N, C_out, L_out)whereL_out= (L + 2*padding -kernel_size) / stride + 1
§Example
ⓘ
use aprender::nn::{Conv1d, Module};
use aprender::autograd::Tensor;
let conv = Conv1d::new(16, 32, 3); // 16 in channels, 32 out channels, kernel size 3
let x = Tensor::randn(&[4, 16, 100]); // batch of 4, 16 channels, length 100
let y = conv.forward(&x); // [4, 32, 98]Implementations§
Source§impl Conv1d
impl Conv1d
Sourcepub fn new(in_channels: usize, out_channels: usize, kernel_size: usize) -> Self
pub fn new(in_channels: usize, out_channels: usize, kernel_size: usize) -> Self
Create a new Conv1d layer.
§Arguments
in_channels- Number of input channelsout_channels- Number of output channelskernel_size- Size of the convolving kernel
Sourcepub fn with_options(
in_channels: usize,
out_channels: usize,
kernel_size: usize,
stride: usize,
padding: usize,
bias: bool,
) -> Self
pub fn with_options( in_channels: usize, out_channels: usize, kernel_size: usize, stride: usize, padding: usize, bias: bool, ) -> Self
Create Conv1d with custom options.
§Arguments
in_channels- Number of input channelsout_channels- Number of output channelskernel_size- Size of the convolving kernelstride- Stride of the convolutionpadding- Zero-padding added to both sidesbias- If true, adds a learnable bias
Sourcepub fn with_layout(
in_channels: usize,
out_channels: usize,
kernel_size: usize,
stride: usize,
padding: usize,
bias: bool,
layout: ConvLayout,
) -> Self
pub fn with_layout( in_channels: usize, out_channels: usize, kernel_size: usize, stride: usize, padding: usize, bias: bool, layout: ConvLayout, ) -> Self
Create Conv1d with a specific data layout.
§Arguments
in_channels- Number of input channelsout_channels- Number of output channelskernel_size- Size of the convolving kernelstride- Stride of the convolutionpadding- Zero-padding added to both sidesbias- If true, adds a learnable biaslayout- Data layout for input/output tensors
Sourcepub fn with_stride(
in_channels: usize,
out_channels: usize,
kernel_size: usize,
stride: usize,
) -> Self
pub fn with_stride( in_channels: usize, out_channels: usize, kernel_size: usize, stride: usize, ) -> Self
Create Conv1d with specific stride.
Sourcepub fn with_padding(
in_channels: usize,
out_channels: usize,
kernel_size: usize,
padding: usize,
) -> Self
pub fn with_padding( in_channels: usize, out_channels: usize, kernel_size: usize, padding: usize, ) -> Self
Create Conv1d with padding.
Sourcepub fn kernel_size(&self) -> usize
pub fn kernel_size(&self) -> usize
Get kernel size.
Trait Implementations§
Source§impl Module for Conv1d
impl Module for Conv1d
Source§fn parameters_mut(&mut self) -> Vec<&mut Tensor>
fn parameters_mut(&mut self) -> Vec<&mut Tensor>
Get mutable references to all learnable parameters. Read more
Source§fn refresh_caches(&mut self)
fn refresh_caches(&mut self)
Refresh any cached computations after parameters have been modified. Read more
Source§fn num_parameters(&self) -> usize
fn num_parameters(&self) -> usize
Get the number of learnable parameters.
Auto Trait Implementations§
impl Freeze for Conv1d
impl !RefUnwindSafe for Conv1d
impl Send for Conv1d
impl Sync for Conv1d
impl Unpin for Conv1d
impl UnsafeUnpin for Conv1d
impl !UnwindSafe for Conv1d
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more