-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathsam2.rs
More file actions
65 lines (53 loc) · 2.03 KB
/
Copy pathsam2.rs
File metadata and controls
65 lines (53 loc) · 2.03 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
use anyhow::Result;
use clap::Args;
use usls::{Config, DType, Device, Scale};
#[derive(Args, Debug)]
pub struct Sam2Args {
/// Scale: t, s, b, l
#[arg(long, default_value = "t")]
pub scale: String,
/// Encoder Dtype: fp32, fp16, q4f16, etc.
#[arg(long, default_value = "fp32")]
pub encoder_dtype: DType,
/// Encoder Device: cpu, cuda:0, mps, coreml, openvino:CPU, etc.
#[arg(long, global = true, default_value = "cpu")]
pub encoder_device: Device,
/// Decoder Dtype: fp32, fp16, q4f16, etc.
#[arg(long, default_value = "fp32")]
pub decoder_dtype: DType,
/// Decoder Device: cpu, cuda:0, mps, coreml, openvino:CPU, etc.
#[arg(long, global = true, default_value = "cpu")]
pub decoder_device: Device,
/// Processor device (for pre/post processing)
#[arg(long, global = true, default_value = "cpu")]
pub processor_device: Device,
/// Batch size
#[arg(long, global = true, default_value_t = 1)]
pub batch: usize,
/// Min batch size (TensorRT)
#[arg(long, global = true, default_value_t = 1)]
pub min_batch: usize,
/// Max batch size (TensorRT)
#[arg(long, global = true, default_value_t = 4)]
pub max_batch: usize,
/// num dry run
#[arg(long, global = true, default_value_t = 3)]
pub num_dry_run: usize,
}
pub fn config(args: &Sam2Args) -> Result<Config> {
let config = match args.scale.parse()? {
Scale::T => Config::sam2_1_tiny(),
Scale::S => Config::sam2_1_small(),
Scale::B => Config::sam2_1_base_plus(),
Scale::L => Config::sam2_1_large(),
_ => anyhow::bail!("Unsupported SAM2.1 scale: {}. Try t, s, b, l.", args.scale),
}
.with_encoder_dtype(args.encoder_dtype)
.with_encoder_device(args.encoder_device)
.with_decoder_dtype(args.decoder_dtype)
.with_decoder_device(args.decoder_device)
.with_batch_size_min_opt_max_all(args.min_batch, args.batch, args.max_batch)
.with_num_dry_run_all(args.num_dry_run)
.with_image_processor_device(args.processor_device);
Ok(config)
}