Skip to main content

Config

Struct Config 

Source
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

Source

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§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.