cli_support/
common.rs

1use clap::Args;
2use std::path::PathBuf;
3
4/// Shared thresholds used by inference-related tools.
5#[derive(Debug, Clone, Copy)]
6pub struct ThresholdOpts {
7    pub objectness_threshold: f32,
8    pub iou_threshold: f32,
9}
10
11impl ThresholdOpts {
12    pub fn new(objectness_threshold: f32, iou_threshold: f32) -> Self {
13        Self {
14            objectness_threshold,
15            iou_threshold,
16        }
17    }
18}
19
20/// Optional detector weights path.
21#[derive(Debug, Clone)]
22pub struct WeightsOpts {
23    pub detector_weights: Option<PathBuf>,
24}
25
26impl WeightsOpts {
27    pub fn new(detector_weights: Option<PathBuf>) -> Self {
28        Self { detector_weights }
29    }
30}
31
32/// Capture output/prune options shared across capture-related binaries.
33#[derive(Debug, Clone, Args)]
34pub struct CaptureOutputArgs {
35    /// Directory to write captures into.
36    #[arg(long, default_value = "assets/datasets/captures")]
37    pub output_root: PathBuf,
38    /// Optionally prune empty-label frames after datagen (writes filtered copy).
39    #[arg(long, default_value_t = false)]
40    pub prune_empty: bool,
41    /// Optional output root for pruned runs (defaults to "<output_root>_filtered").
42    #[arg(long)]
43    pub prune_output_root: Option<PathBuf>,
44}
45
46#[derive(Debug, Clone)]
47pub struct CaptureOutputOpts {
48    pub output_root: PathBuf,
49    pub prune_empty: bool,
50    pub prune_output_root: Option<PathBuf>,
51}
52
53impl CaptureOutputOpts {
54    pub fn new(
55        output_root: PathBuf,
56        prune_empty: bool,
57        prune_output_root: Option<PathBuf>,
58    ) -> Self {
59        Self {
60            output_root,
61            prune_empty,
62            prune_output_root,
63        }
64    }
65
66    /// Resolve the destination root for pruned runs, defaulting to "<output_root>_filtered".
67    pub fn resolve_prune_output_root(&self) -> PathBuf {
68        if let Some(root) = &self.prune_output_root {
69            return root.clone();
70        }
71        let mut base = self.output_root.clone();
72        let suffix = base
73            .file_name()
74            .and_then(|s| s.to_str())
75            .map(|s| format!("{s}_filtered"))
76            .unwrap_or_else(|| "captures_filtered".to_string());
77        base.set_file_name(suffix);
78        base
79    }
80}
81
82impl From<&CaptureOutputArgs> for CaptureOutputOpts {
83    fn from(args: &CaptureOutputArgs) -> Self {
84        CaptureOutputOpts::new(
85            args.output_root.clone(),
86            args.prune_empty,
87            args.prune_output_root.clone(),
88        )
89    }
90}
91
92/// Warehouse output root shared across warehouse_* tooling.
93#[derive(Debug, Clone, Args)]
94pub struct WarehouseOutputArgs {
95    /// Output root for warehouse artifacts.
96    #[arg(long, default_value = "artifacts/tensor_warehouse")]
97    pub output_root: PathBuf,
98}
99
100#[derive(Debug, Clone)]
101pub struct WarehouseOutputOpts {
102    pub output_root: PathBuf,
103}
104
105impl From<&WarehouseOutputArgs> for WarehouseOutputOpts {
106    fn from(args: &WarehouseOutputArgs) -> Self {
107        WarehouseOutputOpts {
108            output_root: args.output_root.clone(),
109        }
110    }
111}
112
113/// Optional WGPU env hints for tooling; consumers can apply these to the environment or log them.
114#[derive(Debug, Clone, Default)]
115pub struct WgpuEnvHints {
116    pub backend: Option<String>,
117    pub adapter_name: Option<String>,
118    pub power_pref: Option<String>,
119    pub rust_log: Option<String>,
120}
121
122impl WgpuEnvHints {
123    pub fn empty() -> Self {
124        Self::default()
125    }
126}