-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,222 additions
and
432 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
[package] | ||
name = "usls" | ||
version = "0.0.6" | ||
version = "0.0.7" | ||
edition = "2021" | ||
description = "A Rust library integrated with ONNXRuntime, providing a collection of ML models." | ||
repository = "https://github.com/jamjamjon/usls" | ||
authors = ["Jamjamjon <[email protected]>"] | ||
license = "MIT" | ||
readme = "README.md" | ||
exclude = ["assets/*", "examples/*"] | ||
exclude = ["assets/*", "examples/*", "scripts/*", "runs/*"] | ||
|
||
[dependencies] | ||
clap = { version = "4.2.4", features = ["derive"] } | ||
|
@@ -44,4 +44,15 @@ ab_glyph = "0.2.23" | |
geo = "0.28.0" | ||
prost = "0.12.4" | ||
human_bytes = "0.4.3" | ||
fast_image_resize = { version = "4.0.0", git = "https://github.com/jamjamjon/fast_image_resize", branch = "dev" , features = ["image"]} | ||
fast_image_resize = { version = "4.2.1", features = ["image"]} | ||
|
||
|
||
[dev-dependencies] | ||
criterion = "0.5.1" | ||
|
||
[[bench]] | ||
name = "yolo" | ||
harness = false | ||
|
||
[lib] | ||
bench = false |
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
use anyhow::Result; | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
|
||
use usls::{coco, models::YOLO, DataLoader, Options, Vision, YOLOTask, YOLOVersion}; | ||
|
||
enum Stage { | ||
Pre, | ||
Run, | ||
Post, | ||
Pipeline, | ||
} | ||
|
||
fn yolo_stage_bench( | ||
model: &mut YOLO, | ||
x: &[image::DynamicImage], | ||
stage: Stage, | ||
n: u64, | ||
) -> std::time::Duration { | ||
let mut t_pre = std::time::Duration::new(0, 0); | ||
let mut t_run = std::time::Duration::new(0, 0); | ||
let mut t_post = std::time::Duration::new(0, 0); | ||
let mut t_pipeline = std::time::Duration::new(0, 0); | ||
for _ in 0..n { | ||
let t0 = std::time::Instant::now(); | ||
let xs = model.preprocess(x).unwrap(); | ||
t_pre += t0.elapsed(); | ||
|
||
let t = std::time::Instant::now(); | ||
let xs = model.inference(xs).unwrap(); | ||
t_run += t.elapsed(); | ||
|
||
let t = std::time::Instant::now(); | ||
let _ys = black_box(model.postprocess(xs, x).unwrap()); | ||
t_post += t.elapsed(); | ||
t_pipeline += t0.elapsed(); | ||
} | ||
match stage { | ||
Stage::Pre => t_pre, | ||
Stage::Run => t_run, | ||
Stage::Post => t_post, | ||
Stage::Pipeline => t_pipeline, | ||
} | ||
} | ||
|
||
pub fn benchmark_cuda(c: &mut Criterion, h: isize, w: isize) -> Result<()> { | ||
let mut group = c.benchmark_group(format!("YOLO ({}-{})", w, h)); | ||
group | ||
.significance_level(0.05) | ||
.sample_size(80) | ||
.measurement_time(std::time::Duration::new(20, 0)); | ||
|
||
let options = Options::default() | ||
.with_yolo_version(YOLOVersion::V8) // YOLOVersion: V5, V6, V7, V8, V9, V10, RTDETR | ||
.with_yolo_task(YOLOTask::Detect) // YOLOTask: Classify, Detect, Pose, Segment, Obb | ||
.with_model("yolov8m-dyn.onnx")? | ||
.with_cuda(0) | ||
// .with_cpu() | ||
.with_dry_run(0) | ||
.with_i00((1, 1, 4).into()) | ||
.with_i02((320, h, 1280).into()) | ||
.with_i03((320, w, 1280).into()) | ||
.with_confs(&[0.2, 0.15]) // class_0: 0.4, others: 0.15 | ||
.with_names2(&coco::KEYPOINTS_NAMES_17); | ||
let mut model = YOLO::new(options)?; | ||
|
||
let xs = vec![DataLoader::try_read("./assets/bus.jpg")?]; | ||
|
||
group.bench_function("pre-process", |b| { | ||
b.iter_custom(|n| yolo_stage_bench(&mut model, &xs, Stage::Pre, n)) | ||
}); | ||
|
||
group.bench_function("run", |b| { | ||
b.iter_custom(|n| yolo_stage_bench(&mut model, &xs, Stage::Run, n)) | ||
}); | ||
|
||
group.bench_function("post-process", |b| { | ||
b.iter_custom(|n| yolo_stage_bench(&mut model, &xs, Stage::Post, n)) | ||
}); | ||
|
||
group.bench_function("pipeline", |b| { | ||
b.iter_custom(|n| yolo_stage_bench(&mut model, &xs, Stage::Pipeline, n)) | ||
}); | ||
|
||
group.finish(); | ||
Ok(()) | ||
} | ||
|
||
pub fn criterion_benchmark(c: &mut Criterion) { | ||
// benchmark_cuda(c, 416, 416).unwrap(); | ||
benchmark_cuda(c, 640, 640).unwrap(); | ||
benchmark_cuda(c, 448, 768).unwrap(); | ||
// benchmark_cuda(c, 800, 800).unwrap(); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main() { | ||
// Need this for CoreML. See: https://ort.pyke.io/perf/execution-providers#coreml | ||
#[cfg(target_os = "macos")] | ||
println!("cargo:rustc-link-arg=-fapple-link-rtlib"); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## Quick Start | ||
|
||
```Shell | ||
|
||
# SAM | ||
cargo run -r --example sam | ||
|
||
# MobileSAM | ||
cargo run -r --example sam -- --kind mobile-sam | ||
|
||
# EdgeSAM | ||
cargo run -r --example sam -- --kind edge-sam | ||
|
||
# SAM-HQ | ||
cargo run -r --example sam -- --kind sam-hq | ||
``` | ||
|
||
|
||
## Results | ||
|
||
![](./demo.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.