Skip to content

Commit

Permalink
Add onnx build script
Browse files Browse the repository at this point in the history
  • Loading branch information
jamjamjon committed May 13, 2024
1 parent fc970fc commit b9c0778
Show file tree
Hide file tree
Showing 13 changed files with 893 additions and 1,086 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ ab_glyph = "0.2.23"
geo = "0.28.0"
prost = "0.12.4"
human_bytes = "0.4.3"
fast_image_resize = "3.0.4"
fast_image_resize = "3.0.4"

[build-dependencies]
prost-build = "0.12.1"
9 changes: 9 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Need this for CoreML. See: https://ort.pyke.io/perf/execution-providers#coreml
#[cfg(target_os = "macos")]
println!("cargo:rustc-link-arg=-fapple-link-rtlib");

// Build onnx
prost_build::compile_protos(&["src/core/onnx.proto3"], &["src/core"])?;
Ok(())
}
5 changes: 4 additions & 1 deletion examples/clip/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let feats_image = model.encode_images(&images).unwrap();

// use image to query texts
let matrix = feats_image.dot2(&feats_text)?;
let matrix = match feats_image.embedding() {
Some(x) => x.dot2(feats_text.embedding().unwrap())?,
None => continue,
};

// summary
for i in 0..paths.len() {
Expand Down
Binary file removed examples/dinov2/images/bus.jpg
Binary file not shown.
8 changes: 5 additions & 3 deletions examples/dinov2/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use usls::{models::Dinov2, Options};
use usls::{models::Dinov2, DataLoader, Options};

fn main() -> Result<(), Box<dyn std::error::Error>> {
// build model
Expand All @@ -7,8 +7,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.with_i00((1, 1, 1).into())
.with_i02((224, 224, 224).into())
.with_i03((224, 224, 224).into());
let _model = Dinov2::new(options)?;
println!("TODO...");
let mut model = Dinov2::new(options)?;
let x = vec![DataLoader::try_read("./examples/dinov2/images/1.jpg")?];
let y = model.run(&x)?;
println!("{y:?}");

// query from vector
// let ys = model.query_from_vec(
Expand Down
5 changes: 4 additions & 1 deletion src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod engine;
mod logits_sampler;
mod metric;
mod min_opt_max;
pub mod onnx;
pub mod ops;
mod options;
mod tokenizer_stream;
Expand All @@ -23,3 +22,7 @@ pub use min_opt_max::MinOptMax;
pub use options::Options;
pub use tokenizer_stream::TokenizerStream;
pub use ts::Ts;

pub mod onnx {
include!(concat!(env!("OUT_DIR"), "/onnx.rs"));
}
Loading

0 comments on commit b9c0778

Please sign in to comment.