This crate provides {ser,de}ialization methods for tch-rs common types.
For example, annotate #[serde(with = "tch_serde::serde_tensor")]
attributes to enable serialization on tensor field.
```rust use tch::{Device, Kind, Tensor};
struct Example { #[serde(with = "tchserde::serdetensor")] tensor: Tensor, #[serde(with = "tchserde::serdekind")] kind: Kind, #[serde(with = "tchserde::serdedevice")] device: Device, #[serde(with = "tchserde::serdereduction")] reduction: Reduction, }
fn main() { let example = Example { tensor: Tensor::randn(&[2, 3], (Kind::Float, Device::cudaifavailable())), kind: Kind::Float, device: Device::Cpu, reduction: Reduction::Mean, }; let text = serdejson::tostring_pretty(&example).unwrap(); println!("{}", text); } ```
MIT license. See the LICENSE file.