Skip to content

Instantly share code, notes, and snippets.

@jerry73204
Created May 20, 2020 04:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jerry73204/fce961f87238d630c465a295e02d9f63 to your computer and use it in GitHub Desktop.
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