Fix mutex lock issues
This commit is contained in:
@@ -1372,6 +1372,7 @@ namespace ANSCENTER {
|
||||
}
|
||||
bool ANSONNXOBB::Initialize(std::string licenseKey, ModelConfig modelConfig, const std::string& modelZipFilePath, const std::string& modelZipPassword, std::string& labelMap) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
ModelLoadingGuard mlg(_modelLoading);
|
||||
try {
|
||||
_modelLoadValid = false;
|
||||
bool result = ANSODBase::Initialize(licenseKey, modelConfig, modelZipFilePath, modelZipPassword, labelMap);
|
||||
@@ -1433,6 +1434,7 @@ namespace ANSCENTER {
|
||||
}
|
||||
bool ANSONNXOBB::LoadModel(const std::string& modelZipFilePath, const std::string& modelZipPassword) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
ModelLoadingGuard mlg(_modelLoading);
|
||||
try {
|
||||
bool result = ANSODBase::LoadModel(modelZipFilePath, modelZipPassword);
|
||||
if (!result) return false;
|
||||
@@ -1488,6 +1490,7 @@ namespace ANSCENTER {
|
||||
}
|
||||
bool ANSONNXOBB::LoadModelFromFolder(std::string licenseKey, ModelConfig modelConfig, std::string modelName, std::string className, const std::string& modelFolder, std::string& labelMap) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
ModelLoadingGuard mlg(_modelLoading);
|
||||
try {
|
||||
bool result = ANSODBase::LoadModelFromFolder(licenseKey, modelConfig, modelName, className, modelFolder, labelMap);
|
||||
if (!result) return false;
|
||||
@@ -1551,25 +1554,7 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
std::vector<Object> ANSONNXOBB::RunInference(const cv::Mat& input, const std::string& camera_id) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
if (!_modelLoadValid) {
|
||||
this->_logger.LogFatal("ANSONNXOBB::RunInference", "Cannot load the TensorRT model. Please check if it is exist", __FILE__, __LINE__);
|
||||
std::vector<Object> result;
|
||||
result.clear();
|
||||
return result;
|
||||
}
|
||||
if (!_licenseValid) {
|
||||
this->_logger.LogFatal("ANSONNXOBB::RunInference", "Runtime license is not valid or expired. Please contact ANSCENTER", __FILE__, __LINE__);
|
||||
std::vector<Object> result;
|
||||
result.clear();
|
||||
return result;
|
||||
}
|
||||
if (!_isInitialized) {
|
||||
this->_logger.LogFatal("ANSONNXOBB::RunInference", "Model is not initialized", __FILE__, __LINE__);
|
||||
std::vector<Object> result;
|
||||
result.clear();
|
||||
return result;
|
||||
}
|
||||
if (!PreInferenceCheck("ANSONNXOBB::RunInference")) return {};
|
||||
try {
|
||||
std::vector<Object> result;
|
||||
if (input.empty()) return result;
|
||||
|
||||
Reference in New Issue
Block a user