Skip to content

Commit e77d440

Browse files
committed
docs + fixed attribute name error in cropping
1 parent 3be91d0 commit e77d440

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

docs/res/model_instance_seg.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
model_workers.py
2+
===========================================
3+
4+
5+
Functions
6+
-------------
7+
8+
binary_connected
9+
**************************************
10+
.. autofunction:: napari_cellseg_annotator.model_instance_seg::binary_connected
11+
12+
binary_watershed
13+
**************************************
14+
.. autofunction:: napari_cellseg_annotator.model_instance_seg::binary_watershed

src/napari_cellseg_annotator/model_workers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
so instead, following the instructions in the guides below to have a worker with custom signals, I implemented
4242
a custom worker function."""
4343

44-
44+
# FutureReference():
4545
# https://python-forum.io/thread-31349.html
4646
# https://www.pythoncentral.io/pysidepyqt-tutorial-creating-your-own-signals-and-slots/
4747
# https://napari-staging-site.github.io/guides/stable/threading.html
@@ -100,7 +100,7 @@ def __init__(
100100
"""
101101

102102
super().__init__(self.inference)
103-
self._signals = LogSignal()
103+
self._signals = LogSignal() # add custom signals
104104
self.log_signal = self._signals.log_signal
105105
###########################################
106106
###########################################
@@ -310,6 +310,8 @@ def inference(self):
310310
"model_name": self.model_dict["name"],
311311
}
312312

313+
model.to("cpu")
314+
313315

314316
class TrainingWorker(GeneratorWorker):
315317
"""A custom worker to run training jobs in.
@@ -693,6 +695,9 @@ def train(self):
693695
f"Train completed, best_metric: {best_metric:.4f} "
694696
f"at epoch: {best_metric_epoch}"
695697
)
698+
model.to("cpu")
699+
optimizer = None
700+
del optimizer
696701
# del device
697702
# del model_id
698703
# del model_name

src/napari_cellseg_annotator/plugin_crop.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@ def quicksave(self):
158158
im_dir + "/" + im_filename + "_cropped_" + time + ".tif"
159159
)
160160

161+
print(self.label)
161162
if self.label is not None:
162163
im_filename = os.path.basename(self.label_path).split(".")[0]
163-
im_dir = os.path.split(self.label_path)[0]
164+
im_dir = os.path.split(self.label_path)[0] + "/cropped"
164165
name = (
165166
im_dir
166167
+ "/"
@@ -170,6 +171,7 @@ def quicksave(self):
170171
+ ".tif"
171172
)
172173
dat = viewer.layers["cropped_labels"].data
174+
os.makedirs(im_dir, exist_ok=True)
173175
imwrite(name, data=dat)
174176

175177
else:
@@ -182,12 +184,14 @@ def quicksave(self):
182184
dir_name = im_dir + "/volume_cropped_" + time
183185
utils.save_stack(dat, dir_name, filetype=self.filetype)
184186

187+
print(self.label)
185188
if self.label is not None:
186189

187190
# im_filename = os.path.basename(self.image_path).split(".")[0]
188191
im_dir = os.path.split(self.label_path)[0]
189192

190193
dir_name = im_dir + "/labels_cropped_" + time
194+
print(f"dir name {dir_name}")
191195
dat = viewer.layers["cropped_labels"].data
192196
utils.save_stack(dat, dir_name, filetype=self.filetype)
193197

@@ -231,7 +235,7 @@ def start(self):
231235
)
232236

233237
if self.crop_labels:
234-
self.labels = utils.load_images(
238+
self.label = utils.load_images(
235239
self.label_path, self.filetype, self.as_folder
236240
)
237241

@@ -248,7 +252,7 @@ def start(self):
248252
)
249253

250254
if self.crop_labels:
251-
self.label_layer = vw.add_labels(self.labels, visible=False)
255+
self.label_layer = vw.add_labels(self.label, visible=False)
252256

253257
@magicgui(call_button="Quicksave")
254258
def save_widget():
@@ -301,9 +305,9 @@ def add_crop_sliders(self):
301305
)
302306

303307
if self.crop_labels:
304-
label_stack = self.labels
308+
label_stack = self.label
305309
labels_crop_layer = vw.add_labels(
306-
self.labels[:cropz, :cropy, :cropx],
310+
self.label[:cropz, :cropy, :cropx],
307311
name="cropped_labels",
308312
scale=self.label_layer.scale,
309313
)

0 commit comments

Comments
 (0)