pub trait Module<Input> {
type Output;
type Error;
// Required method
fn forward(&self, input: Input) -> Result<Self::Output, Self::Error>;
}Expand description
A generic Neural Network Layer or Module. Capable of taking an input and returning an output or error.
Module is the fundamental building block of neural networks in Incin.
Any layer, from a simple ReLU to an entire ResNet architecture, implements Module.
§Deriving Modules
While you can implement Module manually, the recommended approach is to use the #[module] attribute macro
provided by incin-macros. This automatically derives typed visitors and structural boilerplate.
use incin::backend_authoring::VariableBackend;
use incin::prelude::*;
#[module]
pub struct MyLayer<B: VariableBackend> {
weight: Param<s![128, 128], B>,
bias: Param<s![128], B>,
}
impl<B: VariableBackend> Module<Tensor<s![1, 128], B>> for MyLayer<B> {
type Output = Tensor<s![1, 128], B>;
type Error = Error;
fn forward(&self, x: Tensor<s![1, 128], B>) -> Result<Self::Output> {
// Custom logic here
Ok(x)
}
}Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".