diff --git a/Cargo.lock b/Cargo.lock index 9e6f8ac..1362894 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -192,18 +192,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - -[[package]] -name = "base64ct" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba" - [[package]] name = "bindgen" version = "0.70.1" @@ -249,15 +237,6 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6099cdc01846bc367c4e7dd630dc5966dccf36b652fae7a74e17b640411a91b2" -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - [[package]] name = "bounding-box" version = "0.1.0" @@ -270,6 +249,7 @@ dependencies = [ "ordered-float", "simba", "thiserror 2.0.15", + "tracing", ] [[package]] @@ -290,24 +270,12 @@ version = "1.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3995eaeebcdf32f91f980d360f78732ddc061097ab4e39991ae7a6ace9194677" -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - [[package]] name = "byteorder-lite" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" -[[package]] -name = "bytes" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" - [[package]] name = "cc" version = "1.2.33" @@ -442,31 +410,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "core-foundation-sys" version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" -[[package]] -name = "cpufeatures" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" -dependencies = [ - "libc", -] - [[package]] name = "crc32fast" version = "1.5.0" @@ -507,16 +456,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - [[package]] name = "csv" version = "1.3.1" @@ -538,16 +477,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "der" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" -dependencies = [ - "pem-rfc7468", - "zeroize", -] - [[package]] name = "deranged" version = "0.4.0" @@ -595,16 +524,6 @@ dependencies = [ "nu-ansi-term 0.50.1", ] -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - [[package]] name = "displaydoc" version = "0.2.5" @@ -663,16 +582,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" -[[package]] -name = "errno" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" -dependencies = [ - "libc", - "windows-sys 0.60.2", -] - [[package]] name = "error-stack" version = "0.5.0" @@ -722,12 +631,6 @@ dependencies = [ "thiserror 1.0.69", ] -[[package]] -name = "fastrand" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" - [[package]] name = "fdeflate" version = "0.3.7" @@ -737,18 +640,6 @@ dependencies = [ "simd-adler32", ] -[[package]] -name = "filetime" -version = "0.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586" -dependencies = [ - "cfg-if", - "libc", - "libredox", - "windows-sys 0.59.0", -] - [[package]] name = "flate2" version = "1.1.2" @@ -769,33 +660,12 @@ dependencies = [ "spin", ] -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "foldhash" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.1" @@ -811,16 +681,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" version = "0.2.16" @@ -998,23 +858,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "http" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "httparse" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" - [[package]] name = "iana-time-zone" version = "0.1.63" @@ -1344,17 +1187,6 @@ dependencies = [ "windows-targets 0.53.3", ] -[[package]] -name = "libredox" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3" -dependencies = [ - "bitflags 2.9.2", - "libc", - "redox_syscall", -] - [[package]] name = "libsqlite3-sys" version = "0.35.0" @@ -1365,12 +1197,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "linux-raw-sys" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" - [[package]] name = "litemap" version = "0.8.0" @@ -1563,23 +1389,6 @@ dependencies = [ "getrandom 0.2.16", ] -[[package]] -name = "native-tls" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "ndarray" version = "0.16.1" @@ -1773,50 +1582,6 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4ce411919553d3f9fa53a0880544cda985a112117a0444d5ff1e870a893d6ea" -[[package]] -name = "openssl" -version = "0.10.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8" -dependencies = [ - "bitflags 2.9.2", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" - -[[package]] -name = "openssl-sys" -version = "0.9.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90096e2e47630d78b7d1c20952dc621f957103f8bc2c8359ec81290d75238571" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "ordered-float" version = "5.0.0" @@ -1829,8 +1594,6 @@ dependencies = [ [[package]] name = "ort" version = "2.0.0-rc.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fa7e49bd669d32d7bc2a15ec540a527e7764aec722a45467814005725bcd721" dependencies = [ "ndarray", "ort-sys", @@ -1841,14 +1604,8 @@ dependencies = [ [[package]] name = "ort-sys" version = "2.0.0-rc.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2aba9f5c7c479925205799216e7e5d07cc1d4fa76ea8058c60a9a30f6a4e890" dependencies = [ - "flate2", "pkg-config", - "sha2", - "tar", - "ureq", ] [[package]] @@ -1863,15 +1620,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" -[[package]] -name = "pem-rfc7468" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" -dependencies = [ - "base64ct", -] - [[package]] name = "percent-encoding" version = "2.3.1" @@ -2116,15 +1864,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "redox_syscall" -version = "0.5.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" -dependencies = [ - "bitflags 2.9.2", -] - [[package]] name = "regex" version = "1.11.1" @@ -2217,37 +1956,6 @@ dependencies = [ "semver", ] -[[package]] -name = "rustix" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" -dependencies = [ - "bitflags 2.9.2", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.60.2", -] - -[[package]] -name = "rustls-pemfile" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" -dependencies = [ - "rustls-pki-types", -] - -[[package]] -name = "rustls-pki-types" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79" -dependencies = [ - "zeroize", -] - [[package]] name = "rustversion" version = "1.0.22" @@ -2269,44 +1977,12 @@ dependencies = [ "bytemuck", ] -[[package]] -name = "schannel" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags 2.9.2", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "semver" version = "1.0.26" @@ -2354,17 +2030,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha2" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "sharded-slab" version = "0.1.7" @@ -2426,17 +2091,6 @@ version = "2.0.0-alpha.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d44cfb396c3caf6fbfd0ab422af02631b69ddd96d2eff0b0f0724f9024051b" -[[package]] -name = "socks" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c3dbbd9ae980613c6dd8e28a9407b50509d3803b57624d5dfe8315218cd58b" -dependencies = [ - "byteorder", - "libc", - "winapi", -] - [[package]] name = "spin" version = "0.9.8" @@ -2499,36 +2153,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" -[[package]] -name = "tar" -version = "0.4.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d863878d212c87a19c1a610eb53bb01fe12951c0501cf5a0d65f724914a667a" -dependencies = [ - "filetime", - "libc", - "xattr", -] - [[package]] name = "target-lexicon" version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" -[[package]] -name = "tempfile" -version = "3.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" -dependencies = [ - "fastrand", - "getrandom 0.3.3", - "once_cell", - "rustix", - "windows-sys 0.59.0", -] - [[package]] name = "thiserror" version = "1.0.69" @@ -2757,37 +2387,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" -[[package]] -name = "ureq" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00432f493971db5d8e47a65aeb3b02f8226b9b11f1450ff86bb772776ebadd70" -dependencies = [ - "base64", - "der", - "log", - "native-tls", - "percent-encoding", - "rustls-pemfile", - "rustls-pki-types", - "socks", - "ureq-proto", - "utf-8", - "webpki-root-certs", -] - -[[package]] -name = "ureq-proto" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5b6cabebbecc4c45189ab06b52f956206cea7d8c8a20851c35a85cb169224cc" -dependencies = [ - "base64", - "http", - "httparse", - "log", -] - [[package]] name = "url" version = "2.5.4" @@ -2799,12 +2398,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - [[package]] name = "utf8_iter" version = "1.0.4" @@ -2856,12 +2449,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" @@ -2935,15 +2522,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "webpki-root-certs" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4ffd8df1c57e87c325000a3d6ef93db75279dc3a231125aac571650f22b12a" -dependencies = [ - "rustls-pki-types", -] - [[package]] name = "weezl" version = "0.1.10" @@ -3221,16 +2799,6 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" -[[package]] -name = "xattr" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af3a19837351dc82ba89f8a125e22a3c475f05aba604acc023d62b2739ae2909" -dependencies = [ - "libc", - "rustix", -] - [[package]] name = "yansi-term" version = "0.1.2" @@ -3305,12 +2873,6 @@ dependencies = [ "synstructure", ] -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" - [[package]] name = "zerotrie" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index 79505d1..c3e61a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,9 @@ edition = "2024" [patch."https://github.com/uttarayan21/mnn-rs"] mnn = { path = "/Users/fs0c131y/Projects/aftershoot/mnn-rs" } +[patch.crates-io] +ort = { path = "/Users/fs0c131y/Projects/ort" } + [workspace.dependencies] ndarray-image = { path = "ndarray-image" } @@ -53,7 +56,7 @@ 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" } +ort = { version = "2.0.0-rc.10", default-features = false, features = [ "std", "tracing", "ndarray"]} [profile.release] debug = true diff --git a/bounding-box/Cargo.toml b/bounding-box/Cargo.toml index 9900d8d..db9936e 100644 --- a/bounding-box/Cargo.toml +++ b/bounding-box/Cargo.toml @@ -12,7 +12,10 @@ num = "0.4.3" ordered-float = "5.0.0" simba = "0.9.0" thiserror = "2.0.12" +tracing = { version = "0.1.41", optional = true, default-features = false } [features] ndarray = ["dep:ndarray"] -default = ["ndarray"] +tracing = ["dep:tracing"] + +default = ["ndarray", "tracing"] diff --git a/bounding-box/src/draw.rs b/bounding-box/src/draw.rs index c6dca47..9bfebd9 100644 --- a/bounding-box/src/draw.rs +++ b/bounding-box/src/draw.rs @@ -65,8 +65,9 @@ impl Drawable> for Aabb2 { pixel.assign(&color); }) }) - .inspect_err(|e| { - dbg!(e); + .inspect_err(|_e| { + #[cfg(feature = "tracing")] + tracing::error!("{_e}") }) .ok(); }); diff --git a/bounding-box/src/lib.rs b/bounding-box/src/lib.rs index a60cf6b..f56802b 100644 --- a/bounding-box/src/lib.rs +++ b/bounding-box/src/lib.rs @@ -54,7 +54,6 @@ impl AxisAlignedBoundingBox { if max_point >= min_point { Self::from_min_max_vertices(min_point, max_point) } else { - dbg!(max_point, min_point); panic!("max_point must be greater than or equal to min_point"); } } diff --git a/facenet.mnn b/facenet.mnn deleted file mode 100644 index 75f56e2..0000000 Binary files a/facenet.mnn and /dev/null differ diff --git a/flake.nix b/flake.nix index b00ef85..621a115 100644 --- a/flake.nix +++ b/flake.nix @@ -88,25 +88,41 @@ ".hpp" ".cpp" ".cc" + ".mnn" + ".onnx" ]; in lib.cleanSourceWith { filter = sourceFilters; src = ./.; }; - commonArgs = + commonArgs = let + ort_static = pkgs.onnxruntime.overrideAttrs (old: { + cmakeFlags = + old.cmakeFlags + ++ [ + "-Donnxruntime_BUILD_SHARED_LIB=OFF" + "-Donnxruntime_BUILD_STATIC_LIB=ON" + ]; + }); + in { inherit src; pname = name; stdenv = p: p.clangStdenv; doCheck = false; LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; + ORT_LIB_LOCATION = "${ort_static}"; + ORT_ENV_SYSTEM_LIB_LOCATION = "${ort_static}/lib"; + # ORT_ENV_PREFER_DYNAMIC_LINK = true; nativeBuildInputs = with pkgs; [ cmake pkg-config ]; buildInputs = with pkgs; - [onnxruntime] + [ + # onnxruntime + ] ++ (lib.optionals pkgs.stdenv.isDarwin [ libiconv apple-sdk_13 @@ -160,9 +176,11 @@ inherit cargoArtifacts; } // { - nativeBuildInputs = with pkgs; [ - installShellFiles - ]; + nativeBuildInputs = with pkgs; + commonArgs.nativeBuildInputs + ++ [ + installShellFiles + ]; postInstall = '' installShellCompletion --cmd ${name} \ --bash <($out/bin/${name} completions bash) \ @@ -189,6 +207,7 @@ cmake mnn cargo-make + hyperfine ] ++ (lib.optionals pkgs.stdenv.isDarwin [ apple-sdk_13 diff --git a/justfile b/justfile index 7cdf001..8cab077 100644 --- a/justfile +++ b/justfile @@ -1,2 +1,13 @@ -run: - cargo run -r detect -- ./1000066593.jpg +run_onnx ep = "cpu" arg = "selfie.jpg": + cargo run -r detect -p {{ep}} -t 0.3 -o detected.jpg -- {{arg}} +run_mnn forward = "cpu" arg = "selfie.jpg": + cargo run -r detect -f {{forward}} -o detected.jpg -- {{arg}} + +open: + open detected.jpg + +bench: + cargo build --release + BINARY="" hyperfine --warmup 3 --export-markdown benchmark.md \ + "$CARGO_TARGET_DIR/release/detector detect -f coreml selfie.jpg" \ + "$CARGO_TARGET_DIR/release/detector detect -f coreml -b 16 selfie.jpg" diff --git a/ndarray-image/src/lib.rs b/ndarray-image/src/lib.rs index a1f129a..339630e 100644 --- a/ndarray-image/src/lib.rs +++ b/ndarray-image/src/lib.rs @@ -59,7 +59,9 @@ mod rgba8 { mod gray8 { use super::Result; - pub(super) fn image_as_ndarray(image: &image::GrayImage) -> Result> { + pub(super) fn image_as_ndarray( + image: &image::GrayImage, + ) -> Result> { let (width, height) = image.dimensions(); let data = image.as_raw(); ndarray::ArrayView2::from_shape((height as usize, width as usize), data) @@ -112,7 +114,7 @@ mod gray_alpha8 { mod dynamic_image { use super::*; - pub fn image_as_ndarray(image: &image::DynamicImage) -> Result> { + pub fn image_as_ndarray(image: &image::DynamicImage) -> Result> { Ok(match image { image::DynamicImage::ImageRgb8(img) => rgb8::image_as_ndarray(img)?.into_dyn(), image::DynamicImage::ImageRgba8(img) => rgba8::image_as_ndarray(img)?.into_dyn(), diff --git a/src/cli.rs b/src/cli.rs index 439b0f1..b198bce 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -56,6 +56,8 @@ pub struct Detect { pub threshold: f32, #[clap(short, long, default_value_t = 0.3)] pub nms_threshold: f32, + #[clap(short, long, default_value_t = 8)] + pub batch_size: usize, pub image: PathBuf, } diff --git a/src/main.rs b/src/main.rs index 200fdcf..16ae9cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,10 +11,9 @@ const RETINAFACE_MODEL_MNN: &[u8] = include_bytes!("../models/retinaface.mnn"); const FACENET_MODEL_MNN: &[u8] = include_bytes!("../models/facenet.mnn"); const RETINAFACE_MODEL_ONNX: &[u8] = include_bytes!("../models/retinaface.onnx"); const FACENET_MODEL_ONNX: &[u8] = include_bytes!("../models/facenet.onnx"); -const CHUNK_SIZE: usize = 2; pub fn main() -> Result<()> { tracing_subscriber::fmt() - .with_env_filter("trace") + .with_env_filter("error") .with_thread_ids(true) .with_thread_names(true) .with_target(false) @@ -35,8 +34,6 @@ pub fn main() -> Result<()> { } }) .unwrap_or(cli::Executor::Mnn(mnn::ForwardType::CPU)); - // .then_some(cli::Executor::Mnn) - // .unwrap_or(cli::Executor::Ort); match executor { cli::Executor::Mnn(forward) => { @@ -92,7 +89,9 @@ where D: facedet::FaceDetector, E: faceembed::FaceEmbedder, { - let image = image::open(detect.image).change_context(Error)?; + let image = image::open(&detect.image) + .change_context(Error) + .attach_printable(detect.image.to_string_lossy().to_string())?; let image = image.into_rgb8(); let mut array = image .into_ndarray() @@ -122,7 +121,7 @@ where // }) .map(|roi| { roi.as_standard_layout() - .fast_resize(512, 512, &ResizeOptions::default()) + .fast_resize(160, 160, &ResizeOptions::default()) .change_context(Error) }) // .inspect(|f| { @@ -133,15 +132,15 @@ where .collect::>>()?; let face_roi_views = face_rois.iter().map(|roi| roi.view()).collect::>(); - let chunk_size = CHUNK_SIZE; + let chunk_size = detect.batch_size; let embeddings = face_roi_views .chunks(chunk_size) .map(|chunk| { tracing::info!("Processing chunk of size: {}", chunk.len()); - if chunk.len() < 8 { + if chunk.len() < chunk_size { tracing::warn!("Chunk size is less than 8, padding with zeros"); - let zeros = Array3::zeros((512, 512, 3)); + let zeros = Array3::zeros((160, 160, 3)); let zero_array = core::iter::repeat(zeros.view()) .take(chunk_size) .collect::>(); @@ -158,7 +157,7 @@ where Ok(output) } }) - .collect::>>>(); + .collect::>>>()?; let v = array.view(); if let Some(output) = detect.output { diff --git a/src/ort_ep.rs b/src/ort_ep.rs index 9470ce7..3a49363 100644 --- a/src/ort_ep.rs +++ b/src/ort_ep.rs @@ -107,7 +107,15 @@ impl ExecutionProvider { { #[cfg(feature = "ort-coreml")] { - Some(CoreMLExecutionProvider::default().build()) + use tap::Tap; + + Some( + CoreMLExecutionProvider::default() + .with_model_format( + ort::execution_providers::coreml::CoreMLModelFormat::MLProgram, + ) + .build(), + ) } #[cfg(not(feature = "ort-coreml"))] {