mirror of
https://github.com/mii443/usls.git
synced 2025-12-03 11:08:20 +00:00
Update README.md
This commit is contained in:
133
README.md
133
README.md
@@ -3,7 +3,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
| <a href="https://docs.rs/usls"><strong>Documentation</strong></a> |
|
<a href="https://docs.rs/usls"><strong>Documentation</strong></a>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<a href='https://github.com/microsoft/onnxruntime/releases'>
|
<a href='https://github.com/microsoft/onnxruntime/releases'>
|
||||||
@@ -123,69 +123,96 @@ cargo run -r --example yolo # blip, clip, yolop, svtr, db, ...
|
|||||||
- Build model with the provided `models` and `Options`
|
- Build model with the provided `models` and `Options`
|
||||||
- Load images, video and stream with `DataLoader`
|
- Load images, video and stream with `DataLoader`
|
||||||
- Do inference
|
- Do inference
|
||||||
- Annotate inference results with `Annotator`
|
|
||||||
- Retrieve inference results from `Vec<Y>`
|
- Retrieve inference results from `Vec<Y>`
|
||||||
|
- Annotate inference results with `Annotator`
|
||||||
|
- Display images and write them to video with `Viewer`
|
||||||
|
|
||||||
```rust
|
<br/>
|
||||||
use usls::{models::YOLO, Annotator, DataLoader, Nms, Options, Vision, YOLOTask, YOLOVersion};
|
<details>
|
||||||
|
<summary>example code</summary>
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
```rust
|
||||||
// Build model with Options
|
use usls::{models::YOLO, Annotator, DataLoader, Nms, Options, Vision, YOLOTask, YOLOVersion};
|
||||||
let options = Options::new()
|
|
||||||
.with_trt(0)
|
|
||||||
.with_model("yolo/v8-m-dyn.onnx")?
|
|
||||||
.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_i00((1, 2, 4).into())
|
|
||||||
.with_i02((0, 640, 640).into())
|
|
||||||
.with_i03((0, 640, 640).into())
|
|
||||||
.with_confs(&[0.2]);
|
|
||||||
let mut model = YOLO::new(options)?;
|
|
||||||
|
|
||||||
// Build DataLoader to load image(s), video, stream
|
fn main() -> anyhow::Result<()> {
|
||||||
let dl = DataLoader::new(
|
// Build model with Options
|
||||||
// "./assets/bus.jpg", // local image
|
let options = Options::new()
|
||||||
// "images/bus.jpg", // remote image
|
.with_trt(0)
|
||||||
// "../images-folder", // local images (from folder)
|
.with_model("yolo/v8-m-dyn.onnx")?
|
||||||
// "../demo.mp4", // local video
|
.with_yolo_version(YOLOVersion::V8) // YOLOVersion: V5, V6, V7, V8, V9, V10, RTDETR
|
||||||
// "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", // online video
|
.with_yolo_task(YOLOTask::Detect) // YOLOTask: Classify, Detect, Pose, Segment, Obb
|
||||||
"rtsp://admin:kkasd1234@192.168.2.217:554/h264/ch1/", // stream
|
.with_ixx(0, 0, (1, 2, 4).into())
|
||||||
)?
|
.with_ixx(0, 2, (0, 640, 640).into())
|
||||||
.with_batch(2) // iterate with batch_size = 2
|
.with_ixx(0, 3, (0, 640, 640).into())
|
||||||
.build()?;
|
.with_confs(&[0.2]);
|
||||||
|
let mut model = YOLO::new(options)?;
|
||||||
|
|
||||||
// Build annotator
|
// Build DataLoader to load image(s), video, stream
|
||||||
let annotator = Annotator::new()
|
let dl = DataLoader::new(
|
||||||
.with_bboxes_thickness(4)
|
// "./assets/bus.jpg", // local image
|
||||||
.with_saveout("YOLO-DataLoader");
|
// "images/bus.jpg", // remote image
|
||||||
|
// "../images-folder", // local images (from folder)
|
||||||
|
// "../demo.mp4", // local video
|
||||||
|
// "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", // online video
|
||||||
|
"rtsp://admin:kkasd1234@192.168.2.217:554/h264/ch1/", // stream
|
||||||
|
)?
|
||||||
|
.with_batch(2) // iterate with batch_size = 2
|
||||||
|
.build()?;
|
||||||
|
|
||||||
// Run and annotate results
|
// Build annotator
|
||||||
for (xs, _) in dl {
|
let annotator = Annotator::new()
|
||||||
let ys = model.forward(&xs, false)?;
|
.with_bboxes_thickness(4)
|
||||||
annotator.annotate(&xs, &ys);
|
.with_saveout("YOLO-DataLoader");
|
||||||
|
|
||||||
// Retrieve inference results
|
// Build viewer
|
||||||
for y in ys {
|
let mut viewer = Viewer::new().with_delay(10).with_scale(1.).resizable(true);
|
||||||
// bboxes
|
|
||||||
if let Some(bboxes) = y.bboxes() {
|
// Run and annotate results
|
||||||
for bbox in bboxes {
|
for (xs, _) in dl {
|
||||||
println!(
|
let ys = model.forward(&xs, false)?;
|
||||||
"Bbox: {}, {}, {}, {}, {}, {}",
|
// annotator.annotate(&xs, &ys);
|
||||||
bbox.xmin(),
|
let images_plotted = annotator.plot(&xs, &ys, false)?;
|
||||||
bbox.ymin(),
|
|
||||||
bbox.xmax(),
|
// show image
|
||||||
bbox.ymax(),
|
viewer.imshow(&images_plotted)?;
|
||||||
bbox.confidence(),
|
|
||||||
bbox.id(),
|
// check out window and key event
|
||||||
);
|
if !viewer.is_open() || viewer.is_key_pressed(usls::Key::Escape) {
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write video
|
||||||
|
viewer.write_batch(&images_plotted)?;
|
||||||
|
|
||||||
|
// Retrieve inference results
|
||||||
|
for y in ys {
|
||||||
|
// bboxes
|
||||||
|
if let Some(bboxes) = y.bboxes() {
|
||||||
|
for bbox in bboxes {
|
||||||
|
println!(
|
||||||
|
"Bbox: {}, {}, {}, {}, {}, {}",
|
||||||
|
bbox.xmin(),
|
||||||
|
bbox.ymin(),
|
||||||
|
bbox.xmax(),
|
||||||
|
bbox.ymax(),
|
||||||
|
bbox.confidence(),
|
||||||
|
bbox.id(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
// finish video write
|
||||||
|
viewer.finish_write()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
</br>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 📌 License
|
## 📌 License
|
||||||
|
|||||||
Reference in New Issue
Block a user