mirror of
https://github.com/mii443/usls.git
synced 2025-08-22 15:45:41 +00:00
44 lines
1.3 KiB
Rust
44 lines
1.3 KiB
Rust
use usls::{models::Blip, DataLoader, Options};
|
|
|
|
#[derive(argh::FromArgs)]
|
|
/// BLIP 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>,
|
|
}
|
|
|
|
fn main() -> anyhow::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_visual = Options::blip_v1_base_caption_visual()
|
|
.with_model_device(args.device.as_str().try_into()?)
|
|
.commit()?;
|
|
let options_textual = Options::blip_v1_base_caption_textual()
|
|
.with_model_device(args.device.as_str().try_into()?)
|
|
.commit()?;
|
|
let mut model = Blip::new(options_visual, options_textual)?;
|
|
|
|
// image caption
|
|
let xs = DataLoader::try_read_n(&args.source)?;
|
|
|
|
// unconditional caption
|
|
let ys = model.forward(&xs, None)?;
|
|
println!("Unconditional: {:?}", ys);
|
|
|
|
// conditional caption
|
|
let ys = model.forward(&xs, Some("this image depict"))?;
|
|
println!("Conditional: {:?}", ys);
|
|
|
|
Ok(())
|
|
}
|