Struct dfdx::nn::modules::Conv2D

source ·
pub struct Conv2D<const IN_CHAN: usize, const OUT_CHAN: usize, const KERNEL_SIZE: usize, const STRIDE: usize, const PADDING: usize, const DILATION: usize, const GROUPS: usize, E: Dtype, D: Storage<E>>where
    Const<{ _ }>: Sized,{
    pub weight: Tensor<Rank4<OUT_CHAN, { _ }, KERNEL_SIZE, KERNEL_SIZE>, E, D>,
}
Expand description

Requires Nightly Performs unbiased 2d convolutions on 3d and 4d images.

Pytorch Equivalent: torch.nn.Conv2d(..., bias=False)

To create a biased conv, combine with crate::nn::modules::Bias2D:

type BiasedConv = (Conv2D<3, 5, 4>, Bias2D<5>);

Generics:

  • IN_CHAN: The number of input channels in an image.
  • OUT_CHAN: The number of channels in the output of the layer.
  • KERNEL_SIZE: The size of the kernel applied to both width and height of the images.
  • STRIDE: How far to move the kernel each step. Defaults to 1
  • PADDING: How much zero padding to add around the images. Defaults to 0.
  • DILATION: Controls the spacing between kernel points. Defaults to 1.
  • GROUPS: Controls the connections between inputs and outputs. IN_CHAN and OUT_CHAN must both be divisible by GROUPS. For example,

See conv animations for helpful visualization of all of these parameters.

Fields§

§weight: Tensor<Rank4<OUT_CHAN, { _ }, KERNEL_SIZE, KERNEL_SIZE>, E, D>

Trait Implementations§

source§

impl<const IN_CHAN: usize, const OUT_CHAN: usize, const KERNEL_SIZE: usize, const STRIDE: usize, const PADDING: usize, const DILATION: usize, const GROUPS: usize, E: Clone + Dtype, D: Clone + Storage<E>> Clone for Conv2D<IN_CHAN, OUT_CHAN, KERNEL_SIZE, STRIDE, PADDING, DILATION, GROUPS, E, D>where Const<{ _ }>: Sized,

source§

fn clone( &self ) -> Conv2D<IN_CHAN, OUT_CHAN, KERNEL_SIZE, STRIDE, PADDING, DILATION, GROUPS, E, D>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const IN_CHAN: usize, const OUT_CHAN: usize, const KERNEL_SIZE: usize, const STRIDE: usize, const PADDING: usize, const DILATION: usize, const GROUPS: usize, E: Debug + Dtype, D: Debug + Storage<E>> Debug for Conv2D<IN_CHAN, OUT_CHAN, KERNEL_SIZE, STRIDE, PADDING, DILATION, GROUPS, E, D>where Const<{ _ }>: Sized,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const I: usize, const O: usize, const K: usize, const S: usize, const P: usize, const L: usize, const G: usize, E, D, Img> Module<Img> for Conv2D<I, O, K, S, P, L, G, E, D>where Const<{ _ }>: Sized, E: Dtype, D: Device<E>, (Img, Tensor<Rank4<O, { _ }, K, K>, E, D>): TryConv2D<Const<S>, Const<P>, Const<L>, Const<G>>,

§

type Output = <(Img, Tensor<(Const<O>, Const<{ I / G }>, Const<K>, Const<K>), E, D, NoneTape>) as TryConv2D<Const<S>, Const<P>, Const<L>, Const<G>>>::Convolved

The type that this unit produces given Input.
§

type Error = <(Img, Tensor<(Const<O>, Const<{ I / G }>, Const<K>, Const<K>), E, D, NoneTape>) as TryConv2D<Const<S>, Const<P>, Const<L>, Const<G>>>::Error

source§

fn try_forward(&self, x: Img) -> Result<Self::Output, Self::Error>

source§

fn forward(&self, input: Input) -> Self::Output

Forward Input through the module and produce Module::Output. Read more
source§

impl<const I: usize, const O: usize, const K: usize, const S: usize, const P: usize, const L: usize, const G: usize, E, D> TensorCollection<E, D> for Conv2D<I, O, K, S, P, L, G, E, D>where Const<{ _ }>: Sized, E: Dtype + Float + SampleUniform, D: Device<E>,

§

type To<E2: Dtype, D2: Device<E2>> = Conv2D<I, O, K, S, P, L, G, E2, D2>

Type alias that specifies the how a module’s type changes when using a different dtype and/or device.
source§

fn iter_tensors<V: ModuleVisitor<Self, E, D>>( visitor: &mut V ) -> Result<Option<Self::To<V::E2, V::D2>>, V::Err>

Specifies how to iterate through tensors or modules containted within this module, and how to contruct this module given values for its fields. Returns Err(_) to indicate an error, Ok(None) to indicate that there is no error and a module has not been built, and Ok(Some(_)) contains Self::Output<E2, D2>
source§

fn module<F1, F2, Field>( name: &str, get_ref: F1, get_mut: F2 ) -> ModuleField<'_, F1, F2, Self, Field>where F1: FnMut(&Self) -> &Field, F2: FnMut(&mut Self) -> &mut Field, Field: TensorCollection<E, D>,

Creates a ModuleFields that represents a field that may contain one or more tensors. Read more
source§

fn tensor<F1, F2, S>( name: &str, get_ref: F1, get_mut: F2, options: TensorOptions<S, E, D> ) -> TensorField<'_, F1, F2, Self, S, E, D>where F1: FnMut(&Self) -> &Tensor<S, E, D>, F2: FnMut(&mut Self) -> &mut Tensor<S, E, D>, S: Shape,

Creates a ModuleFields that represents a tensor field. Read more
source§

fn scalar<F1, F2, N>( name: &str, get_ref: F1, get_mut: F2, options: ScalarOptions<N> ) -> ScalarField<'_, F1, F2, Self, N>where F1: FnMut(&Self) -> &N, F2: FnMut(&mut Self) -> &mut N, N: NumCast,

Creates a ModuleFields that represents a scalar field. Read more
source§

impl<const I: usize, const O: usize, const K: usize, const S: usize, const P: usize, const L: usize, const G: usize, E: Dtype, D: Storage<E>> NonMutableModule for Conv2D<I, O, K, S, P, L, G, E, D>where Const<{ _ }>: Sized,

Auto Trait Implementations§

§

impl<const IN_CHAN: usize, const OUT_CHAN: usize, const KERNEL_SIZE: usize, const STRIDE: usize, const PADDING: usize, const DILATION: usize, const GROUPS: usize, E, D> RefUnwindSafe for Conv2D<IN_CHAN, OUT_CHAN, KERNEL_SIZE, STRIDE, PADDING, DILATION, GROUPS, E, D>where D: RefUnwindSafe, <D as Storage<E>>::Vec: RefUnwindSafe,

§

impl<const IN_CHAN: usize, const OUT_CHAN: usize, const KERNEL_SIZE: usize, const STRIDE: usize, const PADDING: usize, const DILATION: usize, const GROUPS: usize, E, D> Send for Conv2D<IN_CHAN, OUT_CHAN, KERNEL_SIZE, STRIDE, PADDING, DILATION, GROUPS, E, D>where D: Send,

§

impl<const IN_CHAN: usize, const OUT_CHAN: usize, const KERNEL_SIZE: usize, const STRIDE: usize, const PADDING: usize, const DILATION: usize, const GROUPS: usize, E, D> Sync for Conv2D<IN_CHAN, OUT_CHAN, KERNEL_SIZE, STRIDE, PADDING, DILATION, GROUPS, E, D>where D: Sync,

§

impl<const IN_CHAN: usize, const OUT_CHAN: usize, const KERNEL_SIZE: usize, const STRIDE: usize, const PADDING: usize, const DILATION: usize, const GROUPS: usize, E, D> Unpin for Conv2D<IN_CHAN, OUT_CHAN, KERNEL_SIZE, STRIDE, PADDING, DILATION, GROUPS, E, D>where D: Unpin,

§

impl<const IN_CHAN: usize, const OUT_CHAN: usize, const KERNEL_SIZE: usize, const STRIDE: usize, const PADDING: usize, const DILATION: usize, const GROUPS: usize, E, D> UnwindSafe for Conv2D<IN_CHAN, OUT_CHAN, KERNEL_SIZE, STRIDE, PADDING, DILATION, GROUPS, E, D>where D: UnwindSafe, <D as Storage<E>>::Vec: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<D, E, M> BuildModule<D, E> for Mwhere D: Device<E>, E: Dtype, M: TensorCollection<E, D, To<E, D> = M>,

source§

fn build(device: &D) -> Self

Construct it on the device
source§

fn try_build(device: &D) -> Result<Self, D::Err>

Fallible version of BuildModule::build
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<E, D, T> LoadFromNpz<E, D> for Twhere E: Dtype + NumpyDtype, D: Device<E>, T: TensorCollection<E, D>,

source§

fn load<P: AsRef<Path>>(&mut self, path: P) -> Result<(), NpzError>

Loads data from a .npz zip archive at the specified path. Read more
source§

fn read<R>(&mut self, r: &mut ZipArchive<R>) -> Result<(), NpzError>where R: Read + Seek,

Reads this object from a ZipArchive. r with a base filename of filename_prefix. Read more
source§

impl<E, D, T> LoadFromSafetensors<E, D> for Twhere E: Dtype + SafeDtype, D: Device<E>, T: TensorCollection<E, D>,

source§

fn load_safetensors<P: AsRef<Path>>(&mut self, path: P) -> Result<(), Error>

Loads data from a .safetensors at the specified path. Read more
source§

impl<E, D, M> ModelEMA<E, D> for Mwhere E: Dtype, D: Device<E>, M: TensorCollection<E, D>,

source§

fn ema(&mut self, other: &Self, decay: impl Into<f64>)

Does `self = self * decay + other * (1 - decay), using crate::tensor_ops::axpy() on parameters. Read more
source§

fn try_ema(&mut self, other: &Self, decay: impl Into<f64>) -> Result<(), D::Err>

source§

impl<M, T> ModuleMut<T> for Mwhere M: NonMutableModule + Module<T>,

§

type Output = <M as Module<T>>::Output

The type that this unit produces given Input.
§

type Error = <M as Module<T>>::Error

source§

fn try_forward_mut( &mut self, input: T ) -> Result<<M as ModuleMut<T>>::Output, <M as ModuleMut<T>>::Error>

source§

fn forward_mut(&mut self, input: Input) -> Self::Output

Forward Input through the module and produce ModuleMut::Output. Read more
source§

impl<E, D, M> NumParams<E, D> for Mwhere E: Dtype, D: Device<E>, M: TensorCollection<E, D>,

source§

fn num_trainable_params(&self) -> usize

Returns the number of trainable params in any model.
§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<E, D, M> ResetParams<E, D> for Mwhere E: Dtype, D: Device<E>, M: TensorCollection<E, D>,

source§

fn reset_params(&mut self)

Reset all a model’s parameters.
source§

fn try_reset_params(&mut self) -> Result<(), D::Err>

Reset all a model’s parameters.
source§

impl<E, D, T> SaveToNpz<E, D> for Twhere E: Dtype + NumpyDtype, D: Device<E>, T: TensorCollection<E, D>,

source§

fn save<P: AsRef<Path>>(&self, path: P) -> ZipResult<()>

Save this object into the .npz file determined located at path. Read more
source§

fn write<W>(&self, w: &mut ZipWriter<W>) -> ZipResult<()>where W: Write + Seek,

Write this object into ZipWriter w with a base filename of filename_prefix. Read more
source§

impl<E, D, T> SaveToSafetensors<E, D> for Twhere E: Dtype + SafeDtype, D: Device<E>, T: TensorCollection<E, D>,

source§

fn save_safetensors<P: AsRef<Path>>( &self, path: P ) -> Result<(), SafeTensorError>

Save this object into the .safetensors file determined located at path. Read more
source§

impl<E, D1, D2, T> ToDevice<E, D1, D2> for Twhere E: Dtype, D1: Device<E>, D2: Device<E>, T: TensorCollection<E, D1>,

source§

fn try_to_device(&self, device: &D2) -> Result<Self::To<E, D2>, D2::Err>

Fallible version of ToDevice::to_device
source§

fn to_device(&self, device: &D2) -> Self::To<E, D2>

Copy self from D1 to D2
source§

impl<E1, D, T> ToDtype<E1, D> for Twhere E1: Dtype, D: Device<E1>, T: TensorCollection<E1, D>,

source§

fn try_to_dtype<E2: Dtype>(&self) -> Result<Self::To<E2, D>, D::Err>where D: Device<E2> + ToDtypeKernel<E1, E2>,

Fallible version of ToDtype::to_dtype
source§

fn to_dtype<E2: Dtype>(&self) -> Self::To<E2, D>where D: Device<E2> + ToDtypeKernel<E1, E2>,

Create a copy of self with dtype E2
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<E, D, M> ZeroGrads<E, D> for Mwhere E: Dtype, D: Device<E>, M: TensorCollection<E, D>,

source§

fn alloc_grads(&self) -> Gradients<E, D>

Allocates gradients for this tensor collection. This marks all other gradients as temporary, so they are dropped after .backward()
source§

fn try_alloc_grads(&self) -> Result<Gradients<E, D>, D::Err>

Allocates gradients for this tensor collection. This marks all other gradients as temporary, so they are dropped after .backward()
source§

fn zero_grads(&self, gradients: &mut Gradients<E, D>)

Zero’s any gradients associated with self.
source§

fn try_zero_grads(&self, gradients: &mut Gradients<E, D>) -> Result<(), D::Err>

Zero’s any gradients associated with self.