add url crate to handle local path

This commit is contained in:
jhqxxx
2025-12-11 19:33:30 +08:00
parent 42c95da0e3
commit 6430338e95
4 changed files with 39 additions and 16 deletions
+22 -11
View File
@@ -1,20 +1,31 @@
use std::time::Instant;
use std::{path::PathBuf, str::FromStr};
use aha::utils::tensor_utils::interpolate_bilinear;
use anyhow::Result;
use candle_core::Tensor;
#[test]
fn messy_test() -> Result<()> {
// RUST_BACKTRACE=1 cargo test -F cuda messy_test -r -- --nocapture
let device = &candle_core::Device::Cpu;
let t = Tensor::arange(0.0f32, 40.0, device)?.broadcast_as((1, 1, 40, 40))?;
println!("t: {}", t);
let i_start = Instant::now();
let t_inter = interpolate_bilinear(&t, (20, 20), Some(false))?;
let i_duration = i_start.elapsed();
println!("Time elapsed in interpolate_bilinear is: {:?}", i_duration);
println!("t_inter: {}", t_inter);
let path_str = "file://./assets/img/ocr_test1.png";
let path = url::Url::from_str(path_str)?;
let path = path.to_file_path();
let path = match path {
Ok(path) => path,
Err(_) => {
let mut path = path_str.to_owned();
path = path.split_off(7);
PathBuf::from(path)
}
};
println!("to file path: {:?}", path);
// let device = &candle_core::Device::Cpu;
// let t = Tensor::arange(0.0f32, 40.0, device)?.broadcast_as((1, 1, 40, 40))?;
// println!("t: {}", t);
// let i_start = Instant::now();
// let t_inter = interpolate_bilinear(&t, (20, 20), Some(false))?;
// let i_duration = i_start.elapsed();
// println!("Time elapsed in interpolate_bilinear is: {:?}", i_duration);
// println!("t_inter: {}", t_inter);
// let x: Vec<u32> = (0..5).flat_map(|_| 0u32..10).collect();
// let id: Vec<u32> = (0..5).flat_map(|h| vec![h; 10]).collect();
// println!("x: {:?}", id);