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§
sourcefn save<P: AsRef<Path>>(&self, path: P) -> ZipResult<()>
fn save<P: AsRef<Path>>(&self, path: P) -> ZipResult<()>
Save this object into the .npz
file determined located at path
.
Example:
ⓘ
let model: (Linear<5, 10>, Linear<10, 5>) = Default::default();
model.save("tst.npz")?;
sourcefn write<W>(&self, w: &mut ZipWriter<W>) -> ZipResult<()>where
W: Write + Seek,
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
.
Example:
ⓘ
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