Add DB model for text detection

This commit is contained in:
jamjamjon
2024-03-31 02:14:53 +08:00
parent a5cee66dfd
commit ce9a416b71
11 changed files with 318 additions and 35 deletions

39
examples/db/README.md Normal file
View File

@ -0,0 +1,39 @@
## Quick Start
```shell
cargo run -r --example db
```
## Or you can manully
### 1. Donwload ONNX Model
[ppocr-v3-db-dyn](https://github.com/jamjamjon/assets/releases/download/v0.0.1/ppocr-v3-db-dyn.onnx)
[ppocr-v4-db-dyn](https://github.com/jamjamjon/assets/releases/download/v0.0.1/ppocr-v4-db-dyn.onnx)
### 2. Specify the ONNX model path in `main.rs`
```Rust
let options = Options::default()
.with_model("ONNX_PATH") // <= modify this
.with_profile(false);
```
### 3. Run
```bash
cargo run -r --example db
```
### Speed test
| Model | Image size | TensorRT<br />f16 | TensorRT<br />f32 | CUDA<br />f32 |
| --------------- | ---------- | ----------------- | ----------------- | ------------- |
| ppocr-v3-db-dyn | 640x640 | 1.8585ms | 2.5739ms | 4.3314ms |
| ppocr-v4-db-dyn | 640x640 | 2.0507ms | 2.8264ms | 6.6064ms |
***Test on RTX3060***
## Results
![](./demo.jpg)

BIN
examples/db/demo.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

25
examples/db/main.rs Normal file
View File

@ -0,0 +1,25 @@
use usls::{models::DB, DataLoader, Options};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// build model
let options = Options::default()
.with_model("../models/ppocr-v4-db-dyn.onnx")
.with_i00((1, 1, 4).into())
.with_i02((608, 640, 960).into())
.with_i03((608, 640, 960).into())
.with_confs(&[0.7])
.with_saveout("DB-Text-Detection")
.with_dry_run(5)
// .with_trt(0)
// .with_fp16(true)
.with_profile(true);
let mut model = DB::new(&options)?;
// load image
let x = DataLoader::try_read("./assets/math.jpg")?;
// run
let _y = model.run(&[x])?;
Ok(())
}