Skip to content

Commit

Permalink
feat: Add validation number of patches parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeschamps committed Oct 24, 2024
1 parent d852b93 commit 7972555
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/careamics_napari/signals/training_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,9 @@ class TrainingSignal:

num_conv_filters: int = 32
"""Number of convolutional filters in the first layer."""

val_percentage: float = 0.1
"""Percentage of the training data used for validation."""

val_minimum_split: int = 1
"""Minimum number of patches or images in the validation set."""
37 changes: 35 additions & 2 deletions src/careamics_napari/widgets/configuration_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@

from careamics_napari.signals import TrainingSignal

from .qt_widgets import create_int_spinbox
try:
from .qt_widgets import create_double_spinbox, create_int_spinbox
except ImportError:
# to run the __name__ == "main" block
from careamics_napari.widgets.qt_widgets import (
create_double_spinbox,
create_int_spinbox,
)

# TODO missing:
# structn2v
Expand Down Expand Up @@ -78,6 +85,30 @@ def __init__(
experiment_widget.setLayout(experiment_layout)
self.layout().addWidget(experiment_widget)

##################
# validation
validation = QGroupBox("Validation")
validation_layout = QFormLayout()

self.validation_perc = create_double_spinbox(
0.01, 1, self.configuration_signal.val_percentage, 0.01, n_decimal=2
)
self.validation_perc.setToolTip(
"Percentage of the training data used for validation."
)

self.validation_split = create_int_spinbox(
1, 100, self.configuration_signal.val_minimum_split, 1
)
self.validation_perc.setToolTip(
"Minimum number of patches or images in the validation set."
)

validation_layout.addRow("Percentage", self.validation_perc)
validation_layout.addRow("Minimum split", self.validation_split)
validation.setLayout(validation_layout)
self.layout().addWidget(validation)

##################
# augmentations group box, with x_flip, y_flip and rotations
augmentations = QGroupBox("Augmentations")
Expand Down Expand Up @@ -253,6 +284,8 @@ def _save(self: Self) -> None:
# Update the parameters
if self.configuration_signal is not None:
self.configuration_signal.experiment_name = self.experiment_name.text()
self.configuration_signal.val_percentage = self.validation_perc.value()
self.configuration_signal.val_minimum_split = self.validation_split.value()
self.configuration_signal.x_flip = self.x_flip.isChecked()
self.configuration_signal.y_flip = self.y_flip.isChecked()
self.configuration_signal.rotations = self.rotations.isChecked()
Expand Down Expand Up @@ -281,7 +314,7 @@ def _save(self: Self) -> None:
myalgo = TrainingSignal(use_channels=False) # type: ignore

# Instantiate widget
widget = AdvancedConfigurationWindow(training_signal=myalgo) # type: ignore
widget = AdvancedConfigurationWindow(None, training_signal=myalgo) # type: ignore

# Show the widget
widget.show()
Expand Down
2 changes: 2 additions & 0 deletions src/careamics_napari/workers/training_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ def _train(
val_source=val_data,
train_target=train_data_target,
val_target=val_data_target,
val_minimum_split=config_signal.val_minimum_split,
val_percentage=config_signal.val_percentage,
)

# # TODO can we use this to monkey patch the training process?
Expand Down

0 comments on commit 7972555

Please sign in to comment.