mirror of
https://github.com/mii443/usls.git
synced 2025-12-03 02:58:22 +00:00
update (#109)
* Add docs * Add mediapipe-selfie-segmenter model * Update README.md * Update RTMO model
This commit is contained in:
10
examples/mediapipe-selfie-segmentation/README.md
Normal file
10
examples/mediapipe-selfie-segmentation/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
## Quick Start
|
||||
|
||||
```shell
|
||||
cargo run -r --example mediapipe-selfie-segmentation -- --dtype f16
|
||||
```
|
||||
|
||||
|
||||
## Results
|
||||
|
||||

|
||||
49
examples/mediapipe-selfie-segmentation/main.rs
Normal file
49
examples/mediapipe-selfie-segmentation/main.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use usls::{models::MediaPipeSegmenter, Annotator, Config, DataLoader};
|
||||
|
||||
#[derive(argh::FromArgs)]
|
||||
/// Example
|
||||
struct Args {
|
||||
/// dtype
|
||||
#[argh(option, default = "String::from(\"auto\")")]
|
||||
dtype: String,
|
||||
|
||||
/// device
|
||||
#[argh(option, default = "String::from(\"cpu:0\")")]
|
||||
device: String,
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
||||
.with_timer(tracing_subscriber::fmt::time::ChronoLocal::rfc_3339())
|
||||
.init();
|
||||
let args: Args = argh::from_env();
|
||||
|
||||
// build model
|
||||
let config = Config::mediapipe_selfie_segmentater()
|
||||
.with_model_dtype(args.dtype.parse()?)
|
||||
.with_model_device(args.device.parse()?)
|
||||
.commit()?;
|
||||
let mut model = MediaPipeSegmenter::new(config)?;
|
||||
|
||||
// load image
|
||||
let xs = DataLoader::try_read_n(&["images/selfie-segmenter.png"])?;
|
||||
|
||||
// run
|
||||
let ys = model.forward(&xs)?;
|
||||
|
||||
// annotate
|
||||
let annotator =
|
||||
Annotator::default().with_mask_style(usls::Style::mask().with_mask_cutout(true));
|
||||
for (x, y) in xs.iter().zip(ys.iter()) {
|
||||
annotator.annotate(x, y)?.save(format!(
|
||||
"{}.jpg",
|
||||
usls::Dir::Current
|
||||
.base_dir_with_subs(&["runs", model.spec()])?
|
||||
.join(usls::timestamp(None))
|
||||
.display(),
|
||||
))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,21 +1,48 @@
|
||||
use anyhow::Result;
|
||||
use usls::{models::RTMO, Annotator, Config, DataLoader, Style, SKELETON_COCO_19};
|
||||
|
||||
#[derive(argh::FromArgs)]
|
||||
/// Example
|
||||
struct Args {
|
||||
/// dtype
|
||||
#[argh(option, default = "String::from(\"fp16\")")]
|
||||
dtype: String,
|
||||
|
||||
/// device
|
||||
#[argh(option, default = "String::from(\"cpu:0\")")]
|
||||
device: String,
|
||||
|
||||
/// scale: s, m, l
|
||||
#[argh(option, default = "String::from(\"t\")")]
|
||||
scale: String,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
||||
.with_timer(tracing_subscriber::fmt::time::ChronoLocal::rfc_3339())
|
||||
.init();
|
||||
let args: Args = argh::from_env();
|
||||
|
||||
// build model
|
||||
let mut model = RTMO::new(Config::rtmo_s().commit()?)?;
|
||||
let config = match args.scale.as_str() {
|
||||
"t" => Config::rtmo_t(),
|
||||
"s" => Config::rtmo_s(),
|
||||
"m" => Config::rtmo_m(),
|
||||
"l" => Config::rtmo_l(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
.with_model_dtype(args.dtype.parse()?)
|
||||
.with_model_device(args.device.parse()?)
|
||||
.commit()?;
|
||||
let mut model = RTMO::new(config)?;
|
||||
|
||||
// load image
|
||||
let xs = DataLoader::try_read_n(&["./assets/bus.jpg"])?;
|
||||
|
||||
// run
|
||||
let ys = model.forward(&xs)?;
|
||||
println!("ys: {:?}", ys);
|
||||
// println!("ys: {:?}", ys);
|
||||
|
||||
// annotate
|
||||
let annotator = Annotator::default()
|
||||
@@ -37,5 +64,8 @@ fn main() -> Result<()> {
|
||||
))?;
|
||||
}
|
||||
|
||||
// summary
|
||||
model.summary();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user