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
58 lines (48 loc) · 1.49 KB
/
Copy pathmain.rs
File metadata and controls
58 lines (48 loc) · 1.49 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
use anyhow::Result;
use usls::{models::SmolVLM, Config, DataLoader, Scale};
#[derive(argh::FromArgs)]
/// Example
struct Args {
/// device
#[argh(option, default = "String::from(\"cpu:0\")")]
device: String,
/// source image
#[argh(option, default = "vec![String::from(\"./assets/bus.jpg\")]")]
source: Vec<String>,
/// promt
#[argh(option, default = "String::from(\"Can you describe this image?\")")]
prompt: String,
/// scale
#[argh(option, default = "String::from(\"256m\")")]
scale: 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 config = match args.scale.parse()? {
Scale::Million(256.) => Config::smolvlm_256m(),
Scale::Million(500.) => Config::smolvlm_500m(),
_ => unimplemented!(),
}
.with_device_all(args.device.parse()?)
.commit()?;
let mut model = SmolVLM::new(config)?;
// load images
let xs = DataLoader::try_read_n(&args.source)?;
// run
let ys = model.forward(&xs, &args.prompt)?;
for y in ys.iter() {
let texts = y.texts();
if !texts.is_empty() {
for text in texts {
println!("[User]: {}\n\n[Assistant]:{:?}", args.prompt, text);
}
}
}
usls::perf(false);
Ok(())
}