Skip to main content

write_model

Function write_model 

Source
pub fn write_model<const IN: usize, const OUT: usize>(
    model: &NeuralNetwork<IN, OUT>,
    writer: impl Write,
) -> Result<(), ModelError>
Expand description

Writes a model to any writer, in the newest format version.

The model is encoded in memory and written with a single write_all, so the writer does not need to be buffered. Use it with a Vec<u8> to keep a model in memory, for example to store it in a database.

§Errors

Returns ModelError::Io if writing fails.

§Example

let nn = NeuralNetwork::<2, 1>::new(&[2]);

let mut bytes = Vec::new();
write_model(&nn, &mut bytes)?;

let copy: NeuralNetwork<2, 1> = read_model(bytes.as_slice())?;
assert_eq!(copy, nn);