Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into onnx_yolov9
Browse files Browse the repository at this point in the history
  • Loading branch information
heabeounMKTO committed Apr 24, 2024
2 parents 0a4db84 + 5711fee commit feb3bea
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 5 deletions.
28 changes: 28 additions & 0 deletions examples/onnx_infv9.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
extern crate kesa;
use kesa::backends::compute_backends::ComputeBackendType;
use kesa::backends::onnx_backend::{init_onnx_backend, load_onnx_model};
use anyhow::{Result, Error};
use clap::{ArgAction, Parser,Args };
use kesa::fileutils::get_all_images;


#[derive(Parser, Debug)]
struct CliArguments {
#[arg(long, required=true)]
weights: String,

#[arg(long, required=true)]
folder: String
}


fn main() -> Result<(), Error> {
let args = CliArguments::parse();
let all_imgs = get_all_images(&args.folder);


let _init = init_onnx_backend()?;
let load_model = load_onnx_model(&args.weights, all_imgs[0].to_owned().to_str().unwrap(), false, None);
println!("LOADED MODEL : {:#?}", load_model);
Ok(())
}
3 changes: 2 additions & 1 deletion examples/tch_inference.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature="torch")]
extern crate kesa;
use anyhow::{bail, Error, Result};

Expand Down Expand Up @@ -54,4 +55,4 @@ pub fn main() -> Result<(), Error> {
None,
)?;
Ok(())
}
}
10 changes: 10 additions & 0 deletions src/backends/compute_backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ pub enum ComputeBackendType {
TchModel,
}


#[derive(Debug, Clone)]
pub enum ModelVersion {
V5,
V7,
V8,
V9
}


pub trait InferenceModel: Sized {
fn run(&self, image: image::DynamicImage) -> Result<Embeddings, Error>;
fn warmup(&self);
Expand Down
26 changes: 22 additions & 4 deletions src/kesa_al.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
output::OutputFormat,
};
use anyhow::{Error, Result};
use backends::compute_backends::{get_backend, ComputeBackendType};
use backends::compute_backends::{get_backend, ComputeBackendType, ModelVersion};
#[cfg(feature = "onnxruntime")]
use backends::onnx_backend::{init_onnx_backend, load_onnx_model};

Expand Down Expand Up @@ -62,7 +62,7 @@ struct CliArguments {
/// input cpu or 0 1 2 etc for gpus
device: Option<u32>,

#[arg(long, num_args(2))]
#[arg(long, num_args(2), required=true)]
/// inference image size of the
/// model provided
imgsize: Vec<u32>,
Expand All @@ -72,6 +72,11 @@ struct CliArguments {
/// outputs yolo txt files
/// instead of LabelMe jsons
txt: bool,

#[arg(long, required=true)]
/// yolo version
/// example: "v9"
version: String,

#[arg(long)]
/// amount of threads to use
Expand All @@ -81,7 +86,7 @@ struct CliArguments {
/// cause allocation errors on gpu, if you are using gpu
workers: Option<i64>,

#[arg(long)]
#[arg(long, required=true)]
/// weights to be used
weights: String,
}
Expand Down Expand Up @@ -109,6 +114,19 @@ fn main() -> Result<(), Error> {
None => tch::Device::Cpu,
};


let model_version = match args.version.as_str() {
"v9" => ModelVersion::V9,
"v7" => ModelVersion::V7,
"v8" => ModelVersion::V8,
"v5" => ModelVersion::V5,
_ => panic!("[error]::kesa_al: unsuppourted yolo version {:?}\n[info]::kesa_al: suppourted versions:\n- v9\n- v8\n- v7\n- v5", args.version)
};





let front_sort_dir = format!("{}/front", &args.folder);
let back_sort_dir = format!("{}/back", &args.folder);

Expand Down Expand Up @@ -349,4 +367,4 @@ fn process_onnx_results(
}
}
Ok(())
}
}
58 changes: 58 additions & 0 deletions test/test_v9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
names:
- 10C
- 10D
- 10H
- 10S
- 2C
- 2D
- 2H
- 2S
- 3C
- 3D
- 3H
- 3S
- 4C
- 4D
- 4H
- 4S
- 5C
- 5D
- 5H
- 5S
- 6C
- 6D
- 6H
- 6S
- 7C
- 7D
- 7H
- 7S
- 8C
- 8D
- 8H
- 8S
- 9C
- 9D
- 9H
- 9S
- AC
- AD
- AH
- AS
- JC
- JD
- JH
- JS
- KC
- KD
- KH
- KS
- QC
- QD
- QH
- QS
nc: 52
train: ../export_l2y_test/train/images
val: ../export_l2y_test/val/images
test: ../export_l2y_test/test/images
model_version: yolov9

0 comments on commit feb3bea

Please sign in to comment.