Skip to content

Commit b49b472

Browse files
committed
cleaned up inference + added toggle visibility
1 parent eab113d commit b49b472

File tree

12 files changed

+133
-115
lines changed

12 files changed

+133
-115
lines changed

docs/res/code/interface.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ make_group
1919
.. autofunction:: napari_cellseg3d.interface::make_group
2020

2121

22-
make_container_widget
22+
make_container
2323
**************************************
24-
.. autofunction:: napari_cellseg3d.interface::make_container_widget
24+
.. autofunction:: napari_cellseg3d.interface::make_container
2525

2626

2727
make_button

docs/res/code/model_framework.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Class : ModelFramework
1212
Methods
1313
**********************
1414
.. autoclass:: napari_cellseg3d.model_framework::ModelFramework
15-
:members: __init__,load_dataset_paths,save_log, save_log_to_path,get_model, get_loss,display_status_report,load_dataset_paths,create_train_dataset_dict, load_image_dataset, load_label_dataset,load_results_path,load_model_path,get_device, update_default, remove_from_viewer
15+
:members: __init__,toggle_visibility, load_dataset_paths,save_log, save_log_to_path,get_model, get_loss,display_status_report,load_dataset_paths,create_train_dataset_dict, load_image_dataset, load_label_dataset,load_results_path,load_model_path,get_device, update_default, remove_from_viewer
1616
:noindex:
1717

1818

napari_cellseg3d/interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def make_group(title, L=7, T=20, R=7, B=11, solo_dict=None):
233233
return group, layout
234234

235235

236-
def make_container_widget(L=0, T=0, R=1, B=11, vertical=True):
236+
def make_container(L=0, T=0, R=1, B=11, vertical=True):
237237
"""Creates a QWidget and a layout for the purpose of containing other modules, with a Fixed layout.
238238
239239
Args:

napari_cellseg3d/model_framework.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def __init__(self, viewer: "napari.viewer.Viewer"):
9494
self.lbl_weights_path.setReadOnly(True)
9595

9696
self.weights_path_container = ui.combine_blocks(
97-
self.btn_weights_path, self.lbl_weights_path
97+
self.btn_weights_path, self.lbl_weights_path, b=0
9898
)
9999
self.weights_path_container.setVisible(False)
100100

@@ -107,7 +107,7 @@ def __init__(self, viewer: "napari.viewer.Viewer"):
107107
(
108108
self.container_report,
109109
self.container_report_layout,
110-
) = ui.make_container_widget(10, 5, 5, 5)
110+
) = ui.make_container(10, 5, 5, 5)
111111
self.container_report.setSizePolicy(
112112
QSizePolicy.Fixed, QSizePolicy.Minimum
113113
)
@@ -130,7 +130,17 @@ def __init__(self, viewer: "napari.viewer.Viewer"):
130130
self.btn_save_log.setVisible(False)
131131
#####################################################
132132

133+
def toggle_visibility(self, checkbox, widget):
134+
"""Toggles the visibility of a widget based on the status of a checkbox.
135+
136+
Args:
137+
checkbox: The QCheckbox that determines whether to show or not
138+
widget: The widget to hide or show
139+
"""
140+
widget.setVisible(checkbox.isChecked())
141+
133142
def send_log(self, text):
143+
"""Emit a signal to print in a Log"""
134144
self.log.print_and_log(text)
135145

136146
def save_log(self):
@@ -223,10 +233,9 @@ def display_status_report(self):
223233
self.progress.setValue(0)
224234

225235
def toggle_weights_path(self):
226-
if self.custom_weights_choice.isChecked():
227-
self.weights_path_container.setVisible(True)
228-
else:
229-
self.weights_path_container.setVisible(False)
236+
self.toggle_visibility(
237+
self.custom_weights_choice, self.weights_path_container
238+
)
230239

231240
def create_train_dataset_dict(self):
232241
"""Creates data dictionary for MONAI transforms and training.

napari_cellseg3d/model_workers.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def log_parameters(self):
164164
if self.use_window:
165165
status = "enabled"
166166
else:
167-
status="disabled"
167+
status = "disabled"
168168

169169
self.log(f"Window inference is {status}")
170170

@@ -282,7 +282,9 @@ def inference(self):
282282
self.log("Done")
283283
# print(f"wh dir : {WEIGHTS_DIR}")
284284
# print(weights)
285-
self.log("\nLoading weights...")
285+
self.log(
286+
"\nLoading weights..."
287+
) # TODO add try/except for invalid weights
286288

287289
if self.weights_dict["custom"]:
288290
weights = self.weights_dict["path"]
@@ -306,13 +308,12 @@ def inference(self):
306308

307309
inputs = inf_data["image"]
308310
# print(inputs.shape)
309-
# TODO figure out sliding window device
311+
310312
inputs = inputs.to("cpu")
311313

312314
model_output = lambda inputs: post_process_transforms(
313315
self.model_dict["class"].get_output(model, inputs)
314316
)
315-
# TODO add more params
316317

317318
if self.keep_on_cpu:
318319
dataset_device = "cpu"

napari_cellseg3d/plugin_convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def build(self):
8080

8181
l, t, r, b = 7, 20, 7, 11
8282

83-
w, layout = ui.make_container_widget()
83+
w, layout = ui.make_container()
8484

8585
results_widget = ui.combine_blocks(
8686
right_or_below=self.btn_result_path,

napari_cellseg3d/plugin_crop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def toggle_label_path(self):
9797
def build(self):
9898
"""Build buttons in a layout and add them to the napari Viewer"""
9999

100-
w, layout = ui.make_container_widget(0, 0, 1, 11)
100+
w, layout = ui.make_container(0, 0, 1, 11)
101101

102102
data_group_w, data_group_l = ui.make_group("Data")
103103
data_group_l.addWidget(

napari_cellseg3d/plugin_dock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(self, parent: "napari.viewer.Viewer"):
4848
self.time_label = ui.make_label("", self)
4949
self.time_label.setVisible(False)
5050

51-
io_panel, io_layout = ui.make_container_widget(vertical=False)
51+
io_panel, io_layout = ui.make_container(vertical=False)
5252
io_layout.addWidget(
5353
ui.combine_blocks(
5454
left_or_above=self.button,

napari_cellseg3d/plugin_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def build(self):
7979

8080
self.lbl_filetype.setVisible(False)
8181

82-
w, self.layout = ui.make_container_widget()
82+
w, self.layout = ui.make_container()
8383

8484
metrics_group_w, metrics_group_l = ui.make_group("Data")
8585

0 commit comments

Comments
 (0)