Skip to content

Commit 7e8b77d

Browse files
authored
Add DEIMv2 model (#142)
1 parent c6b606b commit 7e8b77d

11 files changed

Lines changed: 130 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ usls = "latest-version"
8080
| [DocLayout-YOLO](https://github.com/opendatalab/DocLayout-YOLO) | Object Detection | [demo](examples/picodet-layout) |
8181
| [D-FINE](https://github.com/manhbd-22022602/D-FINE) | Object Detection | [demo](examples/d-fine) |
8282
| [DEIM](https://github.com/ShihuaHuang95/DEIM) | Object Detection | [demo](examples/deim) |
83+
| [DEIMv2](https://github.com/Intellindust-AI-Lab/DEIMv2) | Object Detection | [demo](examples/deimv2) |
8384
| [RTMPose](https://github.com/open-mmlab/mmpose/tree/dev-1.x/projects/rtmpose) | Keypoint Detection | [demo](examples/rtmpose) |
8485
| [DWPose](https://github.com/IDEA-Research/DWPose) | Keypoint Detection | [demo](examples/dwpose) |
8586
| [RTMW](https://arxiv.org/abs/2407.08634) | Keypoint Detection | [demo](examples/rtmw) |

examples/d-fine/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use anyhow::Result;
2-
use usls::{models::RTDETR, Annotator, Config, DataLoader};
2+
use usls::{models::DFINE, Annotator, Config, DataLoader};
33

44
fn main() -> Result<()> {
55
tracing_subscriber::fmt()
@@ -8,7 +8,7 @@ fn main() -> Result<()> {
88
.init();
99

1010
// config
11-
let mut model = RTDETR::new(Config::d_fine_n_coco().commit()?)?;
11+
let mut model = DFINE::new(Config::d_fine_n_coco().commit()?)?;
1212

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

examples/deim/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use anyhow::Result;
2-
use usls::{models::RTDETR, Annotator, Config, DataLoader};
2+
use usls::{models::DEIM, Annotator, Config, DataLoader};
33

44
fn main() -> Result<()> {
55
tracing_subscriber::fmt()
@@ -8,7 +8,7 @@ fn main() -> Result<()> {
88
.init();
99

1010
// config
11-
let mut model = RTDETR::new(Config::deim_dfine_s_coco().commit()?)?;
11+
let mut model = DEIM::new(Config::deim_dfine_s_coco().commit()?)?;
1212

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

examples/deimv2/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Quick Start
2+
3+
```shell
4+
cargo run -r --example deimv2
5+
```
6+
7+

examples/deimv2/main.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use anyhow::Result;
2+
use usls::{models::RTDETR, Annotator, Config, DataLoader};
3+
4+
#[derive(argh::FromArgs)]
5+
/// Example
6+
struct Args {
7+
/// model file
8+
#[argh(option)]
9+
model: Option<String>,
10+
11+
/// device
12+
#[argh(option, default = "String::from(\"cpu:0\")")]
13+
device: String,
14+
15+
/// dtype
16+
#[argh(option, default = "String::from(\"fp16\")")]
17+
dtype: String,
18+
}
19+
20+
fn main() -> Result<()> {
21+
tracing_subscriber::fmt()
22+
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
23+
.with_timer(tracing_subscriber::fmt::time::ChronoLocal::rfc_3339())
24+
.init();
25+
26+
let args: Args = argh::from_env();
27+
28+
// config
29+
let config = match &args.model {
30+
Some(m) => Config::deimv2().with_model_file(m),
31+
None => Config::deim_v2_n_coco(),
32+
}
33+
.with_model_dtype(args.dtype.parse()?)
34+
.with_device_all(args.device.parse()?)
35+
.commit()?;
36+
let mut model = RTDETR::new(config)?;
37+
38+
// load
39+
let xs = DataLoader::try_read_n(&["./assets/bus.jpg"])?;
40+
41+
// run
42+
let ys = model.forward(&xs)?;
43+
println!("{:?}", ys);
44+
45+
// annotate
46+
let annotator = Annotator::default();
47+
for (x, y) in xs.iter().zip(ys.iter()) {
48+
annotator.annotate(x, y)?.save(format!(
49+
"{}.jpg",
50+
usls::Dir::Current
51+
.base_dir_with_subs(&["runs", model.spec()])?
52+
.join(usls::timestamp(None))
53+
.display(),
54+
))?;
55+
}
56+
57+
usls::perf(false);
58+
59+
Ok(())
60+
}

src/models/d_fine/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
mod config;
2+
3+
pub type DFINE = crate::RTDETR;

src/models/deim/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
mod config;
2+
3+
pub type DEIM = crate::RTDETR;

src/models/deimv2/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# DEIMv2: Real-Time Object Detection Meets DINOv3
2+
3+
## Official Repository
4+
5+
The official repository can be found on: [GitHub](https://github.com/Intellindust-AI-Lab/DEIMv2)
6+
7+
## Example
8+
9+
Refer to the [example](../../../examples/deimv2)

src/models/deimv2/config.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/// Model configuration for `DEIMv2`
2+
impl crate::Config {
3+
pub fn deimv2() -> Self {
4+
Self::d_fine().with_name("deimv2")
5+
}
6+
7+
pub fn deim_v2_atto_coco() -> Self {
8+
Self::deimv2().with_model_file("hgnetv2-atto-coco.onnx")
9+
}
10+
11+
pub fn deim_v2_femto_coco() -> Self {
12+
Self::deimv2().with_model_file("hgnetv2-femto-coco.onnx")
13+
}
14+
15+
pub fn deim_v2_pico_coco() -> Self {
16+
Self::deimv2().with_model_file("hgnetv2-pico-coco.onnx")
17+
}
18+
19+
pub fn deim_v2_n_coco() -> Self {
20+
Self::deimv2().with_model_file("hgnetv2-n-coco.onnx")
21+
}
22+
23+
pub fn deim_v2_s_coco() -> Self {
24+
Self::deimv2().with_model_file("dinov3-s-coco.onnx")
25+
}
26+
27+
pub fn deim_v2_m_coco() -> Self {
28+
Self::deimv2().with_model_file("dinov3-m-coco.onnx")
29+
}
30+
31+
pub fn deim_v2_l_coco() -> Self {
32+
Self::deimv2().with_model_file("dinov3-l-coco.onnx")
33+
}
34+
35+
pub fn deim_v2_x_coco() -> Self {
36+
Self::deimv2().with_model_file("dinov3-x-coco.onnx")
37+
}
38+
}

src/models/deimv2/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod config;
2+
3+
pub type DEIMv2 = crate::RTDETR;

0 commit comments

Comments
 (0)