pub struct Config {
pub stem_channels: [usize; 3],
pub blocks: Vec<Vec<BlockConfig>>,
}Expand description
骨干的配置(config.json 里的 backbone_config)。
Fields§
§stem_channels: [usize; 3]§blocks: Vec<Vec<BlockConfig>>Implementations§
Source§impl Config
impl Config
Sourcepub fn from_json(v: &Value) -> Result<Config, String>
pub fn from_json(v: &Value) -> Result<Config, String>
从 config.json 的 backbone_config 读。只支持 stem_type = "large"、缩放 1.0、
不用可学习仿射块(PP-OCRv6 的检测、识别都是这样)。
Examples found in repository?
examples/backbone_smoke.rs (line 13)
4fn main() {
5 let a: Vec<String> = std::env::args().skip(1).collect();
6 let dir = std::path::Path::new(&a[0]);
7 let (h, w): (usize, usize) = (a[1].parse().unwrap(), a[2].parse().unwrap());
8 let cfg: serde_json::Value =
9 serde_json::from_slice(&std::fs::read(dir.join("config.json")).unwrap()).unwrap();
10 let wts =
11 pagesift_infer::Weights::from_bytes(&std::fs::read(dir.join("model.safetensors")).unwrap())
12 .unwrap();
13 let c = pagesift_ocr::lcnet::Config::from_json(&cfg).unwrap();
14 let b = pagesift_ocr::lcnet::Backbone::load(&wts, "model.backbone.encoder", &c).unwrap();
15 let x = pagesift_infer::Tensor::new(
16 vec![3, h, w],
17 (0..3 * h * w)
18 .map(|i| ((i % 97) as f32 / 97.0) - 0.5)
19 .collect(),
20 );
21 let t = Instant::now();
22 let outs = b.forward(&x);
23 for o in &outs {
24 println!(
25 "{:?} 均值 {:.5}",
26 o.shape,
27 o.data.iter().sum::<f32>() / o.data.len() as f32
28 );
29 }
30 println!("{:.1} ms", t.elapsed().as_secs_f64() * 1e3);
31}Trait Implementations§
Auto Trait Implementations§
impl Forget for Config
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more