-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.rs
53 lines (42 loc) · 1.33 KB
/
main.rs
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
use anyhow::Result;
use usls::{models::SLANet, Annotator, DataLoader, Options};
#[derive(argh::FromArgs)]
/// Example
struct Args {
/// source
#[argh(option, default = "String::from(\"images/table.png\")")]
source: String,
/// device
#[argh(option, default = "String::from(\"cpu:0\")")]
device: String,
/// dtype
#[argh(option, default = "String::from(\"auto\")")]
dtype: String,
}
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();
// build model
let options = Options::slanet_lcnet_v2_mobile_ch()
.with_model_device(args.device.as_str().try_into()?)
.with_model_dtype(args.dtype.as_str().try_into()?)
.commit()?;
let mut model = SLANet::new(options)?;
// load
let xs = DataLoader::try_read_batch(&[args.source])?;
// run
let ys = model.forward(&xs)?;
// println!("{:?}", ys);
// annotate
let annotator = Annotator::default()
.with_keypoints_radius(2)
.with_skeletons(&[(0, 1), (1, 2), (2, 3), (3, 0)])
.with_saveout(model.spec());
annotator.annotate(&xs, &ys);
// summary
model.summary();
Ok(())
}