pub struct Sequential { /* private fields */ }Expand description
A sequential container that chains modules together.
Modules are added in the order they should be executed. The forward pass executes each module in order, passing the output of one as the input to the next.
§Example
ⓘ
let model = Sequential::new()
.add(Linear::new(784, 256))
.add(ReLU)
.add(Linear::new(256, 10));
let output = model.forward(&input);Implementations§
Source§impl Sequential
impl Sequential
Sourcepub fn add<M: Module + 'static>(self, module: M) -> Self
pub fn add<M: Module + 'static>(self, module: M) -> Self
Adds a module with an auto-generated name.
Sourcepub fn add_named<M: Module + 'static>(
self,
name: impl Into<String>,
module: M,
) -> Self
pub fn add_named<M: Module + 'static>( self, name: impl Into<String>, module: M, ) -> Self
Adds a module with a specific name.
Sourcepub fn push_named<M: Module + 'static>(
&mut self,
name: impl Into<String>,
module: M,
)
pub fn push_named<M: Module + 'static>( &mut self, name: impl Into<String>, module: M, )
Pushes a named module (non-builder pattern).
Trait Implementations§
Source§impl Default for Sequential
impl Default for Sequential
Source§impl Module for Sequential
impl Module for Sequential
Source§fn named_parameters(&self) -> HashMap<String, Parameter>
fn named_parameters(&self) -> HashMap<String, Parameter>
Returns named parameters of this module.
Source§fn set_training(&mut self, training: bool)
fn set_training(&mut self, training: bool)
Sets the training mode.
Source§fn is_training(&self) -> bool
fn is_training(&self) -> bool
Returns whether the module is in training mode.
Source§fn num_parameters(&self) -> usize
fn num_parameters(&self) -> usize
Returns the number of trainable parameters.
Auto Trait Implementations§
impl Freeze for Sequential
impl !RefUnwindSafe for Sequential
impl Send for Sequential
impl Sync for Sequential
impl Unpin for Sequential
impl !UnwindSafe for Sequential
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