Add MODNet model (#11)

* Add MODNet for portrait matting

* Minor fixes

* Move assets to home directory

* Add colormap

* ci

* Update README.md
This commit is contained in:
Jamjamjon
2024-04-30 15:26:53 +08:00
committed by GitHub
parent 9697f4d5b0
commit 371a08011f
46 changed files with 3425 additions and 808 deletions

15
examples/modnet/README.md Normal file
View File

@ -0,0 +1,15 @@
## Quick Start
```shell
cargo run -r --example modnet
```
## ONNX Model
- [modnet-dyn](https://github.com/jamjamjon/assets/releases/download/v0.0.1/modnet-dyn.onnx)
## Results
![](./demo.png)

BIN
examples/modnet/demo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

23
examples/modnet/main.rs Normal file
View File

@ -0,0 +1,23 @@
use usls::{models::MODNet, Annotator, DataLoader, Options};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// build model
let options = Options::default()
.with_model("modnet-dyn.onnx")?
.with_i00((1, 1, 4).into())
.with_i02((416, 512, 800).into())
.with_i03((416, 512, 800).into());
let model = MODNet::new(&options)?;
// load image
let x = vec![DataLoader::try_read("./assets/portrait.jpg")?];
// run
let y = model.run(&x)?;
// annotate
let annotator = Annotator::default().with_saveout("MODNet");
annotator.annotate(&x, &y);
Ok(())
}