forked from jamjamjon/usls
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
87 lines (75 loc) · 2.35 KB
/
Copy pathmain.rs
File metadata and controls
87 lines (75 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use anyhow::Result;
use usls::{models::GroundingDINO, Annotator, Config, DataLoader};
#[derive(argh::FromArgs)]
/// Example
struct Args {
/// source image
#[argh(option, default = "vec![String::from(\"./assets/bus.jpg\")]")]
source: Vec<String>,
/// dtype
#[argh(option, default = "String::from(\"q8\")")]
dtype: String,
/// device
#[argh(option, default = "String::from(\"cpu:0\")")]
device: String,
/// captions
#[argh(
option,
default = "vec![
String::from(\"person\"),
String::from(\"bus\"),
String::from(\"a dog\"),
String::from(\"cat\"),
String::from(\"stop sign\"),
String::from(\"tie\"),
String::from(\"eye glasses\"),
String::from(\"tree\"),
String::from(\"camera\"),
String::from(\"hand\"),
String::from(\"a shoe\"),
String::from(\"balcony\"),
String::from(\"window\"),
]"
)]
labels: Vec<String>,
/// token level class
#[argh(option, default = "false")]
token_level_class: bool,
}
fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_timer(tracing_subscriber::fmt::time::ChronoLocal::rfc_3339())
.init();
let args: Args = argh::from_env();
let config = Config::llmdet_tiny()
// mm_gdino_base_all()
// grounding_dino_tiny()
.with_model_dtype(args.dtype.parse()?)
.with_model_device(args.device.parse()?)
.with_text_names_owned(&args.labels)
.with_class_confs(&[0.35])
.with_text_confs(&[0.25])
.with_model_num_dry_run(0)
.with_token_level_class(args.token_level_class)
.commit()?;
let mut model = GroundingDINO::new(config)?;
// load images
let xs = DataLoader::try_read_n(&args.source)?;
// run
let ys = model.forward(&xs)?;
// annotate
let annotator = Annotator::default();
for (x, y) in xs.iter().zip(ys.iter()) {
annotator.annotate(x, y)?.save(format!(
"{}.jpg",
usls::Dir::Current
.base_dir_with_subs(&["runs", model.spec()])?
.join(usls::timestamp(None))
.display(),
))?;
}
// summary
usls::perf(false);
Ok(())
}