Skip to content

Commit 9b87be4

Browse files
authored
Merge pull request #71 from HyperInspire/dev/detection
Dev/detection Former-commit-id: 12004ab
2 parents c0eca24 + 1a88663 commit 9b87be4

21 files changed

+313
-80
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
99
# Current version
1010
set(INSPIRE_FACE_VERSION_MAJOR 1)
1111
set(INSPIRE_FACE_VERSION_MINOR 1)
12-
set(INSPIRE_FACE_VERSION_PATCH 1)
12+
set(INSPIRE_FACE_VERSION_PATCH 2)
1313

1414
# Converts the version number to a string
1515
string(CONCAT INSPIRE_FACE_VERSION_MAJOR_STR ${INSPIRE_FACE_VERSION_MAJOR})
@@ -108,6 +108,7 @@ if (APPLE)
108108
endif ()
109109
else()
110110
if (ISF_BUILD_LINUX_ARM7 OR ISF_BUILD_LINUX_AARCH64)
111+
set(DISABLE_GUI ON)
111112
add_definitions("-DDISABLE_GUI")
112113
# set(OpenCV_DIR ${ISF_THIRD_PARTY_DIR}/opencv/opencv-linux-armhf/share/OpenCV)
113114
# set(OpenCV_STATIC_INCLUDE_DIR ${PATH_3RDPARTY}/opencv/opencv-linux-armhf/include/)

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ If you require further information on tracking development branches, CI/CD proce
88

99
Please contact [contact@insightface.ai](mailto:contact@insightface.ai?subject=InspireFace) for commercial support, including obtaining and integrating higher accuracy models, as well as custom development.
1010

11-
## ChangeLogs
11+
## Change Logs
12+
13+
**`2024-07-02`** Fixed several bugs in the face detector with multi-level input.
1214

1315
**`2024-06-27`** Verified iOS usability and fixed some bugs.
1416

@@ -69,6 +71,9 @@ The '3rdparty' directory already includes the MNN library and specifies a partic
6971
- Prepare the cross-compilation toolchain in advance, such as gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf
7072
- CUDA (version 10.1 or higher)
7173
- GPU-based inference requires installing NVIDIA's CUDA dependencies on the device.
74+
- Eigen3
75+
- If you need to use the tracking-by-detection feature, you must have Eigen3 installed in advance.
76+
7277
- RKNN
7378
- Adjust and select versions currently supported for specific requirements.
7479

@@ -357,7 +362,7 @@ For different scenarios, we currently provide several Packs, each containing mul
357362

358363
| Name | Supported Devices | Note | Link |
359364
| --- | --- | --- | --- |
360-
| Pikachu | CPU | Lightweight edge-side model | [GDrive](https://drive.google.com/file/d/1i4uC-dZTQxdVgn2rP0ZdfJTMkJIXgYY4/view?usp=drive_link) |
361-
| Megatron | CPU, GPU | Local or server-side model | [GDrive](https://drive.google.com/file/d/1i4uC-dZTQxdVgn2rP0ZdfJTMkJIXgYY4/view?usp=drive_link) |
362-
| Gundam-RV1109 | RKNPU | Supports RK1109 and RK1126 | [GDrive](https://drive.google.com/file/d/1i4uC-dZTQxdVgn2rP0ZdfJTMkJIXgYY4/view?usp=drive_link) |
365+
| Pikachu | CPU | Lightweight edge-side model | [GDrive](https://drive.google.com/drive/folders/1krmv9Pj0XEZXR1GRPHjW_Sl7t4l0dNSS?usp=sharing) |
366+
| Megatron | CPU, GPU | Local or server-side model | [GDrive](https://drive.google.com/drive/folders/1krmv9Pj0XEZXR1GRPHjW_Sl7t4l0dNSS?usp=sharing) |
367+
| Gundam-RV1109 | RKNPU | Supports RK1109 and RK1126 | [GDrive](https://drive.google.com/drive/folders/1krmv9Pj0XEZXR1GRPHjW_Sl7t4l0dNSS?usp=sharing) |
363368

command/build_android.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ reorganize_structure() {
3939
;;
4040
sample)
4141
# Copy the sample directory
42-
if [ -d "$arch_dir/sample" ]; then
43-
cp -r "$arch_dir/sample/"* "$base_path/$main_dir/$arch/"
42+
if [ -d "$arch_dir/InspireFace/sample" ]; then
43+
cp -r "$arch_dir/InspireFace/sample/"* "$base_path/$main_dir/$arch/"
4444
fi
4545
;;
4646
test)
4747
# Copy the test directory
48-
if [ -d "$arch_dir/test" ]; then
49-
cp -r "$arch_dir/test/"* "$base_path/$main_dir/$arch/"
48+
if [ -d "$arch_dir/InspireFace/test" ]; then
49+
cp -r "$arch_dir/InspireFace/test/"* "$base_path/$main_dir/$arch/"
5050
fi
5151
;;
5252
esac

command/build_cross_rv1109rv1126_armhf.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ cmake -DCMAKE_SYSTEM_NAME=Linux \
5555
-DISF_ENABLE_TEST_EVALUATION=OFF \
5656
-DISF_BUILD_SHARED_LIBS=ON ${SCRIPT_DIR}
5757

58-
make -j4
58+
make -j1
5959
make install
6060

6161
move_install_files "$(pwd)"

cpp/inspireface/c_api/inspireface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ HYPER_CAPI_EXPORT extern HResult HFCreateInspireFaceSession(
171171
* @param detectMode Detection mode to be used.
172172
* @param maxDetectFaceNum Maximum number of faces to detect.
173173
* @param detectPixelLevel Modify the input resolution level of the detector, the larger the better,
174-
* the need to input a multiple of 160, such as 160, 320, 640, the default value -1 is 160.
174+
* the need to input a multiple of 160, such as 160, 320, 640, the default value -1 is 320.
175175
* @param trackByDetectModeFPS If you are using the MODE_TRACK_BY_DETECTION tracking mode,
176176
* this value is used to set the fps frame rate of your current incoming video stream, which defaults to -1 at 30fps.
177177
* @param handle Pointer to the context handle that will be returned.

cpp/inspireface/information.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
#define INSPIRE_FACE_VERSION_MAJOR_STR "1"
99
#define INSPIRE_FACE_VERSION_MINOR_STR "1"
10-
#define INSPIRE_FACE_VERSION_PATCH_STR "1"
10+
#define INSPIRE_FACE_VERSION_PATCH_STR "2"
1111

1212
#endif //HYPERFACEREPO_INFORMATION_H

cpp/inspireface/middleware/utils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,14 +643,13 @@ inline cv::Rect GetNewBox(int src_w, int src_h, cv::Rect bbox, float scale) {
643643

644644

645645
template<typename T>
646-
inline bool isShortestSideGreaterThan(const cv::Rect_<T>& rect, T value) {
646+
inline bool isShortestSideGreaterThan(const cv::Rect_<T>& rect, T value, float scale) {
647647
// Find the shortest edge
648-
T shortestSide = std::min(rect.width, rect.height);
648+
T shortestSide = std::min(rect.width / scale, rect.height / scale);
649649
// Determines whether the shortest edge is greater than the given value
650650
return shortestSide > value;
651651
}
652652

653-
654653
} // namespace inspire
655654

656655
#endif

cpp/inspireface/track_module/face_track.cpp

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void FaceTrack::DetectFace(const cv::Mat &input, float scale) {
342342
Object obj;
343343
const auto box = boxes[i];
344344
obj.rect = Rect_<float>(box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
345-
if (!isShortestSideGreaterThan<float>(obj.rect, filter_minimum_face_px_size)) {
345+
if (!isShortestSideGreaterThan<float>(obj.rect, filter_minimum_face_px_size, scale)) {
346346
// Filter too small face detection box
347347
continue;
348348
}
@@ -364,8 +364,8 @@ void FaceTrack::DetectFace(const cv::Mat &input, float scale) {
364364
for (int i = 0; i < boxes.size(); i++) {
365365
bbox[i] = cv::Rect(cv::Point(static_cast<int>(boxes[i].x1), static_cast<int>(boxes[i].y1)),
366366
cv::Point(static_cast<int>(boxes[i].x2), static_cast<int>(boxes[i].y2)));
367-
368-
if (!isShortestSideGreaterThan<float>(bbox[i], filter_minimum_face_px_size)) {
367+
368+
if (!isShortestSideGreaterThan<float>(bbox[i], filter_minimum_face_px_size, scale)) {
369369
// Filter too small face detection box
370370
continue;
371371
}
@@ -378,16 +378,14 @@ void FaceTrack::DetectFace(const cv::Mat &input, float scale) {
378378

379379
FaceObject faceinfo(tracking_idx_, bbox[i], FaceLandmark::NUM_OF_LANDMARK);
380380
faceinfo.detect_bbox_ = bbox[i];
381-
381+
382382
// Control that the number of faces detected does not exceed the maximum limit
383-
if (candidate_faces_.size() < max_detected_faces_) {
384-
candidate_faces_.push_back(faceinfo);
385-
} else {
386-
// If the maximum limit is exceeded, you can choose to discard the currently detected face or choose the face to discard according to the policy
387-
// For example, face confidence can be compared and faces with lower confidence can be discarded
388-
// Take the example of simply discarding the last face
389-
candidate_faces_.pop_back();
383+
if (candidate_faces_.size() >= max_detected_faces_)
384+
{
385+
continue;
390386
}
387+
388+
candidate_faces_.push_back(faceinfo);
391389
}
392390
}
393391

@@ -396,9 +394,10 @@ void FaceTrack::DetectFace(const cv::Mat &input, float scale) {
396394
int FaceTrack::Configuration(inspire::InspireArchive &archive) {
397395
// Initialize the detection model
398396
InspireModel detModel;
399-
auto ret = archive.LoadModel("face_detect", detModel);
397+
auto scheme = ChoiceMultiLevelDetectModel(m_dynamic_detection_input_level_);
398+
auto ret = archive.LoadModel(scheme, detModel);
400399
if (ret != SARC_SUCCESS) {
401-
INSPIRE_LOGE("Load %s error: %d", "face_detect", ret);
400+
INSPIRE_LOGE("Load %s error: %d", "face_detect_320", ret);
402401
return HERR_ARCHIVE_LOAD_MODEL_FAILURE;
403402
}
404403
InitDetectModel(detModel);
@@ -444,21 +443,9 @@ int FaceTrack::InitLandmarkModel(InspireModel &model) {
444443

445444
int FaceTrack::InitDetectModel(InspireModel &model) {
446445
std::vector<int> input_size;
447-
if (m_dynamic_detection_input_level_ != -1) {
448-
if (m_dynamic_detection_input_level_ % 160 != 0 || m_dynamic_detection_input_level_ < 160) {
449-
INSPIRE_LOGE("The input size '%d' for the custom detector is not valid. \
450-
Please use a multiple of 160 (minimum 160) for the input dimensions, such as 320 or 640.", m_dynamic_detection_input_level_);
451-
return HERR_INVALID_DETECTION_INPUT;
452-
}
453-
// Wide-Range mode temporary value
454-
input_size = {m_dynamic_detection_input_level_, m_dynamic_detection_input_level_};
455-
model.Config().set<std::vector<int>>("input_size", input_size);
456-
} else {
457-
input_size = model.Config().get<std::vector<int>>("input_size");
458-
}
459-
bool dym = true;
446+
input_size = model.Config().get<std::vector<int>>("input_size");
460447
m_face_detector_ = std::make_shared<FaceDetect>(input_size[0]);
461-
auto ret = m_face_detector_->loadData(model, model.modelType, dym);
448+
auto ret = m_face_detector_->loadData(model, model.modelType, false);
462449
if (ret != InferenceHelper::kRetOk) {
463450
return HERR_ARCHIVE_LOAD_FAILURE;
464451
}
@@ -499,5 +486,41 @@ void FaceTrack::SetTrackPreviewSize(int preview_size) {
499486
track_preview_size_ = preview_size;
500487
}
501488

489+
std::string FaceTrack::ChoiceMultiLevelDetectModel(const int32_t pixel_size) {
490+
const int32_t supported_sizes[] = {160, 320, 640};
491+
const std::string scheme_names[] = {"face_detect_160", "face_detect_320", "face_detect_640"};
492+
const int32_t num_sizes = sizeof(supported_sizes) / sizeof(supported_sizes[0]);
493+
494+
if (pixel_size == -1)
495+
{
496+
return scheme_names[1];
497+
}
498+
499+
// Check for exact match
500+
for (int i = 0; i < num_sizes; ++i) {
501+
if (pixel_size == supported_sizes[i]) {
502+
return scheme_names[i];
503+
}
504+
}
505+
506+
// Find the closest match
507+
int32_t closest_size = supported_sizes[0];
508+
std::string closest_scheme = scheme_names[0];
509+
int32_t min_diff = std::abs(pixel_size - supported_sizes[0]);
510+
511+
for (int i = 1; i < num_sizes; ++i) {
512+
int32_t diff = std::abs(pixel_size - supported_sizes[i]);
513+
if (diff < min_diff) {
514+
min_diff = diff;
515+
closest_size = supported_sizes[i];
516+
closest_scheme = scheme_names[i];
517+
}
518+
}
519+
520+
INSPIRE_LOGW("Input pixel size %d is not supported. Choosing the closest scheme: %s closest_scheme for size %d.",
521+
pixel_size, closest_scheme.c_str(), closest_size);
522+
523+
return closest_scheme;
524+
}
502525

503526
} // namespace hyper

cpp/inspireface/track_module/face_track.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ class INSPIRE_API FaceTrack {
138138
*/
139139
int InitFacePoseModel(InspireModel& model);
140140

141+
/**
142+
* @brief Select the detection model scheme to be used according to the input pixel level.
143+
* @param pixel_size Currently, only 160, 320, and 640 pixel sizes are supported.
144+
* @return Return the corresponding scheme name, only ”face_detect_160”, ”face_detect_320”, ”face_detect_640” are supported.
145+
*/
146+
std::string ChoiceMultiLevelDetectModel(const int32_t pixel_size);
147+
141148
public:
142149

143150
/**

cpp/inspireface/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
InspireFace Version: 1.1.1
1+
InspireFace Version: 1.1.2

0 commit comments

Comments
 (0)