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
15 changes: 9 additions & 6 deletions SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@ GlobalSettings::GlobalSettings()
"WARNING: If you change the OCR library away from the default (PaddleOCR), you must ensure that you have the necessary resource downloaded. "
"Otherwise, the programs that use OCR will throw an error."
)
, USE_GPU_FOR_ML_INFERENCE(
, USE_GPU_FOR_ML_INFERENCE0(
"<b>Use GPU for Machine learning inference:</b><br>"
"Use the GPU by default for machine learning. Will fall-back to CPU if using the GPU fails.",
"Use the GPU by default for machine learning. Will fall-back to CPU if using the GPU fails.<br>"
"<font color=\"red\">WARNING: DirectML ONNX on Windows is not threadsafe. Using multithreaded PaddleOCR with DirectML will cause a crash with our current infra. "
"Furthermore, with PaddleOCR, DirectML is slower than using the CPU. With other models, such as SAM, DirectML seems to be ~10% "
"faster than the CPU. Cuda has not been tested.</font>",
LockMode::UNLOCK_WHILE_RUNNING,
false
)
Expand Down Expand Up @@ -281,10 +284,10 @@ GlobalSettings::GlobalSettings()
PA_ADD_OPTION(STATS_FILE);
PA_ADD_OPTION(TEMP_FOLDER);
PA_ADD_OPTION(THEME);
PA_ADD_OPTION(USE_GPU_FOR_ML_INFERENCE);
PA_ADD_OPTION(OCR_LIBRARY);

// gated behind Dev mode. see GlobalSettings::load_json
PA_ADD_OPTION(OCR_LIBRARY);
PA_ADD_OPTION(USE_GPU_FOR_ML_INFERENCE0);
// PA_ADD_OPTION(OCR_WARNING); // TODO: enable this when Tesseract is no longer a default resource.
PA_ADD_OPTION(RESOURCE_DOWNLOAD_TABLE);
PA_ADD_OPTION(DOWNLOAD_ERROR);
Expand Down Expand Up @@ -334,7 +337,7 @@ GlobalSettings::GlobalSettings()

PA_ADD_OPTION(DEVELOPER_TOKEN);

OCR_LIBRARY.set_visibility(ConfigOptionState::HIDDEN);
USE_GPU_FOR_ML_INFERENCE0.set_visibility(ConfigOptionState::HIDDEN);
RESOURCE_DOWNLOAD_TABLE.set_visibility(ConfigOptionState::HIDDEN);
DOWNLOAD_ERROR.set_visibility(ConfigOptionState::HIDDEN);
SAVE_DEBUG_VIDEOS_ON_SWITCH.set_visibility(ConfigOptionState::HIDDEN);
Expand All @@ -358,7 +361,7 @@ void GlobalSettings::load_json(const JsonValue& json){
ConfigOptionState devmode_visibility = developer_mode
? ConfigOptionState::ENABLED
: ConfigOptionState::HIDDEN;
OCR_LIBRARY.set_visibility(devmode_visibility);
USE_GPU_FOR_ML_INFERENCE0.set_visibility(devmode_visibility);
RESOURCE_DOWNLOAD_TABLE.set_visibility(devmode_visibility);
DOWNLOAD_ERROR.set_visibility(devmode_visibility);
SAVE_DEBUG_VIDEOS_ON_SWITCH.set_visibility(devmode_visibility);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class GlobalSettings : public BatchOption, private ConfigOption::Listener, priva
Pimpl<ThemeSelectorOption> THEME;
EnumDropdownOption<OcrLibrary> OCR_LIBRARY;
StaticTextOption OCR_WARNING;
BooleanCheckBoxOption USE_GPU_FOR_ML_INFERENCE;
BooleanCheckBoxOption USE_GPU_FOR_ML_INFERENCE0;
SettingsResourceDownloadTable RESOURCE_DOWNLOAD_TABLE;
SettingsDownloadError DOWNLOAD_ERROR;
Pimpl<ResolutionOption> WINDOW_SIZE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ PaddleOCRPipeline::PaddleOCRPipeline(Language language)
PaddleOCRPipeline::PaddleOCRPipeline(Language language, std::string rec_path, std::string dict_path)
: m_env{create_ORT_env()}
// , det_session(env, std::wstring(det_path.begin(), det_path.end()).c_str(), Ort::SessionOptions{})
, m_rec_session(create_session(m_env, rec_path, ML_MODEL_CACHE_PATH() + "PaddleOCRPipeline/", GlobalSettings::instance().USE_GPU_FOR_ML_INFERENCE))
, m_rec_session(create_session(m_env, rec_path, ML_MODEL_CACHE_PATH() + "PaddleOCRPipeline/", GlobalSettings::instance().USE_GPU_FOR_ML_INFERENCE0))
// , memory_info(Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault))
, m_language(language)
, m_input_name(m_rec_session.GetInputNameAllocated(0, Ort::AllocatorWithDefaultOptions{}).get())
Expand Down
2 changes: 1 addition & 1 deletion SerialPrograms/Source/ML/Inference/ML_YOLOv5Detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ YOLOv5Detector::~YOLOv5Detector() = default;

YOLOv5Detector::YOLOv5Detector(const std::string& model_path)
: m_model_path(to_resource_filepath(model_path))
, m_use_gpu(GlobalSettings::instance().USE_GPU_FOR_ML_INFERENCE)
, m_use_gpu(GlobalSettings::instance().USE_GPU_FOR_ML_INFERENCE0)
{
if (!model_path.ends_with(".onnx")){
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION,
Expand Down
6 changes: 3 additions & 3 deletions SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ LabelImages::LabelImages(const LabelImages_Descriptor& descriptor)
: PanelInstance(descriptor)
, m_display_session(m_display_option)
, m_options(LockMode::UNLOCK_WHILE_RUNNING)
, m_use_gpu_for_sam_anno(GlobalSettings::instance().USE_GPU_FOR_ML_INFERENCE)
, m_use_gpu_for_sam_anno(GlobalSettings::instance().USE_GPU_FOR_ML_INFERENCE0)
, X("<b>X Coordinate:</b>", LockMode::UNLOCK_WHILE_RUNNING, 0.3, 0.0, 1.0)
, Y("<b>Y Coordinate:</b>", LockMode::UNLOCK_WHILE_RUNNING, 0.3, 0.0, 1.0)
, WIDTH("<b>Width:</b>", LockMode::UNLOCK_WHILE_RUNNING, 0.4, 0.0, 1.0)
Expand Down Expand Up @@ -135,7 +135,7 @@ LabelImages::LabelImages(const LabelImages_Descriptor& descriptor)



init_sam_session(GlobalSettings::instance().USE_GPU_FOR_ML_INFERENCE);
init_sam_session(GlobalSettings::instance().USE_GPU_FOR_ML_INFERENCE0);

m_overlay_manager = new LabelImages_OverlayManager(*this);
}
Expand Down Expand Up @@ -510,7 +510,7 @@ void LabelImages::remove_segmentation_exclusion_point(double x, double y){
void LabelImages::compute_embeddings_for_folder(const std::string& image_folder_path){
std::string embedding_model_path = RESOURCE_PATH() + "ML/sam_embedder_cpu.onnx";
std::cout << "Use SAM Embedding model " << embedding_model_path << std::endl;
ML::compute_embeddings_for_folder(embedding_model_path, image_folder_path, GlobalSettings::instance().USE_GPU_FOR_ML_INFERENCE);
ML::compute_embeddings_for_folder(embedding_model_path, image_folder_path, GlobalSettings::instance().USE_GPU_FOR_ML_INFERENCE0);
}

void LabelImages::delete_selected_annotation(){
Expand Down
Loading