mirror of
https://github.com/deepinsight/insightface.git
synced 2026-08-20 19:37:57 +00:00
Update InspireFace to 1.1.2
This commit is contained in:
@@ -171,7 +171,7 @@ HYPER_CAPI_EXPORT extern HResult HFCreateInspireFaceSession(
|
||||
* @param detectMode Detection mode to be used.
|
||||
* @param maxDetectFaceNum Maximum number of faces to detect.
|
||||
* @param detectPixelLevel Modify the input resolution level of the detector, the larger the better,
|
||||
* the need to input a multiple of 160, such as 160, 320, 640, the default value -1 is 160.
|
||||
* the need to input a multiple of 160, such as 160, 320, 640, the default value -1 is 320.
|
||||
* @param trackByDetectModeFPS If you are using the MODE_TRACK_BY_DETECTION tracking mode,
|
||||
* this value is used to set the fps frame rate of your current incoming video stream, which defaults to -1 at 30fps.
|
||||
* @param handle Pointer to the context handle that will be returned.
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
|
||||
#define INSPIRE_FACE_VERSION_MAJOR_STR "1"
|
||||
#define INSPIRE_FACE_VERSION_MINOR_STR "1"
|
||||
#define INSPIRE_FACE_VERSION_PATCH_STR "1"
|
||||
#define INSPIRE_FACE_VERSION_PATCH_STR "2"
|
||||
|
||||
#endif //HYPERFACEREPO_INFORMATION_H
|
||||
|
||||
@@ -643,14 +643,13 @@ inline cv::Rect GetNewBox(int src_w, int src_h, cv::Rect bbox, float scale) {
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline bool isShortestSideGreaterThan(const cv::Rect_<T>& rect, T value) {
|
||||
inline bool isShortestSideGreaterThan(const cv::Rect_<T>& rect, T value, float scale) {
|
||||
// Find the shortest edge
|
||||
T shortestSide = std::min(rect.width, rect.height);
|
||||
T shortestSide = std::min(rect.width / scale, rect.height / scale);
|
||||
// Determines whether the shortest edge is greater than the given value
|
||||
return shortestSide > value;
|
||||
}
|
||||
|
||||
|
||||
} // namespace inspire
|
||||
|
||||
#endif
|
||||
|
||||
@@ -342,7 +342,7 @@ void FaceTrack::DetectFace(const cv::Mat &input, float scale) {
|
||||
Object obj;
|
||||
const auto box = boxes[i];
|
||||
obj.rect = Rect_<float>(box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
|
||||
if (!isShortestSideGreaterThan<float>(obj.rect, filter_minimum_face_px_size)) {
|
||||
if (!isShortestSideGreaterThan<float>(obj.rect, filter_minimum_face_px_size, scale)) {
|
||||
// Filter too small face detection box
|
||||
continue;
|
||||
}
|
||||
@@ -364,8 +364,8 @@ void FaceTrack::DetectFace(const cv::Mat &input, float scale) {
|
||||
for (int i = 0; i < boxes.size(); i++) {
|
||||
bbox[i] = cv::Rect(cv::Point(static_cast<int>(boxes[i].x1), static_cast<int>(boxes[i].y1)),
|
||||
cv::Point(static_cast<int>(boxes[i].x2), static_cast<int>(boxes[i].y2)));
|
||||
|
||||
if (!isShortestSideGreaterThan<float>(bbox[i], filter_minimum_face_px_size)) {
|
||||
|
||||
if (!isShortestSideGreaterThan<float>(bbox[i], filter_minimum_face_px_size, scale)) {
|
||||
// Filter too small face detection box
|
||||
continue;
|
||||
}
|
||||
@@ -378,16 +378,14 @@ void FaceTrack::DetectFace(const cv::Mat &input, float scale) {
|
||||
|
||||
FaceObject faceinfo(tracking_idx_, bbox[i], FaceLandmark::NUM_OF_LANDMARK);
|
||||
faceinfo.detect_bbox_ = bbox[i];
|
||||
|
||||
|
||||
// Control that the number of faces detected does not exceed the maximum limit
|
||||
if (candidate_faces_.size() < max_detected_faces_) {
|
||||
candidate_faces_.push_back(faceinfo);
|
||||
} else {
|
||||
// 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
|
||||
// For example, face confidence can be compared and faces with lower confidence can be discarded
|
||||
// Take the example of simply discarding the last face
|
||||
candidate_faces_.pop_back();
|
||||
if (candidate_faces_.size() >= max_detected_faces_)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
candidate_faces_.push_back(faceinfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,9 +394,10 @@ void FaceTrack::DetectFace(const cv::Mat &input, float scale) {
|
||||
int FaceTrack::Configuration(inspire::InspireArchive &archive) {
|
||||
// Initialize the detection model
|
||||
InspireModel detModel;
|
||||
auto ret = archive.LoadModel("face_detect", detModel);
|
||||
auto scheme = ChoiceMultiLevelDetectModel(m_dynamic_detection_input_level_);
|
||||
auto ret = archive.LoadModel(scheme, detModel);
|
||||
if (ret != SARC_SUCCESS) {
|
||||
INSPIRE_LOGE("Load %s error: %d", "face_detect", ret);
|
||||
INSPIRE_LOGE("Load %s error: %d", "face_detect_320", ret);
|
||||
return HERR_ARCHIVE_LOAD_MODEL_FAILURE;
|
||||
}
|
||||
InitDetectModel(detModel);
|
||||
@@ -444,21 +443,9 @@ int FaceTrack::InitLandmarkModel(InspireModel &model) {
|
||||
|
||||
int FaceTrack::InitDetectModel(InspireModel &model) {
|
||||
std::vector<int> input_size;
|
||||
if (m_dynamic_detection_input_level_ != -1) {
|
||||
if (m_dynamic_detection_input_level_ % 160 != 0 || m_dynamic_detection_input_level_ < 160) {
|
||||
INSPIRE_LOGE("The input size '%d' for the custom detector is not valid. \
|
||||
Please use a multiple of 160 (minimum 160) for the input dimensions, such as 320 or 640.", m_dynamic_detection_input_level_);
|
||||
return HERR_INVALID_DETECTION_INPUT;
|
||||
}
|
||||
// Wide-Range mode temporary value
|
||||
input_size = {m_dynamic_detection_input_level_, m_dynamic_detection_input_level_};
|
||||
model.Config().set<std::vector<int>>("input_size", input_size);
|
||||
} else {
|
||||
input_size = model.Config().get<std::vector<int>>("input_size");
|
||||
}
|
||||
bool dym = true;
|
||||
input_size = model.Config().get<std::vector<int>>("input_size");
|
||||
m_face_detector_ = std::make_shared<FaceDetect>(input_size[0]);
|
||||
auto ret = m_face_detector_->loadData(model, model.modelType, dym);
|
||||
auto ret = m_face_detector_->loadData(model, model.modelType, false);
|
||||
if (ret != InferenceHelper::kRetOk) {
|
||||
return HERR_ARCHIVE_LOAD_FAILURE;
|
||||
}
|
||||
@@ -499,5 +486,41 @@ void FaceTrack::SetTrackPreviewSize(int preview_size) {
|
||||
track_preview_size_ = preview_size;
|
||||
}
|
||||
|
||||
std::string FaceTrack::ChoiceMultiLevelDetectModel(const int32_t pixel_size) {
|
||||
const int32_t supported_sizes[] = {160, 320, 640};
|
||||
const std::string scheme_names[] = {"face_detect_160", "face_detect_320", "face_detect_640"};
|
||||
const int32_t num_sizes = sizeof(supported_sizes) / sizeof(supported_sizes[0]);
|
||||
|
||||
if (pixel_size == -1)
|
||||
{
|
||||
return scheme_names[1];
|
||||
}
|
||||
|
||||
// Check for exact match
|
||||
for (int i = 0; i < num_sizes; ++i) {
|
||||
if (pixel_size == supported_sizes[i]) {
|
||||
return scheme_names[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Find the closest match
|
||||
int32_t closest_size = supported_sizes[0];
|
||||
std::string closest_scheme = scheme_names[0];
|
||||
int32_t min_diff = std::abs(pixel_size - supported_sizes[0]);
|
||||
|
||||
for (int i = 1; i < num_sizes; ++i) {
|
||||
int32_t diff = std::abs(pixel_size - supported_sizes[i]);
|
||||
if (diff < min_diff) {
|
||||
min_diff = diff;
|
||||
closest_size = supported_sizes[i];
|
||||
closest_scheme = scheme_names[i];
|
||||
}
|
||||
}
|
||||
|
||||
INSPIRE_LOGW("Input pixel size %d is not supported. Choosing the closest scheme: %s closest_scheme for size %d.",
|
||||
pixel_size, closest_scheme.c_str(), closest_size);
|
||||
|
||||
return closest_scheme;
|
||||
}
|
||||
|
||||
} // namespace hyper
|
||||
|
||||
@@ -138,6 +138,13 @@ private:
|
||||
*/
|
||||
int InitFacePoseModel(InspireModel& model);
|
||||
|
||||
/**
|
||||
* @brief Select the detection model scheme to be used according to the input pixel level.
|
||||
* @param pixel_size Currently, only 160, 320, and 640 pixel sizes are supported.
|
||||
* @return Return the corresponding scheme name, only ”face_detect_160”, ”face_detect_320”, ”face_detect_640” are supported.
|
||||
*/
|
||||
std::string ChoiceMultiLevelDetectModel(const int32_t pixel_size);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
||||
@@ -1 +1 @@
|
||||
InspireFace Version: 1.1.1
|
||||
InspireFace Version: 1.1.2
|
||||
|
||||
@@ -6,7 +6,7 @@ option(ISF_BUILD_SAMPLE_CLUTTERED "Whether to compile the cluttered sample progr
|
||||
include_directories(${SRC_DIR})
|
||||
|
||||
if (ISF_ENABLE_RKNN)
|
||||
set(ISF_RKNN_API_LIB ${ISF_THIRD_PARTY_DIR}/${ISF_RKNPU_MAJOR}/runtime/${ISF_RK_DEVICE_TYPE}/Linux/librknn_api/${CPU_ARCH}/)
|
||||
set(ISF_RKNN_API_LIB ${ISF_THIRD_PARTY_DIR}/inspireface-precompile/rknn/${ISF_RKNPU_MAJOR}/runtime/${ISF_RK_DEVICE_TYPE}/Linux/librknn_api/${CPU_ARCH}/)
|
||||
link_directories(${ISF_RKNN_API_LIB})
|
||||
set(ext rknn_api dl)
|
||||
endif ()
|
||||
@@ -38,12 +38,16 @@ set_target_properties(MTFaceTrackSample PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/sample/"
|
||||
)
|
||||
|
||||
# Examples of face detection and tracking
|
||||
add_executable(FaceTrackVideoSample cpp/sample_face_track_video.cpp)
|
||||
target_link_libraries(FaceTrackVideoSample InspireFace ${ext})
|
||||
set_target_properties(FaceTrackVideoSample PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/sample/"
|
||||
)
|
||||
if(NOT DISABLE_GUI)
|
||||
# Examples of face detection and tracking
|
||||
add_executable(FaceTrackVideoSample cpp/sample_face_track_video.cpp)
|
||||
target_link_libraries(FaceTrackVideoSample InspireFace ${ext})
|
||||
set_target_properties(FaceTrackVideoSample PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/sample/"
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
# Examples of face recognition
|
||||
add_executable(FaceRecognitionSample cpp/sample_face_recognition.cpp)
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <opencv2/core/types.hpp>
|
||||
#ifndef DISABLE_GUI
|
||||
#include <opencv2/highgui.hpp>
|
||||
#endif
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <vector>
|
||||
#include "data_type.h"
|
||||
@@ -38,10 +40,10 @@ int main() {
|
||||
auto &item = results[i];
|
||||
cv::rectangle(img, cv::Point2f(item.x1, item.y1), cv::Point2f(item.x2, item.y2), cv::Scalar(0, 0, 255), 4);
|
||||
}
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
cv::imshow("w", img);
|
||||
cv::waitKey(0);
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -31,9 +31,9 @@ int main(int argc, char* argv[]) {
|
||||
// Non-video or frame sequence mode uses IMAGE-MODE, which is always face detection without tracking
|
||||
HFDetectMode detMode = HF_DETECT_MODE_ALWAYS_DETECT;
|
||||
// Maximum number of faces detected
|
||||
HInt32 maxDetectNum = 5;
|
||||
HInt32 maxDetectNum = 20;
|
||||
// Face detection image input level
|
||||
HInt32 detectPixelLevel = 640;
|
||||
HInt32 detectPixelLevel = 160;
|
||||
// Handle of the current face SDK algorithm context
|
||||
HFSession session = {0};
|
||||
ret = HFCreateInspireFaceSessionOptional(option, detMode, maxDetectNum, detectPixelLevel, -1, &session);
|
||||
@@ -42,7 +42,7 @@ int main(int argc, char* argv[]) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
HFSessionSetTrackPreviewSize(session, 640);
|
||||
HFSessionSetTrackPreviewSize(session, detectPixelLevel);
|
||||
HFSessionSetFilterMinimumFacePixelSize(session, 32);
|
||||
|
||||
// Load a image
|
||||
|
||||
@@ -29,12 +29,12 @@ int main(int argc, char* argv[]) {
|
||||
// Enable the functions in the pipeline: mask detection, live detection, and face quality detection
|
||||
HOption option = HF_ENABLE_QUALITY | HF_ENABLE_MASK_DETECT | HF_ENABLE_LIVENESS;
|
||||
// Non-video or frame sequence mode uses IMAGE-MODE, which is always face detection without tracking
|
||||
HFDetectMode detMode = HF_DETECT_MODE_LIGHT_TRACK;
|
||||
HFDetectMode detMode = HF_DETECT_MODE_ALWAYS_DETECT;
|
||||
// Maximum number of faces detected
|
||||
HInt32 maxDetectNum = 50;
|
||||
// Handle of the current face SDK algorithm context
|
||||
HFSession session = {0};
|
||||
ret = HFCreateInspireFaceSessionOptional(option, detMode, maxDetectNum, -1, -1, &session);
|
||||
ret = HFCreateInspireFaceSessionOptional(option, detMode, maxDetectNum, 160, -1, &session);
|
||||
if (ret != HSUCCEED) {
|
||||
std::cout << "Create FaceContext error: " << ret << std::endl;
|
||||
return ret;
|
||||
|
||||
@@ -48,9 +48,9 @@ int main(int argc, char* argv[]) {
|
||||
// Video or frame sequence mode uses VIDEO-MODE, which is face detection with tracking
|
||||
HFDetectMode detMode = HF_DETECT_MODE_TRACK_BY_DETECTION;
|
||||
// Maximum number of faces detected
|
||||
HInt32 maxDetectNum = 5;
|
||||
HInt32 maxDetectNum = 20;
|
||||
// Face detection image input level
|
||||
HInt32 detectPixelLevel = 640;
|
||||
HInt32 detectPixelLevel = 320;
|
||||
// fps in tracking-by-detection mode
|
||||
HInt32 trackByDetectFps = 20;
|
||||
HFSession session = {0};
|
||||
@@ -61,8 +61,8 @@ int main(int argc, char* argv[]) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
HFSessionSetTrackPreviewSize(session, 640);
|
||||
HFSessionSetFilterMinimumFacePixelSize(session, 32);
|
||||
HFSessionSetTrackPreviewSize(session, detectPixelLevel);
|
||||
HFSessionSetFilterMinimumFacePixelSize(session, 0);
|
||||
|
||||
// Open the video file
|
||||
cv::VideoCapture cap(videoPath);
|
||||
|
||||
@@ -20,7 +20,7 @@ endif ()
|
||||
|
||||
if (ISF_ENABLE_RKNN)
|
||||
set(DEPEND rknn_api dl)
|
||||
set(ISF_RKNN_API_LIB ${ISF_THIRD_PARTY_DIR}/${ISF_RKNPU_MAJOR}/runtime/${ISF_RK_DEVICE_TYPE}/Linux/librknn_api/${CPU_ARCH}/)
|
||||
set(ISF_RKNN_API_LIB ${ISF_THIRD_PARTY_DIR}/inspireface-precompile/rknn/${ISF_RKNPU_MAJOR}/runtime/${ISF_RK_DEVICE_TYPE}/Linux/librknn_api/${CPU_ARCH}/)
|
||||
message("Enable RKNN Inference")
|
||||
link_directories(${ISF_RKNN_API_LIB})
|
||||
set(DEPEND rknn_api dl)
|
||||
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
void operator=(Enviro const&) = delete;
|
||||
|
||||
std::string getPackName() const { return packName; }
|
||||
|
||||
void setPackName(const std::string& name) { packName = name; }
|
||||
|
||||
const std::string &getTestResDir() const { return testResDir; }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Created by tunm on 2023/10/11.
|
||||
//
|
||||
#include <string>
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
|
||||
#include <iostream>
|
||||
@@ -54,11 +55,13 @@ int main(int argc, char* argv[]) {
|
||||
// Pack file name and test directory
|
||||
std::string pack;
|
||||
std::string testDir;
|
||||
std::string packPath;
|
||||
|
||||
// Add command line options
|
||||
auto cli = session.cli()
|
||||
| Catch::clara::Opt(pack, "value")["--pack"]("Resource pack filename")
|
||||
| Catch::clara::Opt(testDir, "value")["--test_dir"]("Test dir resource");
|
||||
| Catch::clara::Opt(testDir, "value")["--test_dir"]("Test dir resource")
|
||||
| Catch::clara::Opt(packPath, "value")["--pack_path"]("The specified path to the pack file");
|
||||
|
||||
// Set combined CLI to the session
|
||||
session.cli(cli);
|
||||
@@ -75,15 +78,22 @@ int main(int argc, char* argv[]) {
|
||||
TEST_PRINT("Using default test dir: {}", getTestDataDir());
|
||||
}
|
||||
|
||||
std::string fullPath;
|
||||
// Check whether custom parameters are set
|
||||
if (!pack.empty()) {
|
||||
SET_PACK_NAME(pack);
|
||||
fullPath = GET_MODEL_FILE();
|
||||
TEST_PRINT("Updated global Pack to: {}", TEST_MODEL_FILE);
|
||||
} else if (!packPath.empty()) {
|
||||
fullPath = packPath;
|
||||
TEST_PRINT("Updated global Pack File to: {}", packPath);
|
||||
} else {
|
||||
fullPath = GET_MODEL_FILE();
|
||||
TEST_PRINT("Using default global Pack: {}", TEST_MODEL_FILE);
|
||||
}
|
||||
|
||||
auto ret = HFLaunchInspireFace(GET_MODEL_FILE().c_str());
|
||||
std::cout << fullPath << std::endl;
|
||||
auto ret = HFLaunchInspireFace(fullPath.c_str());
|
||||
if (ret != HSUCCEED) {
|
||||
spdlog::error("An error occurred while starting InspireFace: {}", ret);
|
||||
return ret;
|
||||
|
||||
@@ -21,7 +21,6 @@ TEST_CASE("test_FaceTrack", "[face_track]") {
|
||||
HFDetectMode detMode = HF_DETECT_MODE_ALWAYS_DETECT;
|
||||
HFSession session;
|
||||
ret = HFCreateInspireFaceSession(parameter, detMode, 3, -1, -1, &session);
|
||||
spdlog::error("error ret :{}", ret);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
// Get a face picture
|
||||
@@ -49,7 +48,7 @@ TEST_CASE("test_FaceTrack", "[face_track]") {
|
||||
cv::rectangle(image, cvRect, cv::Scalar(255, 0, 124), 2);
|
||||
cv::imwrite("ww.jpg", image);
|
||||
// The iou is allowed to have an error of 10%
|
||||
CHECK(iou == Approx(1.0f).epsilon(0.1));
|
||||
CHECK(iou == Approx(1.0f).epsilon(0.3));
|
||||
|
||||
ret = HFReleaseImageStream(imgHandle);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
@@ -224,14 +223,15 @@ TEST_CASE("test_FaceTrack", "[face_track]") {
|
||||
|
||||
}
|
||||
|
||||
SECTION("Face detection benchmark") {
|
||||
#ifdef ISF_ENABLE_BENCHMARK
|
||||
SECTION("Face detection benchmark@160") {
|
||||
int loop = 1000;
|
||||
HResult ret;
|
||||
HFSessionCustomParameter parameter = {0};
|
||||
HFDetectMode detMode = HF_DETECT_MODE_ALWAYS_DETECT;
|
||||
HFSession session;
|
||||
ret = HFCreateInspireFaceSession(parameter, detMode, 3, -1, -1, &session);
|
||||
HInt32 pixLevel = 160;
|
||||
ret = HFCreateInspireFaceSession(parameter, detMode, 3, pixLevel, -1, &session);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
// Prepare an image
|
||||
@@ -250,19 +250,95 @@ TEST_CASE("test_FaceTrack", "[face_track]") {
|
||||
auto cost = ((double) cv::getTickCount() - start) / cv::getTickFrequency() * 1000;
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
REQUIRE(multipleFaceData.detectedNum == 1);
|
||||
TEST_PRINT("<Benchmark> Face Detect -> Loop: {}, Total Time: {:.5f}ms, Average Time: {:.5f}ms", loop, cost, cost / loop);
|
||||
record.insertBenchmarkData("Face Detect", loop, cost, cost / loop);
|
||||
TEST_PRINT("<Benchmark> Face Detect@160 -> Loop: {}, Total Time: {:.5f}ms, Average Time: {:.5f}ms", loop, cost, cost / loop);
|
||||
record.insertBenchmarkData("Face Detect@160", loop, cost, cost / loop);
|
||||
|
||||
ret = HFReleaseImageStream(imgHandle);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
ret = HFReleaseInspireFaceSession(session);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
#else
|
||||
TEST_PRINT("Skip the face detection benchmark test. To run it, you need to turn on the benchmark test.");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
SECTION("Face detection benchmark@320") {
|
||||
int loop = 1000;
|
||||
HResult ret;
|
||||
HFSessionCustomParameter parameter = {0};
|
||||
HFDetectMode detMode = HF_DETECT_MODE_ALWAYS_DETECT;
|
||||
HFSession session;
|
||||
HInt32 pixLevel = 320;
|
||||
ret = HFCreateInspireFaceSession(parameter, detMode, 3, pixLevel, -1, &session);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
// Prepare an image
|
||||
HFImageStream imgHandle;
|
||||
auto image = cv::imread(GET_DATA("data/bulk/kun.jpg"));
|
||||
ret = CVImageToImageStream(image, imgHandle);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
BenchmarkRecord record(getBenchmarkRecordFile());
|
||||
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
HFMultipleFaceData multipleFaceData = {0};
|
||||
auto start = (double) cv::getTickCount();
|
||||
for (int i = 0; i < loop; ++i) {
|
||||
ret = HFExecuteFaceTrack(session, imgHandle, &multipleFaceData);
|
||||
}
|
||||
auto cost = ((double) cv::getTickCount() - start) / cv::getTickFrequency() * 1000;
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
REQUIRE(multipleFaceData.detectedNum == 1);
|
||||
TEST_PRINT("<Benchmark> Face Detect@320 -> Loop: {}, Total Time: {:.5f}ms, Average Time: {:.5f}ms", loop, cost, cost / loop);
|
||||
record.insertBenchmarkData("Face Detect@320", loop, cost, cost / loop);
|
||||
|
||||
ret = HFReleaseImageStream(imgHandle);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
ret = HFReleaseInspireFaceSession(session);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
}
|
||||
|
||||
|
||||
SECTION("Face detection benchmark@640") {
|
||||
int loop = 1000;
|
||||
HResult ret;
|
||||
HFSessionCustomParameter parameter = {0};
|
||||
HFDetectMode detMode = HF_DETECT_MODE_ALWAYS_DETECT;
|
||||
HFSession session;
|
||||
HInt32 pixLevel = 640;
|
||||
ret = HFCreateInspireFaceSession(parameter, detMode, 3, pixLevel, -1, &session);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
// Prepare an image
|
||||
HFImageStream imgHandle;
|
||||
auto image = cv::imread(GET_DATA("data/bulk/kun.jpg"));
|
||||
ret = CVImageToImageStream(image, imgHandle);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
BenchmarkRecord record(getBenchmarkRecordFile());
|
||||
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
HFMultipleFaceData multipleFaceData = {0};
|
||||
auto start = (double) cv::getTickCount();
|
||||
for (int i = 0; i < loop; ++i) {
|
||||
ret = HFExecuteFaceTrack(session, imgHandle, &multipleFaceData);
|
||||
}
|
||||
auto cost = ((double) cv::getTickCount() - start) / cv::getTickFrequency() * 1000;
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
REQUIRE(multipleFaceData.detectedNum == 1);
|
||||
TEST_PRINT("<Benchmark> Face Detect@640 -> Loop: {}, Total Time: {:.5f}ms, Average Time: {:.5f}ms", loop, cost, cost / loop);
|
||||
record.insertBenchmarkData("Face Detect@640", loop, cost, cost / loop);
|
||||
|
||||
ret = HFReleaseImageStream(imgHandle);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
ret = HFReleaseInspireFaceSession(session);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
}
|
||||
#else
|
||||
TEST_PRINT("Skip the face detection benchmark test. To run it, you need to turn on the benchmark test.");
|
||||
#endif
|
||||
|
||||
SECTION("Face light track benchmark") {
|
||||
#ifdef ISF_ENABLE_BENCHMARK
|
||||
int loop = 1000;
|
||||
@@ -289,7 +365,7 @@ TEST_CASE("test_FaceTrack", "[face_track]") {
|
||||
}
|
||||
auto cost = ((double) cv::getTickCount() - start) / cv::getTickFrequency() * 1000;
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
REQUIRE(multipleFaceData.detectedNum == 1);
|
||||
REQUIRE(multipleFaceData.detectedNum > 0);
|
||||
TEST_PRINT("<Benchmark> Face Track -> Loop: {}, Total Time: {:.5f}ms, Average Time: {:.5f}ms", loop, cost, cost / loop);
|
||||
record.insertBenchmarkData("Face Track", loop, cost, cost / loop);
|
||||
|
||||
@@ -304,4 +380,107 @@ TEST_CASE("test_FaceTrack", "[face_track]") {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("test_MultipleLevelFaceDetect", "[face_detect]") {
|
||||
DRAW_SPLIT_LINE
|
||||
TEST_PRINT_OUTPUT(true);
|
||||
|
||||
SECTION("Detect input 160px") {
|
||||
HResult ret;
|
||||
HFSessionCustomParameter parameter = {0};
|
||||
HFDetectMode detMode = HF_DETECT_MODE_ALWAYS_DETECT;
|
||||
HFSession session;
|
||||
HInt32 detectPixelLevel = 160;
|
||||
ret = HFCreateInspireFaceSession(parameter, detMode, 20, detectPixelLevel, -1, &session);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
HFSessionSetTrackPreviewSize(session, detectPixelLevel);
|
||||
HFSessionSetFilterMinimumFacePixelSize(session, 0);
|
||||
|
||||
// Get a face picture
|
||||
HFImageStream imgHandle;
|
||||
auto image = cv::imread(GET_DATA("data/bulk/pedestrian.png"));
|
||||
ret = CVImageToImageStream(image, imgHandle);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
// Extract basic face information from photos
|
||||
HFMultipleFaceData multipleFaceData = {0};
|
||||
ret = HFExecuteFaceTrack(session, imgHandle, &multipleFaceData);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
CHECK(multipleFaceData.detectedNum > 0);
|
||||
CHECK(multipleFaceData.detectedNum < 7);
|
||||
|
||||
ret = HFReleaseImageStream(imgHandle);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
ret = HFReleaseInspireFaceSession(session);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
}
|
||||
|
||||
SECTION("Detect input 320px") {
|
||||
HResult ret;
|
||||
HFSessionCustomParameter parameter = {0};
|
||||
HFDetectMode detMode = HF_DETECT_MODE_ALWAYS_DETECT;
|
||||
HFSession session;
|
||||
HInt32 detectPixelLevel = 320;
|
||||
ret = HFCreateInspireFaceSession(parameter, detMode, 20, detectPixelLevel, -1, &session);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
HFSessionSetTrackPreviewSize(session, detectPixelLevel);
|
||||
HFSessionSetFilterMinimumFacePixelSize(session, 0);
|
||||
|
||||
// Get a face picture
|
||||
HFImageStream imgHandle;
|
||||
auto image = cv::imread(GET_DATA("data/bulk/pedestrian.png"));
|
||||
ret = CVImageToImageStream(image, imgHandle);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
// Extract basic face information from photos
|
||||
HFMultipleFaceData multipleFaceData = {0};
|
||||
ret = HFExecuteFaceTrack(session, imgHandle, &multipleFaceData);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
CHECK(multipleFaceData.detectedNum > 9);
|
||||
CHECK(multipleFaceData.detectedNum < 15);
|
||||
|
||||
ret = HFReleaseImageStream(imgHandle);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
ret = HFReleaseInspireFaceSession(session);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
}
|
||||
|
||||
SECTION("Detect input 640px") {
|
||||
HResult ret;
|
||||
HFSessionCustomParameter parameter = {0};
|
||||
HFDetectMode detMode = HF_DETECT_MODE_ALWAYS_DETECT;
|
||||
HFSession session;
|
||||
HInt32 detectPixelLevel = 640;
|
||||
ret = HFCreateInspireFaceSession(parameter, detMode, 25, detectPixelLevel, -1, &session);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
HFSessionSetTrackPreviewSize(session, detectPixelLevel);
|
||||
HFSessionSetFilterMinimumFacePixelSize(session, 0);
|
||||
|
||||
// Get a face picture
|
||||
HFImageStream imgHandle;
|
||||
auto image = cv::imread(GET_DATA("data/bulk/pedestrian.png"));
|
||||
ret = CVImageToImageStream(image, imgHandle);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
// Extract basic face information from photos
|
||||
HFMultipleFaceData multipleFaceData = {0};
|
||||
ret = HFExecuteFaceTrack(session, imgHandle, &multipleFaceData);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
CHECK(multipleFaceData.detectedNum > 15);
|
||||
CHECK(multipleFaceData.detectedNum < 25);
|
||||
|
||||
ret = HFReleaseImageStream(imgHandle);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
|
||||
ret = HFReleaseInspireFaceSession(session);
|
||||
REQUIRE(ret == HSUCCEED);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -335,7 +335,7 @@ TEST_CASE("test_SearchTopK", "[feature_search_top_k]") {
|
||||
configuration.dbPath = dbPathStr;
|
||||
configuration.featureBlockNum = 20;
|
||||
configuration.searchMode = HF_SEARCH_MODE_EXHAUSTIVE;
|
||||
configuration.searchThreshold = 0.48f;
|
||||
configuration.searchThreshold = 0.46f;
|
||||
// Delete the previous data before testing
|
||||
if (std::remove(configuration.dbPath) != 0) {
|
||||
spdlog::trace("Error deleting file");
|
||||
|
||||
Reference in New Issue
Block a user