Fix mutex lock issues
This commit is contained in:
@@ -1153,6 +1153,7 @@ namespace ANSCENTER {
|
||||
}
|
||||
bool ANSONNXSEG::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);
|
||||
@@ -1215,6 +1216,7 @@ namespace ANSCENTER {
|
||||
}
|
||||
bool ANSONNXSEG::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;
|
||||
@@ -1271,6 +1273,7 @@ namespace ANSCENTER {
|
||||
}
|
||||
bool ANSONNXSEG::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;
|
||||
@@ -1335,25 +1338,7 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
std::vector<Object> ANSONNXSEG::RunInference(const cv::Mat& input, const std::string& camera_id) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
if (!_modelLoadValid) {
|
||||
this->_logger.LogFatal("ANSONNXSEG::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("ANSONNXSEG::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("ANSONNXSEG::RunInference", "Model is not initialized", __FILE__, __LINE__);
|
||||
std::vector<Object> result;
|
||||
result.clear();
|
||||
return result;
|
||||
}
|
||||
if (!PreInferenceCheck("ANSONNXSEG::RunInference")) return {};
|
||||
try {
|
||||
std::vector<Object> result;
|
||||
if (input.empty()) return result;
|
||||
|
||||
Reference in New Issue
Block a user