Skip to content

Instantly share code, notes, and snippets.

@jmsdnns
Created August 9, 2024 22:01
Show Gist options
  • Save jmsdnns/aa7c4cf1699304abe62b694010644d7e to your computer and use it in GitHub Desktop.
Save jmsdnns/aa7c4cf1699304abe62b694010644d7e to your computer and use it in GitHub Desktop.
first attempt at loading an image as a candle tensor
use candle_core::{Device, Result, Tensor};
use image;
pub fn hongry<P: AsRef<std::path::Path>>(
p: P,
) -> Result<(Tensor, usize, usize)> {
let img = image::open(p).unwrap();
let (height, width) = (img.height() as usize, img.width() as usize);
let img = img.to_rgba8();
let data = img.into_raw();
let data = Tensor::from_vec(data, (height, width, 4), &Device::Cpu)?.permute((2, 0, 1))?;
Ok((data, height, width))
}
fn main() {
let image_tensor = hongry("../cpunks-10k/cpunks/images/training/punk0000.png").unwrap();
println!("{:?}", image_tensor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment