Files
usls/examples/yolov8/main.rs
Jamjamjon a5141a53be Accelerate model pre-processing and post-processing (#23)
* Add X struct to handle input and preprocessing

*Add Ops struct to manage common operations

* Use SIMD (fast_image_resize) to accelerate model pre-processing and post-processing
2024-06-30 15:19:34 +08:00

46 lines
1.4 KiB
Rust

use usls::{coco, models::YOLO, Annotator, DataLoader, Options, Vision};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// build model
let options = Options::default()
// .with_model("yolov8m-dyn.onnx")?
// .with_model("yolov8m-dyn-f16.onnx")?
// .with_model("yolov8m-pose-dyn.onnx")?
// .with_model("yolov8m-cls-dyn.onnx")?
.with_model("yolov8m-seg-dyn.onnx")?
// .with_model("yolov8m-obb-dyn.onnx")?
// .with_model("yolov8m-oiv7-dyn.onnx")?
// .with_trt(0)
// .with_fp16(true)
// .with_coreml(0)
// .with_cuda(3)
.with_i00((1, 1, 4).into())
.with_i02((224, 640, 800).into())
.with_i03((224, 640, 800).into())
.with_confs(&[0.4, 0.15]) // class 0: 0.4, others: 0.15
.with_names2(&coco::KEYPOINTS_NAMES_17)
.with_profile(false);
let mut model = YOLO::new(options)?;
// build dataloader
let dl = DataLoader::default()
.with_batch(1)
.load("./assets/bus.jpg")?;
// .load("./assets/dota.png")?;
// build annotate
let annotator = Annotator::default()
.with_skeletons(&coco::SKELETONS_16)
.with_bboxes_thickness(7)
.with_saveout("YOLOv8");
// run & annotate
for (xs, _paths) in dl {
let ys = model.run(&xs)?;
// let ys = model.forward(&xs, true)?;
annotator.annotate(&xs, &ys);
}
Ok(())
}