-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5ba6b2b
Showing
46 changed files
with
4,296 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
.local | ||
build | ||
|
||
# Rust | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
**/target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
main | ||
|
||
|
||
## --- nodejs --- | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[workspace] | ||
|
||
members = [ | ||
"server", | ||
"retinaface", | ||
"rs-genproto", | ||
] | ||
|
||
[profile.release] | ||
opt-level = 3 | ||
lto = true | ||
debug = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# face-inference-rs | ||
|
||
An example project to build a face recognition, face detection, and face alignment inference service using GRPC, Rust, TensorRT, CUDA, running on Jetson Nano, Jetson Xavier NX. | ||
|
||
## Architecture | ||
|
||
### Deep face analysis | ||
* Face Detection: Retinaface by [deepinsight/insightface](https://github.com/deepinsight/insightface) | ||
* Face Recognition: Arcface by [deepinsight/insightface](https://github.com/deepinsight/insightface) | ||
|
||
### GRPC Server | ||
* Tonic [hyperium/tonic](https://github.com/hyperium/tonic) | ||
* Protobuf [tokio-rs/prost](https://github.com/tokio-rs/prost) | ||
|
||
## Project Structure | ||
|
||
* [retinaface](./retinaface): Rust bindings for Arcface and Retinaface C++ implementations. | ||
* [retinaface/libretinaface](./retinaface/libretinaface): TensorRT implementation of Arcface and Retinaface. Based on [wang-xinyu/tensorrtx](https://github.com/wang-xinyu/tensorrtx). | ||
* [proto](./proto): Protobuf definitions for GRPC server. | ||
* [rs-genproto](./rs-genproto): library that generates rust protobuf for GRPC server. | ||
* [server](./server): Implementation of inference GRPC server. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
syntax = "proto3"; | ||
|
||
package v1.face; | ||
|
||
message RetinaArcFace { | ||
int32 original_image_width = 1; | ||
int32 original_image_height = 2; | ||
|
||
repeated RetinafaceDetection faces = 20; | ||
} | ||
|
||
message RetinafaceDetection { | ||
// Bound Box is within original image_w and h | ||
BBox bbox = 1; | ||
|
||
float class_confidence = 20; | ||
|
||
RetinafaceLandmark landmarks = 30; | ||
|
||
// 512 array of float32 | ||
repeated float arcface_feature = 40; | ||
|
||
int32 retina_engine_version = 50; | ||
int32 arcface_engine_version = 51; | ||
} | ||
|
||
message RetinafaceLandmark { | ||
float left_eye_x = 1; | ||
float left_eye_y = 2; | ||
float right_eye_x = 10; | ||
float right_eye_y = 11; | ||
float nose_x = 20; | ||
float nose_y = 21; | ||
float mouth_left_corner_x = 30; | ||
float mouth_left_corner_y = 31; | ||
float mouth_right_corner_x = 32; | ||
float mouth_right_corner_y = 33; | ||
} | ||
|
||
message BBox { | ||
int32 x1 = 1; | ||
int32 y1 = 2; | ||
int32 x2 = 3; | ||
int32 y2 = 4; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
syntax = "proto3"; | ||
|
||
package v1.infer; | ||
|
||
import "face.proto"; | ||
|
||
service InferV1 { | ||
// RetinaArcFaceFile - | ||
rpc RetinaArcFaceFile(RetinaArcFaceFileRequest) | ||
returns (RetinaArcFaceFileResponse) {} | ||
|
||
// RetinaArcFaceBlob takes image bytes | ||
rpc RetinaArcFaceBlob(RetinaArcFaceBlobRequest) | ||
returns (RetinaArcFaceFileResponse) {} | ||
} | ||
|
||
message RetinaArcFaceFileRequest { string path = 1; } | ||
|
||
message RetinaArcFaceFileResponse { v1.face.RetinaArcFace face = 1; } | ||
|
||
message RetinaArcFaceBlobRequest { bytes blob = 1; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "retinafacers" | ||
version = "0.1.0" | ||
authors = ["Chen Liang <[email protected]>"] | ||
edition = "2018" | ||
|
||
exclude = ["build/**/*", "libretinaface/build/**/*"] | ||
|
||
[build-dependencies] | ||
cmake = "0.1.44" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// extern crate bindgen; | ||
extern crate cmake; | ||
|
||
use std::env; | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-changed=libretinaface/src/**/*"); | ||
println!("cargo:rerun-if-changed=libretinaface/CMakeLists.txt"); | ||
|
||
// println!("cargo:rerun-if-changed=wrapper.h"); | ||
|
||
let tensorrt_root = match env::var("TENSORRT_ROOT") { | ||
Ok(v) => v, | ||
Err(_) => String::from("/usr/local/lib"), | ||
}; | ||
let cuda_root = match env::var("CUDA_HOME") { | ||
Ok(v) => v, | ||
Err(_) => String::from("/usr/local/cuda-10.2/targets/aarch64-linux/lib"), | ||
}; | ||
|
||
const CURRENT_DIR: &str = "libretinaface"; | ||
|
||
let cpp_libs = cmake::Config::new(CURRENT_DIR) | ||
.always_configure(true) | ||
.cxxflag("-DCMAKE_CUDA_FLAGS=\"--expt-extended-lambda -std=c++14\"") | ||
.build(); | ||
|
||
println!("cargo:rustc-link-lib=stdc++"); | ||
println!("cargo:rustc-link-lib=dylib=stdc++"); | ||
// println!("cargo:rustc-link-lib=dylib=stdc++"); | ||
// println!("cargo:rustc-flags=-l dylib=stdc++"); | ||
println!("cargo:rustc-link-search=native={}", cpp_libs.display()); | ||
println!("cargo:rustc-link-search=native={}", &tensorrt_root); | ||
println!("cargo:rustc-link-search=native={}", &cuda_root); | ||
println!("cargo:rustc-link-search=native=/usr/lib/aarch64-linux-gnu"); | ||
println!("cargo:rustc-link-search=native=/usr/local/cuda/lib64"); | ||
println!("cargo:rustc-link-lib=nvinfer"); | ||
println!("cargo:rustc-link-lib=cudart"); | ||
println!("cargo:rustc-link-lib=static=retinaface"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
cmake_minimum_required(VERSION 3.9 FATAL_ERROR) | ||
|
||
project(retinaface LANGUAGES CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wno-write-strings") | ||
find_package(CUDA REQUIRED) | ||
message("-- CUDA version: ${CUDA_VERSION}") | ||
enable_language(CUDA) | ||
|
||
|
||
if(CUDA_VERSION_MAJOR GREATER 9) | ||
message("-- CUDA ${CUDA_VERSION_MAJOR} detected, enabling SM_72") | ||
|
||
set( | ||
CUDA_NVCC_FLAGS | ||
${CUDA_NVCC_FLAGS}; | ||
-gencode arch=compute_72,code=sm_72 | ||
) | ||
endif() | ||
|
||
find_package(OpenCV REQUIRED) | ||
|
||
if(DEFINED TensorRT_DIR) | ||
include_directories("${TensorRT_DIR}/include") | ||
link_directories("${TensorRT_DIR}/lib") | ||
endif(DEFINED TensorRT_DIR) | ||
list(APPEND CUDA_INCLUDE_DIRS "/usr/local/cuda-10.2/targets/aarch64-linux/include") | ||
message("-- CUDA INCLUDE DIRS: ${CUDA_INCLUDE_DIRS}") | ||
include_directories(${CUDA_INCLUDE_DIRS}) | ||
message("-- PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}") | ||
message("-- OpenCV_INCLUDE_DIRS: ${OpenCV_INCLUDE_DIRS}, ${OpenCV_LIBS}") | ||
if(NOT DEFINED ARCH) | ||
set(ARCH "sm_70") | ||
endif(NOT DEFINED ARCH) | ||
|
||
|
||
include_directories( | ||
${PROJECT_SOURCE_DIR}/src | ||
) | ||
|
||
add_library(retinaface STATIC | ||
${PROJECT_SOURCE_DIR}/src/cuda/decode.hpp | ||
${PROJECT_SOURCE_DIR}/src/cuda/decode_plugin.hpp | ||
${PROJECT_SOURCE_DIR}/src/cuda/decode.cu | ||
${PROJECT_SOURCE_DIR}/src/cuda/prelu.h | ||
${PROJECT_SOURCE_DIR}/src/cuda/prelu.cu | ||
|
||
${PROJECT_SOURCE_DIR}/src/logging.hpp | ||
${PROJECT_SOURCE_DIR}/src/utils.hpp | ||
|
||
${PROJECT_SOURCE_DIR}/src/base_engine.hpp | ||
${PROJECT_SOURCE_DIR}/src/base_engine.cpp | ||
|
||
${PROJECT_SOURCE_DIR}/src/c_retinaface.h | ||
${PROJECT_SOURCE_DIR}/src/c_retinaface.cpp | ||
|
||
${PROJECT_SOURCE_DIR}/src/retinaface.hpp | ||
${PROJECT_SOURCE_DIR}/src/retinaface.cpp | ||
|
||
${PROJECT_SOURCE_DIR}/src/arcface.hpp | ||
${PROJECT_SOURCE_DIR}/src/arcface.cpp | ||
) | ||
target_sources(retinaface | ||
PUBLIC | ||
${PROJECT_SOURCE_DIR}/src/c_retinaface.h | ||
${PROJECT_SOURCE_DIR}/src/arcface.hpp | ||
) | ||
target_link_libraries(retinaface | ||
nvinfer | ||
cuda | ||
cudart | ||
${CUDA_LIBRARIES} | ||
) | ||
set_target_properties(retinaface PROPERTIES | ||
CUDA_RESOLVE_DEVICE_SYMBOLS ON | ||
) | ||
# install(TARGETS retinaface DESTINATION .) | ||
|
||
install(TARGETS retinaface | ||
EXPORT RetinafaceTargets | ||
DESTINATION ${CMAKE_INSTALL_PREFIX} | ||
) | ||
|
||
add_subdirectory(src/cuda) | ||
include_directories(${OpenCV_INCLUDE_DIRS}) | ||
add_subdirectory(src/engine) | ||
add_subdirectory(src/example) |
Oops, something went wrong.