From 4cb4566fe48b6ce9d9e3943c615d77b8408c67ba Mon Sep 17 00:00:00 2001 From: Jordan Pierce Date: Fri, 17 Jan 2025 16:11:32 +0000 Subject: [PATCH] TagLab labels; export dataset visual bug; robustness to IO --- coralnet_toolbox/IO/QtExportAnnotations.py | 13 +++-- .../IO/QtExportCoralNetAnnotations.py | 17 +++--- coralnet_toolbox/IO/QtExportLabels.py | 26 ++++++++- .../IO/QtExportTagLabAnnotations.py | 10 ++-- .../IO/QtExportViscoreAnnotations.py | 10 ++-- coralnet_toolbox/IO/QtImportAnnotations.py | 11 ++-- .../IO/QtImportCoralNetAnnotations.py | 12 ++--- coralnet_toolbox/IO/QtImportImages.py | 54 +++++++++++-------- coralnet_toolbox/IO/QtImportLabels.py | 18 ++++++- coralnet_toolbox/IO/QtImportTagLabLabels.py | 42 +++++++++------ .../IO/QtImportViscoreAnnotations.py | 21 +++++--- coralnet_toolbox/IO/__init__.py | 2 + .../ExportDataset/QtClassify.py | 2 +- .../MachineLearning/ExportDataset/QtDetect.py | 2 +- .../ExportDataset/QtSegment.py | 2 +- coralnet_toolbox/QtMainWindow.py | 16 +++--- coralnet_toolbox/SAM/QtDeployPredictor.py | 20 ++++--- coralnet_toolbox/Tile/TileInference/QtBase.py | 2 + 18 files changed, 181 insertions(+), 99 deletions(-) diff --git a/coralnet_toolbox/IO/QtExportAnnotations.py b/coralnet_toolbox/IO/QtExportAnnotations.py index ec3e02fd..1c014220 100644 --- a/coralnet_toolbox/IO/QtExportAnnotations.py +++ b/coralnet_toolbox/IO/QtExportAnnotations.py @@ -7,6 +7,7 @@ from coralnet_toolbox.Annotations.QtPatchAnnotation import PatchAnnotation from coralnet_toolbox.Annotations.QtPolygonAnnotation import PolygonAnnotation from coralnet_toolbox.Annotations.QtRectangleAnnotation import RectangleAnnotation + from coralnet_toolbox.QtProgressBar import ProgressBar warnings.filterwarnings("ignore", category=DeprecationWarning) @@ -35,6 +36,7 @@ def export_annotations(self): options=options) if file_path: try: + # Make cursor busy QApplication.setOverrideCursor(Qt.WaitCursor) total_annotations = len(list(self.annotation_window.annotations_dict.values())) @@ -74,9 +76,6 @@ def export_annotations(self): json.dump(export_dict, file, indent=4) file.flush() - progress_bar.stop_progress() - progress_bar.close() - QMessageBox.information(self.annotation_window, "Annotations Exported", "Annotations have been successfully exported.") @@ -85,5 +84,9 @@ def export_annotations(self): QMessageBox.warning(self.annotation_window, "Error Exporting Annotations", f"An error occurred while exporting annotations: {str(e)}") - - QApplication.restoreOverrideCursor() \ No newline at end of file + + finally: + # Restore the cursor + QApplication.restoreOverrideCursor() + progress_bar.stop_progress() + progress_bar.close() \ No newline at end of file diff --git a/coralnet_toolbox/IO/QtExportCoralNetAnnotations.py b/coralnet_toolbox/IO/QtExportCoralNetAnnotations.py index 41b45e2b..0c47cc42 100644 --- a/coralnet_toolbox/IO/QtExportCoralNetAnnotations.py +++ b/coralnet_toolbox/IO/QtExportCoralNetAnnotations.py @@ -31,11 +31,14 @@ def export_annotations(self): "CSV Files (*.csv);;All Files (*)", options=options) if file_path: - + + # Make cursor busy QApplication.setOverrideCursor(Qt.WaitCursor) + + total_annotations = len(self.annotation_window.annotations_dict) progress_bar = ProgressBar(self.annotation_window, title="Exporting CoralNet Annotations") progress_bar.show() - progress_bar.start_progress(len(self.annotation_window.annotations_dict)) + progress_bar.start_progress(total_annotations) try: df = [] @@ -55,7 +58,9 @@ def export_annotations(self): QMessageBox.warning(self.annotation_window, "Error Exporting Annotations", f"An error occurred while exporting annotations: {str(e)}") - - progress_bar.stop_progress() - progress_bar.close() - QApplication.restoreOverrideCursor() \ No newline at end of file + + finally: + # Restore the cursor + QApplication.restoreOverrideCursor() + progress_bar.stop_progress() + progress_bar.close() \ No newline at end of file diff --git a/coralnet_toolbox/IO/QtExportLabels.py b/coralnet_toolbox/IO/QtExportLabels.py index b2139b10..0f21725d 100644 --- a/coralnet_toolbox/IO/QtExportLabels.py +++ b/coralnet_toolbox/IO/QtExportLabels.py @@ -1,8 +1,11 @@ import json import warnings +from PyQt5.QtCore import Qt from PyQt5.QtWidgets import (QFileDialog, QMessageBox) +from coralnet_toolbox.QtProgressBar import ProgressBar + warnings.filterwarnings("ignore", category=DeprecationWarning) @@ -28,8 +31,22 @@ def export_labels(self): "JSON Files (*.json);;All Files (*)", options=options) if file_path: + + # Make cursor busy + self.QApplication.setOverrideCursor(Qt.WaitCursor) + + # Create a progress bar + total_labels = len(self.label_window.labels) + progress_bar = ProgressBar("Exporting Labels", self.label_window) + progress_bar.show() + progress_bar.start_progress(total_labels) + try: - labels_data = [label.to_dict() for label in self.label_window.labels] + labels_data = [] + for i, label in enumerate(self.label_window.labels): + labels_data.append(label.to_dict()) + progress_bar.update_progress(i + 1) + with open(file_path, 'w') as file: json.dump(labels_data, file, indent=4) @@ -40,4 +57,9 @@ def export_labels(self): except Exception as e: QMessageBox.warning(self.label_window, "Error Importing Labels", - f"An error occurred while importing labels: {str(e)}") \ No newline at end of file + f"An error occurred while importing labels: {str(e)}") + finally: + # Reset the cursor + self.QApplication.restoreOverrideCursor() + progress_bar.stop_progress() + progress_bar.close() diff --git a/coralnet_toolbox/IO/QtExportTagLabAnnotations.py b/coralnet_toolbox/IO/QtExportTagLabAnnotations.py index 1484961b..779adbe5 100644 --- a/coralnet_toolbox/IO/QtExportTagLabAnnotations.py +++ b/coralnet_toolbox/IO/QtExportTagLabAnnotations.py @@ -180,10 +180,6 @@ def export_annotations(self): json.dump(taglab_data, file, indent=4) file.flush() - # Close the progress bar - progress_bar.stop_progress() - progress_bar.close() - QMessageBox.information(self.annotation_window, "Annotations Exported", "Annotations have been successfully exported.") @@ -193,4 +189,8 @@ def export_annotations(self): "Error Exporting Annotations", f"An error occurred while exporting annotations: {str(e)}") - QApplication.restoreOverrideCursor() \ No newline at end of file + finally: + # Restore the cursor + QApplication.restoreOverrideCursor() + progress_bar.stop_progress() + progress_bar.close() \ No newline at end of file diff --git a/coralnet_toolbox/IO/QtExportViscoreAnnotations.py b/coralnet_toolbox/IO/QtExportViscoreAnnotations.py index 285750f2..fc0ab46c 100644 --- a/coralnet_toolbox/IO/QtExportViscoreAnnotations.py +++ b/coralnet_toolbox/IO/QtExportViscoreAnnotations.py @@ -58,7 +58,9 @@ def export_annotations(self): QMessageBox.warning(self.annotation_window, "Error Exporting Viscore Annotations", f"An error occurred while exporting annotations: {str(e)}") - - progress_bar.stop_progress() - progress_bar.close() - QApplication.restoreOverrideCursor() \ No newline at end of file + + finally: + # Restore the cursor + QApplication.restoreOverrideCursor() + progress_bar.stop_progress() + progress_bar.close() \ No newline at end of file diff --git a/coralnet_toolbox/IO/QtImportAnnotations.py b/coralnet_toolbox/IO/QtImportAnnotations.py index e5afc10d..128b24de 100644 --- a/coralnet_toolbox/IO/QtImportAnnotations.py +++ b/coralnet_toolbox/IO/QtImportAnnotations.py @@ -43,6 +43,7 @@ def import_annotations(self): options=options) if file_paths: try: + # Make cursor busy QApplication.setOverrideCursor(Qt.WaitCursor) all_data = {} @@ -114,10 +115,6 @@ def import_annotations(self): # Load the annotations for current image self.annotation_window.load_annotations() - # Stop the progress bar - progress_bar.stop_progress() - progress_bar.close() - QMessageBox.information(self.annotation_window, "Annotations Imported", "Annotations have been successfully imported.") @@ -127,4 +124,8 @@ def import_annotations(self): "Error Importing Annotations", f"An error occurred while importing annotations: {str(e)}") - QApplication.restoreOverrideCursor() + finally: + # Restore the cursor + QApplication.restoreOverrideCursor() + progress_bar.stop_progress() + progress_bar.close() diff --git a/coralnet_toolbox/IO/QtImportCoralNetAnnotations.py b/coralnet_toolbox/IO/QtImportCoralNetAnnotations.py index 3eb2b150..54e03e30 100644 --- a/coralnet_toolbox/IO/QtImportCoralNetAnnotations.py +++ b/coralnet_toolbox/IO/QtImportCoralNetAnnotations.py @@ -160,10 +160,6 @@ def import_annotations(self): # Load the annotations for current image self.annotation_window.load_annotations() - # Stop the progress bar - progress_bar.stop_progress() - progress_bar.close() - QMessageBox.information(self.annotation_window, "Annotations Imported", "Annotations have been successfully imported.") @@ -172,5 +168,9 @@ def import_annotations(self): QMessageBox.warning(self.annotation_window, "Error Importing Annotations", f"An error occurred while importing annotations: {str(e)}") - - QApplication.restoreOverrideCursor() + + finally: + # Restore the cursor to the default cursor + QApplication.restoreOverrideCursor() + progress_bar.stop_progress() + progress_bar.close() diff --git a/coralnet_toolbox/IO/QtImportImages.py b/coralnet_toolbox/IO/QtImportImages.py index d3b568c0..5fa6b59a 100644 --- a/coralnet_toolbox/IO/QtImportImages.py +++ b/coralnet_toolbox/IO/QtImportImages.py @@ -28,30 +28,38 @@ def import_images(self): "", "Image Files (*.png *.jpg *.jpeg *.tif* *.bmp)") if file_names: - # Set the cursor to waiting (busy) cursor - QApplication.setOverrideCursor(Qt.WaitCursor) + try: + # Set the cursor to waiting (busy) cursor + QApplication.setOverrideCursor(Qt.WaitCursor) - progress_bar = ProgressBar(self.image_window, title="Importing Images") - progress_bar.show() - progress_bar.start_progress(len(file_names)) - progress_bar.set_value(1) + progress_bar = ProgressBar(self.image_window, title="Importing Images") + progress_bar.show() + progress_bar.start_progress(len(file_names)) - for i, file_name in enumerate(file_names): - if file_name not in set(self.image_window.image_paths): - self.image_window.add_image(file_name) - progress_bar.update_progress() + for i, file_name in enumerate(file_names): + if file_name not in set(self.image_window.image_paths): + try: + self.image_window.add_image(file_name) + except Exception as e: + print(f"Warning: Could not import image {file_name}. Error: {e}") + + # Update the progress bar + progress_bar.update_progress() - progress_bar.stop_progress() - progress_bar.close() + # Update filtered images + self.image_window.filter_images() + # Show the last image + self.image_window.load_image_by_path(self.image_window.image_paths[-1]) - # Update filtered images - self.image_window.filter_images() - # Show the last image - self.image_window.load_image_by_path(self.image_window.image_paths[-1]) - - # Restore the cursor to the default cursor - QApplication.restoreOverrideCursor() - - QMessageBox.information(self.image_window, - "Image(s) Imported", - "Image(s) have been successfully imported.") \ No newline at end of file + QMessageBox.information(self.image_window, + "Image(s) Imported", + "Image(s) have been successfully imported.") + except Exception as e: + QMessageBox.warning(self.image_window, + "Error Importing Image(s)", + f"An error occurred while importing image(s): {str(e)}") + finally: + # Restore the cursor to the default cursor + QApplication.restoreOverrideCursor() + progress_bar.stop_progress() + progress_bar.close() \ No newline at end of file diff --git a/coralnet_toolbox/IO/QtImportLabels.py b/coralnet_toolbox/IO/QtImportLabels.py index 4ceedda6..1af154a3 100644 --- a/coralnet_toolbox/IO/QtImportLabels.py +++ b/coralnet_toolbox/IO/QtImportLabels.py @@ -8,6 +8,8 @@ from coralnet_toolbox.QtLabelWindow import Label +from coralnet_toolbox.QtProgressBar import ProgressBar + # ---------------------------------------------------------------------------------------------------------------------- # Classes @@ -34,6 +36,12 @@ def import_labels(self): try: with open(file_path, 'r') as file: labels_data = json.load(file) + + # Create a progress bar + total_labels = len(labels_data) + progress_bar = ProgressBar("Importing Labels", self.label_window) + progress_bar.show() + progress_bar.start_progress(total_labels) for label_data in labels_data: label = Label.from_dict(label_data) @@ -42,6 +50,8 @@ def import_labels(self): label.long_label_code, label.color, label.id) + # Update the progress bar + progress_bar.update_progress() # Set the Review label as active self.label_window.set_active_label(self.label_window.get_label_by_long_code("Review")) @@ -53,4 +63,10 @@ def import_labels(self): except Exception as e: QMessageBox.warning(self.label_window, "Error Importing Labels", - f"An error occurred while importing Labels: {str(e)}") \ No newline at end of file + f"An error occurred while importing Labels: {str(e)}") + + finally: + # Stop the progress bar + progress_bar.stop_progress() + progress_bar.close() + QApplication.restoreOverrideCursor() \ No newline at end of file diff --git a/coralnet_toolbox/IO/QtImportTagLabLabels.py b/coralnet_toolbox/IO/QtImportTagLabLabels.py index 6b98effa..97ab39ef 100644 --- a/coralnet_toolbox/IO/QtImportTagLabLabels.py +++ b/coralnet_toolbox/IO/QtImportTagLabLabels.py @@ -1,7 +1,9 @@ import json import warnings -from PyQt5.QtWidgets import QFileDialog, QMessageBox +from PyQt5.QtCore import Qt +from PyQt5.QtGui import QColor +from PyQt5.QtWidgets import QFileDialog, QMessageBox, QApplication from coralnet_toolbox.QtLabelWindow import Label @@ -43,31 +45,33 @@ def import_taglab_labels(self): "Invalid JSON Format", "The selected JSON file does not contain 'Labels' or 'labels' key.") return + + # Make cursor busy + QApplication.setOverrideCursor(Qt.WaitCursor) # Create a progress bar total_labels = len(data['labels']) - progress_bar = ProgressBar("Importing TagLab Labels", self.label_window) + progress_bar = ProgressBar(self.label_window, "Importing TagLab Labels") progress_bar.show() progress_bar.start_progress(total_labels) - for label_id, label_info in data['labels'].items(): - short_label_code = label_info['name'].strip() - long_label_code = label_info['name'].strip() - color = label_info['fill'] + for label_info in data['labels']: + try: + short_label_code = label_info['name'].strip() + long_label_code = label_info['name'].strip() + color = label_info['fill'] + + # Create a QtColor object from the color string + color = QColor(color[0], color[1], color[2]) - label = Label(short_label_code, long_label_code, color, label_id) - if not self.label_window.label_exists(label.short_label_code, label.long_label_code): - self.label_window.add_label(label.short_label_code, - label.long_label_code, - label.color, - label.id) + # Add label if it does not exist + self.label_window.add_label_if_not_exists(short_label_code, long_label_code, color) + + except Exception as e: + print(f"Warning: Could not import label {label_info['name']}: {str(e)}") # Update the progress bar progress_bar.update_progress() - - # Close the progress bar - progress_bar.close() - progress_bar.stop_progress() QMessageBox.information(self.label_window, "Labels Imported", @@ -77,3 +81,9 @@ def import_taglab_labels(self): QMessageBox.warning(self.label_window, "Error Importing Labels", f"An error occurred while importing TagLab labels: {str(e)}") + + finally: + # Stop the progress bar + progress_bar.stop_progress() + progress_bar.close() + QApplication.restoreOverrideCursor() diff --git a/coralnet_toolbox/IO/QtImportViscoreAnnotations.py b/coralnet_toolbox/IO/QtImportViscoreAnnotations.py index 1c2a829a..3400c39b 100644 --- a/coralnet_toolbox/IO/QtImportViscoreAnnotations.py +++ b/coralnet_toolbox/IO/QtImportViscoreAnnotations.py @@ -13,6 +13,7 @@ QLabel, QHBoxLayout, QPushButton, QDialogButtonBox) from coralnet_toolbox.Annotations.QtPatchAnnotation import PatchAnnotation + from coralnet_toolbox.QtProgressBar import ProgressBar @@ -209,9 +210,11 @@ def browse_csv_file(file_path_input): # Start the import process QApplication.setOverrideCursor(Qt.WaitCursor) + + total_annotations = len(df) progress_bar = ProgressBar(self.annotation_window, title="Importing Viscore Annotations") progress_bar.show() - progress_bar.start_progress(len(df)) + progress_bar.start_progress(total_annotations) # Map image names to image paths image_path_map = {os.path.basename(path): path for path in self.image_window.image_paths} @@ -280,6 +283,7 @@ def browse_csv_file(file_path_input): # Add annotation to the dict self.annotation_window.annotations_dict[annotation.id] = annotation + # Update the progress bar progress_bar.update_progress() # Update the image window's image dict @@ -288,16 +292,17 @@ def browse_csv_file(file_path_input): # Load the annotations for current image self.annotation_window.load_annotations() - # Stop the progress bar - progress_bar.stop_progress() - progress_bar.close() - QMessageBox.information(self.annotation_window, "Annotations Imported", "Annotations have been successfully imported.") except Exception as e: - QMessageBox.critical(self.annotation_window, "Critical Error", f"Failed to import annotations: {e}") + QMessageBox.critical(self.annotation_window, + "Critical Error", + f"Failed to import annotations: {e}") - # Make the cursor active - QApplication.restoreOverrideCursor() \ No newline at end of file + finally: + # Restore the cursor + QApplication.restoreOverrideCursor() + progress_bar.stop_progress() + progress_bar.close() diff --git a/coralnet_toolbox/IO/__init__.py b/coralnet_toolbox/IO/__init__.py index 2fbe9dfb..b6a149eb 100644 --- a/coralnet_toolbox/IO/__init__.py +++ b/coralnet_toolbox/IO/__init__.py @@ -1,5 +1,6 @@ from .QtImportImages import ImportImages from .QtImportLabels import ImportLabels +from .QtImportTagLabLabels import ImportTagLabLabels from .QtImportAnnotations import ImportAnnotations from .QtImportCoralNetAnnotations import ImportCoralNetAnnotations from .QtImportViscoreAnnotations import ImportViscoreAnnotations @@ -13,6 +14,7 @@ __all__ = [ 'ImportImages', 'ImportLabels', + 'ImportTagLabLabels', 'ImportAnnotations', 'ImportCoralNetAnnotations', 'ImportViscoreAnnotations', diff --git a/coralnet_toolbox/MachineLearning/ExportDataset/QtClassify.py b/coralnet_toolbox/MachineLearning/ExportDataset/QtClassify.py index edb74bcb..dfde7f79 100644 --- a/coralnet_toolbox/MachineLearning/ExportDataset/QtClassify.py +++ b/coralnet_toolbox/MachineLearning/ExportDataset/QtClassify.py @@ -91,7 +91,7 @@ def process_annotations(self, annotations, split_dir, split): if not image_paths: return - progress_bar = ProgressBar(self, title=f"Creating {split} Dataset") + progress_bar = ProgressBar(self.annotation_window, title=f"Creating {split} Dataset") progress_bar.show() progress_bar.start_progress(len(image_paths)) diff --git a/coralnet_toolbox/MachineLearning/ExportDataset/QtDetect.py b/coralnet_toolbox/MachineLearning/ExportDataset/QtDetect.py index c7e68ae8..43748b4c 100644 --- a/coralnet_toolbox/MachineLearning/ExportDataset/QtDetect.py +++ b/coralnet_toolbox/MachineLearning/ExportDataset/QtDetect.py @@ -107,7 +107,7 @@ def process_annotations(self, annotations, split_dir, split): if not image_paths: return - progress_bar = ProgressBar(self, title=f"Creating {split} Dataset") + progress_bar = ProgressBar(self.annotation_window, title=f"Creating {split} Dataset") progress_bar.show() progress_bar.start_progress(len(image_paths)) diff --git a/coralnet_toolbox/MachineLearning/ExportDataset/QtSegment.py b/coralnet_toolbox/MachineLearning/ExportDataset/QtSegment.py index 239b6467..3bbf2fad 100644 --- a/coralnet_toolbox/MachineLearning/ExportDataset/QtSegment.py +++ b/coralnet_toolbox/MachineLearning/ExportDataset/QtSegment.py @@ -107,7 +107,7 @@ def process_annotations(self, annotations, split_dir, split): if not image_paths: return - progress_bar = ProgressBar(self, title=f"Creating {split} Dataset") + progress_bar = ProgressBar(self.annotation_window, title=f"Creating {split} Dataset") progress_bar.show() progress_bar.start_progress(len(image_paths)) diff --git a/coralnet_toolbox/QtMainWindow.py b/coralnet_toolbox/QtMainWindow.py index 49cf117e..066f1197 100644 --- a/coralnet_toolbox/QtMainWindow.py +++ b/coralnet_toolbox/QtMainWindow.py @@ -363,17 +363,17 @@ def __init__(self): self.tile_dataset_menu.addAction(self.segment_tile_dataset_action) # Tile Inference submenu - self.tile_inference_menu = self.tile_menu.addMenu("Tile Inference") + # self.tile_inference_menu = self.tile_menu.addMenu("Tile Inference") # Tile Detect Inference - self.detect_tile_inference_action = QAction("Detect", self) - self.detect_tile_inference_action.triggered.connect(self.open_detect_tile_inference_dialog) - self.tile_inference_menu.addAction(self.detect_tile_inference_action) + # self.detect_tile_inference_action = QAction("Detect", self) + # self.detect_tile_inference_action.triggered.connect(self.open_detect_tile_inference_dialog) + # self.tile_inference_menu.addAction(self.detect_tile_inference_action) # Tile Segment Inference - self.segment_tile_inference_action = QAction("Segment", self) - self.segment_tile_inference_action.triggered.connect(self.open_segment_tile_inference_dialog) - self.tile_inference_menu.addAction(self.segment_tile_inference_action) + # self.segment_tile_inference_action = QAction("Segment", self) + # self.segment_tile_inference_action.triggered.connect(self.open_segment_tile_inference_dialog) + # self.tile_inference_menu.addAction(self.segment_tile_inference_action) # CoralNet menu # self.coralnet_menu = self.menu_bar.addMenu("CoralNet") @@ -577,7 +577,7 @@ def __init__(self): self.tile_inference_tool_action = QAction(self.tile_icon, "Tile Inference", self) self.tile_inference_tool_action.setCheckable(False) self.tile_inference_tool_action.triggered.connect(self.toggle_tool) - self.toolbar.addAction(self.tile_inference_tool_action) # TODO + # self.toolbar.addAction(self.tile_inference_tool_action) # TODO self.toolbar.addSeparator() diff --git a/coralnet_toolbox/SAM/QtDeployPredictor.py b/coralnet_toolbox/SAM/QtDeployPredictor.py index fe9b79f8..99811a4c 100644 --- a/coralnet_toolbox/SAM/QtDeployPredictor.py +++ b/coralnet_toolbox/SAM/QtDeployPredictor.py @@ -318,10 +318,10 @@ def load_model(self): self.loaded_model.model.eval() self.status_bar.setText("Model loaded") - QMessageBox.information(self, "Model Loaded", "Model loaded successfully") + QMessageBox.information(self.annotation_window, "Model Loaded", "Model loaded successfully") except Exception as e: - QMessageBox.critical(self, "Error Loading Model", f"Error loading model: {e}") + QMessageBox.critical(self.annotation_window, "Error Loading Model", f"Error loading model: {e}") progress_bar.stop_progress() progress_bar.close() @@ -380,7 +380,7 @@ def set_image(self, image, image_path): raise Exception("Model not loaded") except Exception as e: - QMessageBox.critical(self, "Error Setting Image", f"Error setting image: {e}") + QMessageBox.critical(self.annotation_window, "Error Setting Image", f"Error setting image: {e}") finally: # Ensure cleanup happens even if an error occurs @@ -497,7 +497,9 @@ def predict_from_prompts(self, bbox, points, labels): results (Results): Ultralytics Results object """ if not self.loaded_model: - QMessageBox.critical(self, "Model Not Loaded", "Model not loaded, cannot make predictions") + QMessageBox.critical(self.annotation_window, + "Model Not Loaded", + "Model not loaded, cannot make predictions") return None try: @@ -528,7 +530,9 @@ def predict_from_prompts(self, bbox, points, labels): results = results_processor.from_sam(masks, scores, self.original_image, self.image_path) except Exception as e: - QMessageBox.critical(self, "Prediction Error", f"Error predicting: {e}") + QMessageBox.critical(self.annotation_window, + "Prediction Error", + f"Error predicting: {e}") return None return results @@ -580,7 +584,9 @@ def predict_from_results(self, results_generator, class_mapping): yield new_results except Exception as e: - QMessageBox.critical(self, "Prediction Error", f"Error predicting: {e}") + QMessageBox.critical(self.annotation_window, + "Prediction Error", + f"Error predicting: {e}") def deactivate_model(self): """ @@ -595,4 +601,4 @@ def deactivate_model(self): empty_cache() self.main_window.untoggle_all_tools() self.status_bar.setText("No model loaded") - QMessageBox.information(self, "Model Deactivated", "Model deactivated") \ No newline at end of file + QMessageBox.information(self.annotation_window, "Model Deactivated", "Model deactivated") \ No newline at end of file diff --git a/coralnet_toolbox/Tile/TileInference/QtBase.py b/coralnet_toolbox/Tile/TileInference/QtBase.py index 4de8e257..9504ea07 100644 --- a/coralnet_toolbox/Tile/TileInference/QtBase.py +++ b/coralnet_toolbox/Tile/TileInference/QtBase.py @@ -285,6 +285,8 @@ def apply(self): try: # Tile inference self.setup_tile_inference() + # Apply tile inference + # self.apply_tile_inference() # TODO except Exception as e: QMessageBox.critical(self, "Error", f"Failed to tile inference image: {str(e)}")