Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace ML{


SAMEmbedderSession::SAMEmbedderSession(const std::string& model_path, bool use_gpu)
: m_session_options{create_session_options(ML_MODEL_CACHE_PATH() + "SAMEmbedder/", use_gpu)}
: m_env{create_ORT_env()}
, m_session_options{create_session_options(ML_MODEL_CACHE_PATH() + "SAMEmbedder/", use_gpu)}
, session{create_session(m_env, m_session_options, model_path, ML_MODEL_CACHE_PATH() + "SAMEmbedder/")}
, memory_info{Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU)}
, input_names{session.GetInputNames()}
Expand Down Expand Up @@ -65,7 +66,8 @@ void SAMEmbedderSession::run(cv::Mat& input_image, std::vector<float>& model_out


SAMSession::SAMSession(const std::string& model_path, bool use_gpu)
: m_session_options{create_session_options(ML_MODEL_CACHE_PATH() + "SAM/", use_gpu)}
: m_env{create_ORT_env()}
, m_session_options{create_session_options(ML_MODEL_CACHE_PATH() + "SAM/", use_gpu)}
, session{create_session(m_env, m_session_options, model_path, ML_MODEL_CACHE_PATH() + "SAM/")}
, memory_info{Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU)}
, input_names{session.GetInputNames()}
Expand Down
9 changes: 9 additions & 0 deletions SerialPrograms/Source/ML/Models/ML_ONNXRuntimeHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <fstream>
#include <onnxruntime_cxx_api.h>
#include "3rdParty/ONNX/OnnxToolsPA.h"
#include "Common/Cpp/Exceptions.h"
#include "Common/Compiler.h"
#include "ML_ONNXRuntimeHelpers.h"

Expand Down Expand Up @@ -194,5 +195,13 @@ void print_model_input_output_info(const Ort::Session& session){
}
}

Ort::Env create_ORT_env(){
if (Ort::Global<void>::api_ == nullptr){
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Onnx API returned a null pointer.");
}

return Ort::Env();
}

}
}
2 changes: 2 additions & 0 deletions SerialPrograms/Source/ML/Models/ML_ONNXRuntimeHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ std::string to_string(std::vector<T>& vec){
// Print model input and output types and shapes to cout. Useful for debugging.
void print_model_input_output_info(const Ort::Session& session);

Ort::Env create_ORT_env();


}
}
Expand Down
1 change: 1 addition & 0 deletions SerialPrograms/Source/ML/Models/ML_YOLOv5Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ std::tuple<int, int, double, double> resize_image_with_border(

YOLOv5Session::YOLOv5Session(const std::string& model_path, std::vector<std::string> label_names, bool use_gpu)
: m_label_names(std::move(label_names))
, m_env{create_ORT_env()}
, m_session_options(create_session_options(ML_MODEL_CACHE_PATH() + "YOLOv5", use_gpu))
, m_session{create_session(m_env, m_session_options, model_path, ML_MODEL_CACHE_PATH() + "YOLOv5")}
, m_memory_info{Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU)}
Expand Down
Loading