Skip to content

Instantly share code, notes, and snippets.

@jerry73204
Created May 20, 2020 04:50
Embed
What would you like to do?
use failure::Fallible;
use ndarray::Array;
use std::convert::TryFrom;
use tch::Tensor;
fn main() -> Fallible<()> {
let tensor = Tensor::try_from(Array::from_shape_fn(
(3, 300, 200),
|(channel, _row, _col)| match channel {
0 => 1f32,
1 | 2 => 0.0,
_ => unreachable!(),
},
))?;
tch::vision::image::save(&tensor, "test.jpg")?;
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment