Trait dfdx::nn::SaveToNpz

source ·
pub trait SaveToNpz<E: Dtype + NumpyDtype, D: Device<E>>: TensorCollection<E, D> {
    // Provided methods
    fn save<P: AsRef<Path>>(&self, path: P) -> ZipResult<()> { ... }
    fn write<W>(&self, w: &mut ZipWriter<W>) -> ZipResult<()>
       where W: Write + Seek { ... }
Expand description

Something that can be saved to a .npz (which is a .zip).

All super::Modules in nn implement SaveToNpz, and the zips are formatted in a .npz fashion.

Provided Methods§


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

Save this object into the .npz file determined located at path.


let model: (Linear<5, 10>, Linear<10, 5>) = Default::default();"tst.npz")?;

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.


let model: Linear<5, 10> = Default::default();
let mut zip = ZipWriter::new(...);
model.write("0", &mut zip)?;
model.write("1", &mut zip)?;

Will save a zip file with the following files in it:

  • 0.weight.npy
  • 0.bias.npy
  • 1.weight.npy
  • 1.bias.npy



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