From e7ceed46bbd4347739a5f0493aa0a59855cbff6e Mon Sep 17 00:00:00 2001 From: jw098 Date: Mon, 10 Nov 2025 12:33:06 -0800 Subject: [PATCH 1/2] ML: Move data annotation file to the same folder as the image files --- SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp | 6 +++--- SerialPrograms/Source/ML/Programs/ML_LabelImages.h | 2 +- SerialPrograms/Source/ML/Programs/ML_LabelImagesWidget.cpp | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp b/SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp index a9035eb67d..a2596b120d 100644 --- a/SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp +++ b/SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp @@ -183,8 +183,8 @@ void LabelImages::load_image_related_data(const std::string& image_path, size_t const std::string anno_filename = std::filesystem::path(image_path).filename().replace_extension(".json").string(); // ensure the folder exists - std::filesystem::create_directory(ML_ANNOTATION_PATH()); - m_annotation_file_path = ML_ANNOTATION_PATH() + anno_filename; + // std::filesystem::create_directory(ML_ANNOTATION_PATH()); + m_annotation_file_path = image_path + anno_filename; // ML_ANNOTATION_PATH() + anno_filename; if (!std::filesystem::exists(m_annotation_file_path)){ cout << "Annotataion output path, " << m_annotation_file_path << " does not exist yet" << endl; return; @@ -641,7 +641,7 @@ std::pair LabelImages::pixel_to_float(size_t x, size_t y) const{ void LabelImages::export_to_yolov5_dataset(const std::string& image_folder_path, const std::string& dataset_path){ m_yolo_config_file_path = dataset_path; - export_image_annotations_to_yolo_dataset(image_folder_path, ML_ANNOTATION_PATH(), dataset_path); + export_image_annotations_to_yolo_dataset(image_folder_path, image_folder_path, dataset_path); // image_folder_path, ML_ANNOTATION_PATH(), dataset_path); } diff --git a/SerialPrograms/Source/ML/Programs/ML_LabelImages.h b/SerialPrograms/Source/ML/Programs/ML_LabelImages.h index ca5607dbe2..41318c4c8c 100644 --- a/SerialPrograms/Source/ML/Programs/ML_LabelImages.h +++ b/SerialPrograms/Source/ML/Programs/ML_LabelImages.h @@ -64,7 +64,7 @@ class LabelImages : public PanelInstance, public ConfigOption::Listener { // Load image related data: // - Image SAM embedding data file, which has the same file path but with a name suffix ".embedding" - // - Existing annotation file, which is stored in a pre-defined ML_ANNOTATION_PATH() and with the same filename as + // - Existing annotation file, which is stored in the same folder as the image and with the same filename as // the image but with name extension replaced to be ".json". void load_image_related_data(const std::string& image_path, const size_t source_image_width, const size_t source_image_height); diff --git a/SerialPrograms/Source/ML/Programs/ML_LabelImagesWidget.cpp b/SerialPrograms/Source/ML/Programs/ML_LabelImagesWidget.cpp index 5249dc734d..b567289711 100644 --- a/SerialPrograms/Source/ML/Programs/ML_LabelImagesWidget.cpp +++ b/SerialPrograms/Source/ML/Programs/ML_LabelImagesWidget.cpp @@ -151,8 +151,9 @@ LabelImages_Widget::LabelImages_Widget( this->m_program.save_annotation_to_file(); // ensure the folder exists - std::filesystem::create_directory(ML_ANNOTATION_PATH()); - QDesktopServices::openUrl(QUrl(QString::fromStdString("file:///" + ML_ANNOTATION_PATH()))); + // std::filesystem::create_directory(ML_ANNOTATION_PATH()); + // QDesktopServices::openUrl(QUrl(QString::fromStdString("file:///" + ML_ANNOTATION_PATH()))); + QDesktopServices::openUrl(QUrl(QString::fromStdString("file:///" + m_image_display_widget->image_folder_path()))); }); connect(save_anno_button, &QPushButton::clicked, this, [this](bool){ this->m_program.save_annotation_to_file(); From 09ba7dd45a29e75633fe6f056cf6facb4ad7f7f3 Mon Sep 17 00:00:00 2001 From: jw098 Date: Mon, 10 Nov 2025 19:36:02 -0800 Subject: [PATCH 2/2] bug fix: use image_folder_path instead of image_path. --- SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp b/SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp index a2596b120d..20a1cdacd2 100644 --- a/SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp +++ b/SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp @@ -181,10 +181,10 @@ void LabelImages::load_image_related_data(const std::string& image_path, size_t // see if we can load the previously created labels const std::string anno_filename = std::filesystem::path(image_path).filename().replace_extension(".json").string(); + const std::string image_folder_path = std::filesystem::path(image_path).parent_path().string() + "/"; - // ensure the folder exists // std::filesystem::create_directory(ML_ANNOTATION_PATH()); - m_annotation_file_path = image_path + anno_filename; // ML_ANNOTATION_PATH() + anno_filename; + m_annotation_file_path = image_folder_path + anno_filename; // ML_ANNOTATION_PATH() + anno_filename; if (!std::filesystem::exists(m_annotation_file_path)){ cout << "Annotataion output path, " << m_annotation_file_path << " does not exist yet" << endl; return;