Skip to content

Commit 8d81ad3

Browse files
authored
feat(gdino): add multi-batch inference support; integrate mm-gdino & llmdet models; (#162)
And extend post-processing to token/phrase class-name modes
1 parent 8a7b24e commit 8d81ad3

8 files changed

Lines changed: 169 additions & 58 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "usls"
33
edition = "2021"
4-
version = "0.1.9"
4+
version = "0.1.10"
55
rust-version = "1.85"
66
description = "A Rust library integrated with ONNXRuntime, providing a collection of ML models."
77
repository = "https://github.com/jamjamjon/usls"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ usls = { version = "latest-version", features = [ "cuda" ] }
142142
| [YOLO-World](https://github.com/AILab-CVC/YOLO-World) | Open-Set Detection With Language | `yolo` | [demo](examples/yolo) |
143143
| [YOLOE](https://github.com/THU-MIG/yoloe) | Open-Set Detection And Segmentation | `yoloe` | [demo-prompt-free](examples/yoloe-prompt-free)<br />[demo-prompt(visual & textual)](examples/yoloe-prompt) |
144144
| [GroundingDINO](https://github.com/IDEA-Research/GroundingDINO) | Open-Set Detection With Language | `grounding-dino` | [demo](examples/grounding-dino) |
145+
| [MM-GDINO](https://github.com/open-mmlab/mmdetection/blob/main/configs/mm_grounding_dino/README.md) | Open-Set Detection With Language | `grounding-dino` | [demo](examples/grounding-dino) |
146+
| [LLMDet](https://github.com/iSEE-Laboratory/LLMDet) | Open-Set Detection With Language | `grounding-dino` | [demo](examples/grounding-dino) |
145147
| [CLIP](https://github.com/openai/CLIP) | Vision-Language Embedding | `clip` | [demo](examples/clip) |
146148
| [jina-clip-v1](https://huggingface.co/jinaai/jina-clip-v1) | Vision-Language Embedding | `clip` | [demo](examples/clip) |
147149
| [jina-clip-v2](https://huggingface.co/jinaai/jina-clip-v2) | Vision-Language Embedding | `clip` | [demo](examples/clip) |

examples/grounding-dino/README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
## Quick Start
22

33
```shell
4-
cargo run -r -F grounding-dino -F cuda --example grounding-dino -- --device cuda --dtype fp16
4+
cargo run -r -F grounding-dino -F cuda --example grounding-dino -- --device cuda --dtype q8
55
```
66

7-
8-
## Results
9-
10-
![](https://github.com/jamjamjon/assets/releases/download/grounding-dino/demo.png)

examples/grounding-dino/main.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ use usls::{models::GroundingDINO, Annotator, Config, DataLoader};
44
#[derive(argh::FromArgs)]
55
/// Example
66
struct Args {
7+
/// source image
8+
#[argh(option, default = "vec![String::from(\"./assets/bus.jpg\")]")]
9+
source: Vec<String>,
10+
711
/// dtype
812
#[argh(option, default = "String::from(\"q8\")")]
913
dtype: String,
@@ -12,47 +16,50 @@ struct Args {
1216
#[argh(option, default = "String::from(\"cpu:0\")")]
1317
device: String,
1418

15-
/// source image
16-
#[argh(option, default = "vec![String::from(\"./assets/bus.jpg\")]")]
17-
source: Vec<String>,
18-
19-
/// open class names
19+
/// captions
2020
#[argh(
2121
option,
2222
default = "vec![
2323
String::from(\"person\"),
24-
String::from(\"a hand\"),
25-
String::from(\"a shoe\"),
2624
String::from(\"bus\"),
27-
String::from(\"dog\"),
25+
String::from(\"a dog\"),
2826
String::from(\"cat\"),
29-
String::from(\"sign\"),
27+
String::from(\"stop sign\"),
3028
String::from(\"tie\"),
31-
String::from(\"monitor\"),
32-
String::from(\"glasses\"),
29+
String::from(\"eye glasses\"),
3330
String::from(\"tree\"),
34-
String::from(\"head\"),
31+
String::from(\"camera\"),
32+
String::from(\"hand\"),
33+
String::from(\"a shoe\"),
34+
String::from(\"balcony\"),
35+
String::from(\"window\"),
3536
]"
3637
)]
3738
labels: Vec<String>,
39+
40+
/// token level class
41+
#[argh(option, default = "false")]
42+
token_level_class: bool,
3843
}
3944

4045
fn main() -> Result<()> {
4146
tracing_subscriber::fmt()
4247
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
4348
.with_timer(tracing_subscriber::fmt::time::ChronoLocal::rfc_3339())
4449
.init();
45-
4650
let args: Args = argh::from_env();
4751

48-
let config = Config::grounding_dino_tiny()
52+
let config = Config::llmdet_tiny()
53+
// mm_gdino_base_all()
54+
// grounding_dino_tiny()
4955
.with_model_dtype(args.dtype.parse()?)
5056
.with_model_device(args.device.parse()?)
5157
.with_text_names_owned(&args.labels)
52-
.with_class_confs(&[0.25])
58+
.with_class_confs(&[0.35])
5359
.with_text_confs(&[0.25])
60+
.with_model_num_dry_run(0)
61+
.with_token_level_class(args.token_level_class)
5462
.commit()?;
55-
5663
let mut model = GroundingDINO::new(config)?;
5764

5865
// load images

src/core/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use aksr::Builder;
44
use crate::models::SamKind;
55
#[cfg(feature = "yolo")]
66
use crate::models::YOLOPredsFormat;
7-
87
use crate::{ORTConfig, ProcessorConfig, Scale, Task, Version};
98

109
/// Configuration for model inference including engines, processors, and task settings.
@@ -69,6 +68,7 @@ pub struct Config {
6968
#[cfg(feature = "sam")]
7069
pub sam_low_res_mask: Option<bool>,
7170
pub max_tokens: Option<usize>,
71+
pub token_level_class: bool,
7272
}
7373

7474
impl Default for Config {
@@ -102,6 +102,7 @@ impl Default for Config {
102102
#[cfg(feature = "sam")]
103103
sam_low_res_mask: None,
104104
topk: None,
105+
token_level_class: false,
105106
model: Default::default(),
106107
encoder: Default::default(),
107108
decoder: Default::default(),

src/models/grounding_dino/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
# Grounding DINO: Marrying DINO with Grounded Pre-Training for Open-Set Object Detection
1+
# Grounding DINO Series
22

3-
## Official Repository
3+
## Repository & Papers
4+
5+
- **GroundingDINO**
6+
- Paper: https://arxiv.org/abs/2303.05499
7+
- Repo: https://github.com/IDEA-Research/GroundingDINO
8+
- **mm-GroundingDINO (mm-gdino)**
9+
- Paper: https://arxiv.org/abs/2401.02361
10+
- Repo: https://github.com/open-mmlab/mmdetection/blob/main/configs/mm_grounding_dino/README.md
11+
- **LLMDet**
12+
- Paper: https://arxiv.org/abs/2501.18954
13+
- Repo: https://github.com/iSEE-Laboratory/LLMDet
414

5-
The official repository can be found on: [GitHub](https://github.com/IDEA-Research/GroundingDINO)
615

716
## Example
817

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
/// Model configuration for `GroundingDino`
1+
/// Model configuration for `GroundingDino` Series
22
impl crate::Config {
33
pub fn grounding_dino() -> Self {
44
Self::default()
55
.with_name("grounding-dino")
6-
.with_model_ixx(0, 0, 1.into()) // TODO: current onnx model does not support bs > 1
7-
.with_model_ixx(0, 2, 800.into()) // TODO: matters
8-
.with_model_ixx(0, 3, 1200.into()) // TODO: matters
6+
.with_model_ixx(0, 0, 1.into())
7+
.with_model_ixx(0, 1, 3.into())
8+
.with_model_ixx(0, 2, 800.into())
9+
.with_model_ixx(0, 3, 1066.into())
910
.with_resize_mode(crate::ResizeMode::FitAdaptive)
1011
.with_resize_filter("CatmullRom")
1112
.with_image_mean(&[0.485, 0.456, 0.406])
@@ -17,10 +18,54 @@ impl crate::Config {
1718
}
1819

1920
pub fn grounding_dino_tiny() -> Self {
20-
Self::grounding_dino().with_model_file("swint-ogc.onnx")
21+
Self::grounding_dino().with_model_file("gdino-tiny.onnx")
2122
}
2223

2324
pub fn grounding_dino_base() -> Self {
24-
Self::grounding_dino().with_model_file("swinb-cogcoor.onnx")
25+
Self::grounding_dino().with_model_file("gdino-base.onnx")
26+
}
27+
28+
pub fn llmdet_tiny() -> Self {
29+
Self::grounding_dino().with_model_file("llmdet-tiny.onnx")
30+
}
31+
32+
pub fn llmdet_base() -> Self {
33+
Self::grounding_dino().with_model_file("llmdet-base.onnx")
34+
}
35+
36+
pub fn llmdet_large() -> Self {
37+
Self::grounding_dino().with_model_file("llmdet-large.onnx")
38+
}
39+
40+
pub fn mm_gdino_tiny_o365v1_goldg_grit_v3det() -> Self {
41+
Self::grounding_dino().with_model_file("mm-gdino-tiny-o365v1-goldg-grit-v3det.onnx")
42+
}
43+
44+
pub fn mm_gdino_tiny_o365v1_goldg_grit() -> Self {
45+
Self::grounding_dino().with_model_file("mm-gdino-tiny-o365v1-goldg-grit.onnx")
46+
}
47+
48+
pub fn mm_gdino_tiny_o365v1_goldg_v3det() -> Self {
49+
Self::grounding_dino().with_model_file("mm-gdino-tiny-o365v1-goldg-v3det.onnx")
50+
}
51+
52+
pub fn mm_gdino_tiny_o365v1_goldg() -> Self {
53+
Self::grounding_dino().with_model_file("mm-gdino-tiny-o365v1-goldg.onnx")
54+
}
55+
56+
pub fn mm_gdino_base_o365v1_goldg_v3det() -> Self {
57+
Self::grounding_dino().with_model_file("mm-gdino-base-o365v1-goldg-v3det.onnx")
58+
}
59+
60+
pub fn mm_gdino_base_all() -> Self {
61+
Self::grounding_dino().with_model_file("mm-gdino-base-all.onnx")
62+
}
63+
64+
pub fn mm_gdino_large_o365v2_oiv6_goldg() -> Self {
65+
Self::grounding_dino().with_model_file("mm-gdino-large-o365v2-oiv6-goldg.onnx")
66+
}
67+
68+
pub fn mm_gdino_large_all() -> Self {
69+
Self::grounding_dino().with_model_file("mm-gdino-large-all.onnx")
2570
}
2671
}

0 commit comments

Comments
 (0)