Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add track cost time #153

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cpp/inspireface/c_api/inspireface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,30 @@ HResult HFGetFaceFiveKeyPointsFromFaceToken(HFFaceBasicToken singleFace, HPoint2
return HSUCCEED;
}

HResult HFSessionSetEnableTrackCostSpend(HFSession session, bool value) {
if (session == nullptr) {
return HERR_INVALID_CONTEXT_HANDLE;
}
HF_FaceAlgorithmSession *ctx = (HF_FaceAlgorithmSession *)session;
if (ctx == nullptr) {
return HERR_INVALID_CONTEXT_HANDLE;
}
ctx->impl.SetEnableTrackCostSpend(value);
return HSUCCEED;
}

HResult HFSessionPrintTrackCostSpend(HFSession session) {
if (session == nullptr) {
return HERR_INVALID_CONTEXT_HANDLE;
}
HF_FaceAlgorithmSession *ctx = (HF_FaceAlgorithmSession *)session;
if (ctx == nullptr) {
return HERR_INVALID_CONTEXT_HANDLE;
}
ctx->impl.PrintTrackCostSpend();
return HSUCCEED;
}

HResult HFFeatureHubFaceSearchThresholdSetting(float threshold) {
FEATURE_HUB_DB->SetRecognitionThreshold(threshold);
return HSUCCEED;
Expand Down
14 changes: 14 additions & 0 deletions cpp/inspireface/c_api/inspireface.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,20 @@ HYPER_CAPI_EXPORT extern HResult HFGetFaceDenseLandmarkFromFaceToken(HFFaceBasic
*/
HYPER_CAPI_EXPORT extern HResult HFGetFaceFiveKeyPointsFromFaceToken(HFFaceBasicToken singleFace, HPoint2f *landmarks, HInt32 num);

/**
* @brief Set the enable cost spend
* @param value The enable cost spend value
* @return int32_t Status code of the operation.
* */
HYPER_CAPI_EXPORT extern HResult HFSessionSetEnableTrackCostSpend(HFSession session, bool value);

/**
* @brief Print the cost spend
* @param session The session handle
* @return int32_t Status code of the operation.
* */
HYPER_CAPI_EXPORT extern HResult HFSessionPrintTrackCostSpend(HFSession session);

/************************************************************************
* Face Recognition
************************************************************************/
Expand Down
22 changes: 20 additions & 2 deletions cpp/inspireface/face_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ int32_t FaceSession::Configuration(DetectModuleMode detect_mode, int32_t max_det

m_face_pipeline_ = std::make_shared<FacePipelineModule>(INSPIRE_LAUNCH->getMArchive(), param.enable_liveness, param.enable_mask_detect,
param.enable_face_attribute, param.enable_interaction_liveness);
m_face_track_cost_ = std::make_shared<inspirecv::TimeSpend>("FaceTrack");

return HSUCCEED;
}

int32_t FaceSession::FaceDetectAndTrack(inspirecv::InspireImageProcess& process) {
std::lock_guard<std::mutex> lock(m_mtx_);
if (m_enable_track_cost_spend_) {
m_face_track_cost_->Start();
}
m_detect_cache_.clear();
m_face_basic_data_cache_.clear();
m_face_rects_cache_.clear();
Expand Down Expand Up @@ -107,7 +111,9 @@ int32_t FaceSession::FaceDetectAndTrack(inspirecv::InspireImageProcess& process)
basic.dataSize = m_detect_cache_[i].size();
basic.data = m_detect_cache_[i].data();
}

if (m_enable_track_cost_spend_) {
m_face_track_cost_->Stop();
}
// LOGD("Track COST: %f", m_face_track_->GetTrackTotalUseTime());
return HSUCCEED;
}
Expand Down Expand Up @@ -410,4 +416,16 @@ int32_t FaceSession::SetTrackModeDetectInterval(int value) {
return HSUCCEED;
}

} // namespace inspire
int32_t FaceSession::SetEnableTrackCostSpend(bool value) {
m_enable_track_cost_spend_ = value;
m_face_track_cost_->Reset();
return HSUCCEED;
}

void FaceSession::PrintTrackCostSpend() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PrintTrackCostSpend method should validate the TimeSpend object exists. Add a null check for m_face_track_cost_ before accessing it:

Suggested change
if (m_enable_track_cost_spend_) {
if (m_enable_track_cost_spend_ && m_face_track_cost_) {

if (m_enable_track_cost_spend_) {
INSPIRE_LOGI("%s", m_face_track_cost_->Report().c_str());
}
}

} // namespace inspire
18 changes: 18 additions & 0 deletions cpp/inspireface/face_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define INSPIRE_FACE_CONTEXT_H

#include <memory>
#include <inspirecv/inspirecv.h>
#include "data_type.h"
#include "track_module/face_track_module.h"
#include "pipeline_module/face_pipeline_module.h"
Expand Down Expand Up @@ -334,6 +335,18 @@ class INSPIRE_API FaceSession {
* */
int32_t SetTrackModeDetectInterval(int value);

/**
* @brief Set the enable cost spend
* @param value The enable cost spend value
* @return int32_t Status code of the operation.
* */
int32_t SetEnableTrackCostSpend(bool value);

/**
* @brief Print the cost spend
* */
void PrintTrackCostSpend();

private:
// Private member variables
CustomPipelineParameter m_parameter_; ///< Stores custom parameters for the pipeline
Expand Down Expand Up @@ -375,6 +388,11 @@ class INSPIRE_API FaceSession {
float m_face_feature_norm_; ///< Cache for face feature norm

std::mutex m_mtx_; ///< Mutex for thread safety.

// cost spend
std::shared_ptr<inspirecv::TimeSpend> m_face_track_cost_;

bool m_enable_track_cost_spend_ = false;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a more descriptive name for the member variable. m_enable_track_cost_spend_ could be renamed to m_enable_performance_tracking_ or m_track_perf_enabled_ to better reflect its purpose.

};

} // namespace inspire
Expand Down
Loading
Loading