Skip to content

Commit

Permalink
chore: upgrade ort
Browse files Browse the repository at this point in the history
  • Loading branch information
mosure committed May 5, 2024
1 parent b65aa44 commit cdfe44b
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ features = [
"bevy_winit",
"multi-threaded",
"png",
"tonemapping_luts",
]


[dependencies.ort]
version = "2.0.0-rc.0"
version = "2.0.0-rc.2"
default-features = false
features = [
"cuda",
Expand Down
4 changes: 2 additions & 2 deletions benches/modnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn modnet_output_to_luma_images_benchmark(c: &mut Criterion) {

let session = Session::builder().unwrap()
.with_optimization_level(GraphOptimizationLevel::Level3).unwrap()
.with_model_from_file("assets/modnet_photographic_portrait_matting.onnx").unwrap();
.commit_from_file("assets/modnet_photographic_portrait_matting.onnx").unwrap();

let data = vec![0u8; (1920 * 1080 * 4) as usize];
let image: Image = Image::new(
Expand Down Expand Up @@ -123,7 +123,7 @@ fn modnet_inference_benchmark(c: &mut Criterion) {

let session = Session::builder().unwrap()
.with_optimization_level(GraphOptimizationLevel::Level3).unwrap()
.with_model_from_file("assets/modnet_photographic_portrait_matting.onnx").unwrap();
.commit_from_file("assets/modnet_photographic_portrait_matting.onnx").unwrap();

MAX_RESOLUTIONS.iter().for_each(|(width, height)| {
let data = vec![0u8; *width as usize * *height as usize * 4];
Expand Down
4 changes: 2 additions & 2 deletions benches/yolo_v8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn process_output_benchmark(c: &mut Criterion) {

let session = Session::builder().unwrap()
.with_optimization_level(GraphOptimizationLevel::Level3).unwrap()
.with_model_from_file("assets/yolov8n.onnx").unwrap();
.commit_from_file("assets/yolov8n.onnx").unwrap();

RESOLUTIONS.iter()
.for_each(|(width, height)| {
Expand Down Expand Up @@ -117,7 +117,7 @@ fn inference_benchmark(c: &mut Criterion) {

let session = Session::builder().unwrap()
.with_optimization_level(GraphOptimizationLevel::Level3).unwrap()
.with_model_from_file("assets/yolov8n.onnx").unwrap();
.commit_from_file("assets/yolov8n.onnx").unwrap();

RESOLUTIONS.iter().for_each(|(width, height)| {
let data = vec![0u8; *width as usize * *height as usize * 4];
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl AssetLoader for OnnxLoader {
// TODO: add session configuration
let session = Session::builder()?
.with_optimization_level(GraphOptimizationLevel::Level3)?
.with_model_from_memory(&bytes)?;
.commit_from_memory(&bytes)?;

Ok(Onnx {
session: Arc::new(Mutex::new(Some(session))),
Expand Down
4 changes: 2 additions & 2 deletions src/models/flame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ pub fn post_process(
vertices: &ort::Value,
landmarks: &ort::Value,
) -> FlameOutput {
let vertices_tensor = vertices.extract_tensor::<f32>().unwrap();
let vertices_tensor = vertices.try_extract_tensor::<f32>().unwrap();
let vertices_view = vertices_tensor.view(); // [8, 5023, 3]

let landmarks_tensor = landmarks.extract_tensor::<f32>().unwrap();
let landmarks_tensor = landmarks.try_extract_tensor::<f32>().unwrap();
let landmarks_view = landmarks_tensor.view(); // [8, 68, 3]

let vertices = vertices_view.outer_iter()
Expand Down
6 changes: 3 additions & 3 deletions src/models/lightglue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ pub fn post_process(
kpts1: &ort::Value,
matches: &ort::Value,
) -> Result<Vec<GluedPair>, &'static str> {
let kpts0_tensor = kpts0.extract_tensor::<i64>().unwrap();
let kpts0_tensor = kpts0.try_extract_tensor::<i64>().unwrap();
let kpts0_view = kpts0_tensor.view();

let kpts1_tensor = kpts1.extract_tensor::<i64>().unwrap();
let kpts1_tensor = kpts1.try_extract_tensor::<i64>().unwrap();
let kpts1_view = kpts1_tensor.view();

let matches = matches.extract_tensor::<i64>().unwrap();
let matches = matches.try_extract_tensor::<i64>().unwrap();
let matches_view = matches.view();

Ok(
Expand Down
2 changes: 1 addition & 1 deletion src/models/modnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn modnet_inference(
pub fn modnet_output_to_luma_images(
output_value: &ort::Value,
) -> Vec<Image> {
let tensor = output_value.extract_tensor::<f32>().unwrap();
let tensor = output_value.try_extract_tensor::<f32>().unwrap();
let data = tensor.view();

let shape = data.shape();
Expand Down
2 changes: 1 addition & 1 deletion src/models/yolo_v8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn process_output(
) -> Vec<BoundingBox> {
let mut boxes = Vec::new();

let tensor = output.extract_tensor::<f32>().unwrap();
let tensor = output.try_extract_tensor::<f32>().unwrap();
let data = tensor.view().t().into_owned();

for detection in data.axis_iter(Axis(0)) {
Expand Down

0 comments on commit cdfe44b

Please sign in to comment.