Skip to content

Commit

Permalink
feat: implement TagLab labels import functionality with progress indi…
Browse files Browse the repository at this point in the history
…cation
  • Loading branch information
Jordan-Pierce committed Jan 17, 2025
1 parent 69eb178 commit e20cd9a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions coralnet_toolbox/IO/QtExportTagLabAnnotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def export_annotations(self):
json.dump(taglab_data, file, indent=4)
file.flush()

# Close the progress bar
progress_bar.stop_progress()
progress_bar.close()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@

from coralnet_toolbox.QtLabelWindow import Label

from coralnet_toolbox.QtProgressBar import ProgressBar

warnings.filterwarnings("ignore", category=DeprecationWarning)


# ----------------------------------------------------------------------------------------------------------------------
# Classes
# ----------------------------------------------------------------------------------------------------------------------


class ImportTagLabLabels:
def __init__(self, main_window):
self.main_window = main_window
Expand All @@ -26,12 +33,22 @@ def import_taglab_labels(self):
try:
with open(file_path, 'r') as file:
data = json.load(file)

if 'labels' not in data:

if 'Labels' in data:
data['labels'] = data.pop('Labels')
elif 'labels' in data:
pass
else:
QMessageBox.warning(self.label_window,
"Invalid JSON Format",
"The selected JSON file does not contain 'labels' key.")
"The selected JSON file does not contain 'Labels' or 'labels' key.")
return

# Create a progress bar
total_labels = len(data['labels'])
progress_bar = ProgressBar("Importing TagLab Labels", self.label_window)
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()
Expand All @@ -44,6 +61,13 @@ def import_taglab_labels(self):
label.long_label_code,
label.color,
label.id)

# 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",
Expand Down
4 changes: 2 additions & 2 deletions coralnet_toolbox/QtMainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from coralnet_toolbox.IO import (
ImportImages,
ImportLabels,
ImportTagLabLabels,
ImportAnnotations,
ImportCoralNetAnnotations,
ImportViscoreAnnotations,
Expand All @@ -40,7 +41,6 @@
ExportCoralNetAnnotations,
ExportViscoreAnnotations,
ExportTagLabAnnotations,
ImportTagLabLabels # Import the new class
)

from coralnet_toolbox.MachineLearning import (
Expand Down Expand Up @@ -143,6 +143,7 @@ def __init__(self):
# Create dialogs (I/O)
self.import_images = ImportImages(self)
self.import_labels = ImportLabels(self)
self.import_taglab_labels = ImportTagLabLabels(self)
self.import_annotations = ImportAnnotations(self)
self.import_coralnet_annotations = ImportCoralNetAnnotations(self)
self.import_viscore_annotations = ImportViscoreAnnotations(self)
Expand All @@ -152,7 +153,6 @@ def __init__(self):
self.export_coralnet_annotations = ExportCoralNetAnnotations(self)
self.export_viscore_annotations = ExportViscoreAnnotations(self)
self.export_taglab_annotations = ExportTagLabAnnotations(self)
self.import_taglab_labels = ImportTagLabLabels(self) # Create an instance of the new class

# Create dialogs (Sample)
self.patch_annotation_sampling_dialog = PatchSamplingDialog(self)
Expand Down

0 comments on commit e20cd9a

Please sign in to comment.