feat: Added stuff
Some checks failed
build / checks-matrix (push) Successful in 19m21s
build / codecov (push) Failing after 19m19s
docs / docs (push) Failing after 28m51s
build / checks-build (push) Has been cancelled

This commit is contained in:
uttarayan21
2025-08-19 20:52:29 +05:30
parent 33798467ba
commit d8bf68dfed
5 changed files with 15 additions and 67 deletions

6
Cargo.lock generated
View File

@@ -1299,6 +1299,7 @@ dependencies = [
[[package]]
name = "mnn"
version = "0.2.0"
source = "git+https://github.com/uttarayan21/mnn-rs?branch=restructure-tensor-type#4128b5b40e03c8744fc0e68f6684ef8a2dd971e5"
dependencies = [
"dunce",
"error-stack",
@@ -1312,7 +1313,7 @@ dependencies = [
[[package]]
name = "mnn-bridge"
version = "0.1.0"
source = "git+https://github.com/uttarayan21/mnn-rs?branch=restructure-tensor-type#456c53307ff551d8cb8e4e380c7febf7c16ba0ab"
source = "git+https://github.com/uttarayan21/mnn-rs?branch=restructure-tensor-type#4128b5b40e03c8744fc0e68f6684ef8a2dd971e5"
dependencies = [
"error-stack",
"mnn",
@@ -1322,7 +1323,7 @@ dependencies = [
[[package]]
name = "mnn-sync"
version = "0.1.0"
source = "git+https://github.com/uttarayan21/mnn-rs?branch=restructure-tensor-type#456c53307ff551d8cb8e4e380c7febf7c16ba0ab"
source = "git+https://github.com/uttarayan21/mnn-rs?branch=restructure-tensor-type#4128b5b40e03c8744fc0e68f6684ef8a2dd971e5"
dependencies = [
"error-stack",
"flume",
@@ -1334,6 +1335,7 @@ dependencies = [
[[package]]
name = "mnn-sys"
version = "0.1.0"
source = "git+https://github.com/uttarayan21/mnn-rs?branch=restructure-tensor-type#4128b5b40e03c8744fc0e68f6684ef8a2dd971e5"
dependencies = [
"anyhow",
"bindgen",

View File

@@ -5,15 +5,12 @@ members = ["ndarray-image", "ndarray-resize", ".", "bounding-box"]
version = "0.1.0"
edition = "2024"
[patch."https://github.com/uttarayan21/mnn-rs"]
mnn = { path = "/Users/fs0c131y/Projects/aftershoot/mnn-rs" }
[workspace.dependencies]
ndarray-image = { path = "ndarray-image" }
ndarray-resize = { path = "ndarray-resize" }
mnn = { git = "https://github.com/uttarayan21/mnn-rs", version = "0.2.0", features = [
"metal",
"coreml",
# "metal",
# "coreml",
"tracing",
], branch = "restructure-tensor-type" }
mnn-bridge = { git = "https://github.com/uttarayan21/mnn-rs", version = "0.1.0", features = [
@@ -53,7 +50,11 @@ bounding-box = { version = "0.1.0", path = "bounding-box" }
color = "0.3.1"
itertools = "0.14.0"
ordered-float = "5.0.0"
ort = { version = "2.0.0-rc.10", default-features = false, features = [ "std", "tracing", "ndarray"]}
ort = { version = "2.0.0-rc.10", default-features = false, features = [
"std",
"tracing",
"ndarray",
] }
[profile.release]
debug = true
@@ -65,5 +66,7 @@ ort-tensorrt = ["ort/tensorrt"]
ort-tvm = ["ort/tvm"]
ort-openvino = ["ort/openvino"]
ort-directml = ["ort/directml"]
mnn-metal = ["mnn/metal"]
mnn-coreml = ["mnn/coreml"]
default = ["ort-coreml"]
default = []

View File

@@ -52,7 +52,7 @@
mnn = mnn-overlay.packages.${system}.mnn.override {
src = mnn-src;
buildConverter = true;
enableMetal = true;
enableMetal = pkgs.stdenv.isDarwin;
enableOpencl = true;
};
})

View File

@@ -61,35 +61,6 @@ impl FaceDetection {
) -> std::result::Result<FaceDetectionBuilder, error_stack::Report<crate::errors::Error>> {
FaceDetectionBuilder::new(model)
}
pub fn new(path: impl AsRef<Path>) -> Result<Self> {
let model = std::fs::read(path)
.change_context(Error)
.attach_printable("Failed to read model file")?;
Self::new_from_bytes(&model)
}
pub fn new_from_bytes(model: &[u8]) -> Result<Self> {
tracing::info!("Loading face detection model from bytes");
let mut model = mnn::Interpreter::from_bytes(model)
.map_err(|e| e.into_inner())
.change_context(Error)
.attach_printable("Failed to load model from bytes")?;
model.set_session_mode(mnn::SessionMode::Release);
model
.set_cache_file("retinaface.cache", 128)
.change_context(Error)
.attach_printable("Failed to set cache file")?;
let bc = mnn::BackendConfig::default().with_memory_mode(mnn::MemoryMode::High);
let sc = mnn::ScheduleConfig::new()
.with_type(mnn::ForwardType::Metal)
.with_backend_config(bc);
tracing::info!("Creating session handle for face detection model");
let handle = mnn_sync::SessionHandle::new(model, sc)
.change_context(Error)
.attach_printable("Failed to create session handle")?;
Ok(FaceDetection { handle })
}
}
impl FaceDetector for FaceDetection {

View File

@@ -56,12 +56,6 @@ impl EmbeddingGeneratorBuilder {
impl EmbeddingGenerator {
const INPUT_NAME: &'static str = "serving_default_input_6:0";
const OUTPUT_NAME: &'static str = "StatefulPartitionedCall:0";
pub fn new(path: impl AsRef<Path>) -> Result<Self> {
let model = std::fs::read(path)
.change_context(Error)
.attach_printable("Failed to read model file")?;
Self::new_from_bytes(&model)
}
pub fn builder<T: AsRef<[u8]>>(
model: T,
@@ -69,28 +63,6 @@ impl EmbeddingGenerator {
EmbeddingGeneratorBuilder::new(model)
}
pub fn new_from_bytes(model: &[u8]) -> Result<Self> {
tracing::info!("Loading face embedding model from bytes");
let mut model = mnn::Interpreter::from_bytes(model)
.map_err(|e| e.into_inner())
.change_context(Error)
.attach_printable("Failed to load model from bytes")?;
model.set_session_mode(mnn::SessionMode::Release);
model
.set_cache_file("facenet.cache", 128)
.change_context(Error)
.attach_printable("Failed to set cache file")?;
let bc = mnn::BackendConfig::default().with_memory_mode(mnn::MemoryMode::High);
let sc = mnn::ScheduleConfig::new()
.with_type(mnn::ForwardType::Metal)
.with_backend_config(bc);
tracing::info!("Creating session handle for face embedding model");
let handle = mnn_sync::SessionHandle::new(model, sc)
.change_context(Error)
.attach_printable("Failed to create session handle")?;
Ok(Self { handle })
}
pub fn run_models(&self, face: ArrayView4<u8>) -> Result<Array2<f32>> {
let tensor = face
// .permuted_axes((0, 3, 1, 2))