From 46094570745e4957875043638b806c7727df476d Mon Sep 17 00:00:00 2001 From: oatiz Date: Tue, 16 Apr 2024 18:18:43 +0800 Subject: [PATCH] fix: svtr deduplication bug --- examples/svtr/README.md | 3 +- examples/svtr/main.rs | 5 ++- examples/svtr/text4.png | Bin 0 -> 24832 bytes src/models/svtr.rs | 69 ++++++++++++++++++++++------------------ 4 files changed, 44 insertions(+), 33 deletions(-) create mode 100644 examples/svtr/text4.png diff --git a/examples/svtr/README.md b/examples/svtr/README.md index 23b0bf8..6c94700 100644 --- a/examples/svtr/README.md +++ b/examples/svtr/README.md @@ -25,6 +25,7 @@ cargo run -r --example svtr ```shell [Texts] from the background, but also separate text instances which -[Texts] are closely jointed. Some examples are ilustrated in Fig.7. +[Texts] are closely jointed. Some examples are illustrated in Fig.7. [Texts] 你有这么高速运转的机械进入中国,记住我给出的原理 +[Texts] 110022345 ``` diff --git a/examples/svtr/main.rs b/examples/svtr/main.rs index 81a4d67..3ca77b1 100644 --- a/examples/svtr/main.rs +++ b/examples/svtr/main.rs @@ -15,10 +15,13 @@ fn main() -> Result<(), Box> { DataLoader::try_read("./examples/svtr/text1.png")?, DataLoader::try_read("./examples/svtr/text2.png")?, DataLoader::try_read("./examples/svtr/text3.png")?, + DataLoader::try_read("./examples/svtr/text4.png")?, ]; // run - model.run(&xs)?; + for text in model.run(&xs)?.into_iter() { + println!("[Texts] {text}") + } Ok(()) } diff --git a/examples/svtr/text4.png b/examples/svtr/text4.png new file mode 100644 index 0000000000000000000000000000000000000000..9700cf6520b85fffe88a34f9bb53b5905da45a92 GIT binary patch literal 24832 zcmcJ&3wRTC7CwxNSOp;>NJXR(5ep&&s8FyWvn;Yz5wa|+RSJoSP_aP33Qb6wk((82 z8=yidg=7`6Y8N6RgwiAf^pcidBG*t_nl@<@N@;VMCYeblGvAqj3Z?(=zdrkYJdd}@ zWb&Ke<(&7t=RL>m|CpaRu>Ujt`}FBE@Qv4B`)8j%4_$_T&wlg~`1_y>S8@ z-(TBWQjp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_L9AZ#(%+*6zwd+ttmqnhzMI) zUtyS=H~pG*8H#G!S_ZSf3C*q`L73*PSs4?AwsoLx*&nH`hcvJ}9~$jiR|C6<`U=qs z4O7L%p)K7mh#RgM)^5s*=KW3Dwc zq%sd2Yv_viz~E7~@%w#eYvB!fq+R>Hh7!r{`HCxhc|}bnY{dJ{^Uy#O+eQAqy(4_! zP@U>!B4Xou>@ei=5CAq0_5JsK3)J3oCOCLmp6tCoXKvoRLMYq)`M#H&&G#%9?M?aH zz1W^f1`BiFY2w~LatYhy`#y6pwENy!!XB8V!N1o#bEN_cm;c`uo;3@K;sx z#DR`YcX2ct*YiD&zz@t#%P+Rx>Gn@SSN{8li1lM0UH-2XpDn)KH5&fU27TU`Gyk=t Je|vxP{{yfg#W4T? literal 0 HcmV?d00001 diff --git a/src/models/svtr.rs b/src/models/svtr.rs index 1bd88ae..0f8f8dd 100644 --- a/src/models/svtr.rs +++ b/src/models/svtr.rs @@ -41,46 +41,53 @@ impl SVTR { }) } - pub fn run(&mut self, xs: &[DynamicImage]) -> Result<()> { + pub fn run(&mut self, xs: &[DynamicImage]) -> Result> { let xs_ = ops::resize_with_fixed_height(xs, self.height.opt as u32, self.width.opt as u32, 0.0)?; let xs_ = ops::normalize(xs_, 0.0, 255.0); let ys: Vec> = self.engine.run(&[xs_])?; let ys = ys[0].to_owned(); - self.postprocess(&ys)?; - Ok(()) + + self.postprocess(&ys) } - pub fn postprocess(&self, xs: &Array) -> Result<()> { - for batch in xs.axis_iter(Axis(0)) { - let mut texts: Vec = Vec::new(); - for (i, seq) in batch.axis_iter(Axis(0)).enumerate() { - let (id, &confidence) = seq - .into_iter() - .enumerate() - .reduce(|max, x| if x.1 > max.1 { x } else { max }) - .unwrap(); - if id == 0 || confidence < self.confs[0] { - continue; - } - if i == 0 && id == self.vocab.len() - 1 { - continue; - } - texts.push(self.vocab[id].to_owned()); - } - texts.dedup(); + pub fn postprocess(&self, output: &Array) -> Result> { + let mut texts: Vec = Vec::new(); + for batch in output.axis_iter(Axis(0)) { + let preds = batch + .axis_iter(Axis(0)) + .filter_map(|x| { + x.into_iter() + .enumerate() + .max_by(|(_, x), (_, y)| x.total_cmp(y)) + }) + .collect::>(); - print!("[Texts] "); - if texts.is_empty() { - println!("Nothing detected!"); - } else { - for text in texts.into_iter() { - print!("{text}"); - } - println!(); - } + let text = preds + .iter() + .enumerate() + .fold(Vec::new(), |mut text_ids, (idx, (text_id, &confidence))| { + if *text_id == 0 || confidence < self.confs[0] { + return text_ids; + } + + if idx == 0 || idx == self.vocab.len() - 1 { + return text_ids; + } + + if *text_id != preds[idx - 1].0 { + text_ids.push(*text_id); + } + text_ids + }) + .into_iter() + .map(|idx| self.vocab[idx].to_owned()) + .collect::(); + + texts.push(text); } - Ok(()) + Ok(texts) } } +