Skip to content

Commit 22d0df5

Browse files
authored
Add RF-DETR-seg model (#154)
Add RF-DETR models: - rf-detr-nano - rf-detr-small - rf-detr-medium - rf-detr-seg-preview
1 parent 6c337b2 commit 22d0df5

File tree

5 files changed

+494
-25
lines changed

5 files changed

+494
-25
lines changed

examples/rfdetr/README.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
## Quick Start
22

33
```shell
4-
cargo run -r --example rfdetr
5-
```
6-
7-
## Results
8-
9-
```
10-
[Bboxes]: Found 5 objects
11-
0: Bbox { xyxy: [47.969677, 397.81808, 246.22426, 904.8823], class_id: 0, name: Some("person"), confidence: 0.94432133 }
12-
1: Bbox { xyxy: [668.0796, 399.28854, 810.3779, 880.7412], class_id: 0, name: Some("person"), confidence: 0.93386495 }
13-
2: Bbox { xyxy: [20.852705, 229.30482, 807.43494, 729.51196], class_id: 5, name: Some("bus"), confidence: 0.9319465 }
14-
3: Bbox { xyxy: [223.28226, 405.37265, 343.92603, 859.50366], class_id: 0, name: Some("person"), confidence: 0.9130827 }
15-
4: Bbox { xyxy: [0.0, 552.6165, 65.99908, 868.00525], class_id: 0, name: Some("person"), confidence: 0.7910869 }
16-
4+
cargo run --example rfdetr -- --scale n --dtype f16 # detection
5+
cargo run --example rfdetr -- --dtype f16 --task seg # instance segment
176
```

examples/rfdetr/main.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,50 @@
11
use anyhow::Result;
2-
use usls::{models::RFDETR, Annotator, Config, DataLoader};
2+
use usls::{models::RFDETR, Annotator, Config, DataLoader, Scale, Task};
3+
4+
#[derive(argh::FromArgs)]
5+
/// Example
6+
struct Args {
7+
/// device
8+
#[argh(option, default = "String::from(\"cpu\")")]
9+
device: String,
10+
11+
/// task
12+
#[argh(option, default = "String::from(\"det\")")]
13+
task: String,
14+
15+
/// scale
16+
#[argh(option, default = "String::from(\"n\")")]
17+
scale: String,
18+
19+
/// dtype
20+
#[argh(option, default = "String::from(\"auto\")")]
21+
dtype: String,
22+
}
323

424
fn main() -> Result<()> {
525
tracing_subscriber::fmt()
626
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
727
.with_timer(tracing_subscriber::fmt::time::ChronoLocal::rfc_3339())
828
.init();
29+
let args: Args = argh::from_env();
930

1031
// config
11-
let mut model = RFDETR::new(Config::rfdetr_base().commit()?)?;
32+
let config = match args.task.parse()? {
33+
Task::ObjectDetection => match args.scale.parse()? {
34+
Scale::N => Config::rfdetr_nano(),
35+
Scale::S => Config::rfdetr_small(),
36+
Scale::M => Config::rfdetr_medium(),
37+
Scale::B => Config::rfdetr_base(),
38+
Scale::L => Config::rfdetr_large(),
39+
_ => unimplemented!("Unsupported model scale: {:?}. Try b, s, t.", args.scale),
40+
},
41+
Task::InstanceSegmentation => Config::rfdetr_seg_preview(),
42+
_ => unimplemented!("Unsupported task: {:?}. Try det, seg.", args.task),
43+
}
44+
.with_dtype_all(args.dtype.parse()?)
45+
.with_device_all(args.device.parse()?)
46+
.commit()?;
47+
let mut model = RFDETR::new(config)?;
1248

1349
// load
1450
let xs = DataLoader::try_read_n(&["./assets/bus.jpg"])?;

0 commit comments

Comments
 (0)