Created
August 9, 2024 22:01
-
-
Save jmsdnns/aa7c4cf1699304abe62b694010644d7e to your computer and use it in GitHub Desktop.
first attempt at loading an image as a candle tensor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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