pub struct Dense<B: Backend, T: Float = f32> {
pub kernel: Array<B, T>,
pub bias: Array<B, T>,
}Expand description
A fully connected layer, x @ kernel + bias (flax.linen.Dense).
§Examples
use ruxla_core::{Array, Native};
use ruxla_nn::Dense;
let layer = Dense::<Native> {
kernel: Array::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0], [3, 2]),
bias: Array::from_vec(vec![0.5, -0.5], [2]),
};
let y = layer.apply(&Array::from_vec(vec![1.0, 0.0, 1.0], [3]));
assert_eq!(y.to_vec(), [6.5, 7.5]);Fields§
§kernel: Array<B, T>[in, out].
bias: Array<B, T>[out].
Implementations§
Source§impl<T: Float> Dense<Native, T>
impl<T: Float> Dense<Native, T>
Sourcepub fn load(weights: &Weights, prefix: &str) -> Result<Self, WeightsError>
pub fn load(weights: &Weights, prefix: &str) -> Result<Self, WeightsError>
Loads {prefix}/kernel ([in, out]) and {prefix}/bias ([out]),
such as the weights of params/Dense_0 of a Flax model.
§Errors
Returns an error if a weight is missing or has another type, or if the shapes do not fit together.
Trait Implementations§
Source§impl<B: Backend, T: Float> Tree<B> for Dense<B, T>
impl<B: Backend, T: Float> Tree<B> for Dense<B, T>
Source§fn unflatten_like(
&self,
leaves: &mut dyn Iterator<Item = <B as Backend>::Leaf>,
) -> Self
fn unflatten_like( &self, leaves: &mut dyn Iterator<Item = <B as Backend>::Leaf>, ) -> Self
Builds a value of the same structure from leaves.
Auto Trait Implementations§
impl<B, T> Freeze for Dense<B, T>
impl<B, T> RefUnwindSafe for Dense<B, T>
impl<B, T> Send for Dense<B, T>
impl<B, T> Sync for Dense<B, T>
impl<B, T> Unpin for Dense<B, T>
impl<B, T> UnsafeUnpin for Dense<B, T>
impl<B, T> UnwindSafe for Dense<B, T>
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