Skip to content

Commit

Permalink
Fixed train/predict layer is none issue (#14)
Browse files Browse the repository at this point in the history
* fixed module test run: replaced name with algorithm

* added checkpoints, csv_logs, and tb_logs to be ignored

* fixed layer is none when image was loaded before the plugin
  • Loading branch information
mese79 authored Jan 16, 2025
1 parent 09af2b9 commit 054b4a6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
checkpoints
csv_logs
tb_logs

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 1 addition & 1 deletion src/careamics_napari/widgets/algorithm_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def algorithm_changed(self, index: int) -> None:

myalgo = TrainingSignal() # type: ignore

@myalgo.events.name.connect
@myalgo.events.algorithm.connect
def print_algorithm(name: str):
"""Print the selected algorithm."""
print(f"Selected algorithm: {name}")
Expand Down
3 changes: 3 additions & 0 deletions src/careamics_napari/widgets/predict_data_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def _set_layer_tab(

# connection actions for images
self.img_pred.changed.connect(self._update_pred_layer)
# to cover the case when image was loaded before the plugin
if self.img_pred.value is not None:
self._update_pred_layer(self.img_pred.value)

else:
# simply remove the tab
Expand Down
12 changes: 12 additions & 0 deletions src/careamics_napari/widgets/train_data_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ def _set_layer_tab(
self.img_train.changed.connect(self._update_train_layer)
self.img_val.changed.connect(self._update_val_layer)

# to cover the case when image was loaded before the plugin
if self.img_train.value is not None:
self._update_train_layer(self.img_train.value)
if self.img_val.value is not None:
self._update_val_layer(self.img_val.value)

if self.use_target:
# get the target layers
self.target_train = layer_choice()
Expand All @@ -118,6 +124,12 @@ def _set_layer_tab(
self.target_train.changed.connect(self._update_train_target_layer)
self.target_val.changed.connect(self._update_val_target_layer)

# to cover the case when image was loaded before the plugin
if self.target_train.value is not None:
self._update_train_target_layer(self.target_train.value)
if self.target_val.value is not None:
self._update_val_target_layer(self.target_val.value)

widget_layers.layout().addRow("Train", self.img_train.native)
widget_layers.layout().addRow("Val", self.img_val.native)
widget_layers.layout().addRow("Train target", self.target_train.native)
Expand Down

0 comments on commit 054b4a6

Please sign in to comment.