Skip to content

Commit 2fc88d0

Browse files
committed
Rebase + fixes
- Rebased on rc3 main - Removed debug prints - Added tqdm to reqs - Added more error handling for stats to csv (region.axis_minor_length value errors)
1 parent 30387e9 commit 2fc88d0

File tree

6 files changed

+40
-26
lines changed

6 files changed

+40
-26
lines changed

napari_cellseg3d/interface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,10 @@ def __init__(
496496
fixed: Optional[bool] = True,
497497
):
498498
"""Args:
499-
min (Optional[int]): minimum value, defaults to 0
500-
max (Optional[int]): maximum value, defaults to 10
501-
default (Optional[int]): default value, defaults to 0
502-
step (Optional[int]): step value, defaults to 1
499+
min (Optional[float]): minimum value, defaults to 0
500+
max (Optional[float]): maximum value, defaults to 10
501+
default (Optional[float]): default value, defaults to 0
502+
step (Optional[float]): step value, defaults to 1
503503
parent: parent widget, defaults to None
504504
fixed (bool): if True, sets the QSizePolicy of the spinbox to Fixed"""
505505

napari_cellseg3d/model_instance_seg.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,19 @@ def volume_stats(volume_image):
194194
"""
195195

196196
properties = regionprops(volume_image)
197-
number_objects = np.amax(volume_image)
198197

199-
sphericity_va = []
200-
sphericity_ax = [
201-
sphericity_axis(
202-
region.axis_major_length * 0.5, region.axis_minor_length * 0.5
203-
)
204-
for region in properties
205-
]
198+
# sphericity_va = []
199+
def sphericity(region):
200+
try:
201+
return sphericity_axis(
202+
region.axis_major_length * 0.5, region.axis_minor_length * 0.5
203+
)
204+
except ValueError:
205+
return (
206+
np.nan
207+
) # FIXME better way ? inconsistent errors in region.axis_minor_length
208+
209+
sphericity_ax = [sphericity(region) for region in properties]
206210
# for region in properties:
207211
# object = (volume_image == region.label).transpose(1, 2, 0)
208212
# verts, faces, _, values = marching_cubes(

napari_cellseg3d/model_workers.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from pathlib import Path
44
import importlib.util
55
from typing import Optional
6-
import warnings
76

87
import numpy as np
98
from tifffile import imwrite
@@ -112,7 +111,7 @@ def show_progress(count, block_size, total_size):
112111
pretrained_folder_path, model_weights_filename
113112
)
114113
if os.path.exists(check_path):
115-
message = f"Weight file {model_weights_filename} already exists, skipping download step"
114+
message = f"Weight file {model_weights_filename} already exists, skipping download"
116115
if self.log_widget is not None:
117116
self.log_widget.print_and_log(message, printing=False)
118117
print(message)
@@ -240,7 +239,6 @@ def __init__(
240239
self.layer = layer
241240
self.images_filepaths = images_filepaths
242241

243-
244242
"""These attributes are all arguments of :py:func:~inference, please see that for reference"""
245243

246244
self.downloader = WeightsDownloader()
@@ -362,8 +360,8 @@ def load_layer(self):
362360
dims_check = volume.shape
363361
self.log("\nChecking dimensions...")
364362
pad = utils.get_padding_dim(dims_check)
365-
print(volume.shape)
366-
print(volume.dtype)
363+
# print(volume.shape)
364+
# print(volume.dtype)
367365
load_transforms = Compose(
368366
[
369367
ToTensor(),
@@ -534,10 +532,14 @@ def inference_on_list(self, inf_data, i, model, post_process_transforms):
534532

535533
def stats_csv(self, instance_labels):
536534
if self.stats_to_csv:
535+
# try:
537536
data_dict = volume_stats(
538537
instance_labels
539538
) # TODO test with area mesh function
540539
return data_dict
540+
# except ValueError as e:
541+
# self.log(f"Error occurred during stats computing : {e}")
542+
# return None
541543
else:
542544
return None
543545

@@ -677,7 +679,6 @@ def inference(self):
677679
if self.model_dict["name"] == "SegResNet":
678680
model = self.model_dict["class"].get_net()(
679681
input_image_size=[
680-
681682
dims,
682683
dims,
683684
dims,
@@ -751,7 +752,7 @@ def inference(self):
751752

752753
if is_layer and is_folder:
753754
raise ValueError(
754-
"Both a layer and a folder have been specified, please specifiy only one of the two. Aborting."
755+
"Both a layer and a folder have been specified, please specify only one of the two. Aborting."
755756
)
756757
elif is_folder:
757758
inference_loader = self.load_folder()
@@ -767,7 +768,7 @@ def inference(self):
767768
##################
768769
elif is_layer:
769770
input_image = self.load_layer()
770-
print(input_image.shape)
771+
# print(input_image.shape)
771772

772773
else:
773774
raise ValueError("No data has been provided. Aborting.")

napari_cellseg3d/plugin_model_inference.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import warnings
32

43
import napari
@@ -220,8 +219,10 @@ def __init__(self, viewer: "napari.viewer.Viewer"):
220219
"Image size on which the SegResNet has been trained (default : 128)"
221220
)
222221

223-
thresh_desc = "Thresholding : all values in the image below the chosen probability" \
224-
" threshold will be set to 0, and all others to 1."
222+
thresh_desc = (
223+
"Thresholding : all values in the image below the chosen probability"
224+
" threshold will be set to 0, and all others to 1."
225+
)
225226
self.thresholding_checkbox.setToolTip(thresh_desc)
226227
self.thresholding_count.setToolTip(thresh_desc)
227228
self.window_infer_box.setToolTip(
@@ -712,14 +713,18 @@ def on_yield(data, widget):
712713

713714
viewer = widget._viewer
714715

715-
widget.progress.setValue(100 * image_id // total)
716+
pbar_value = image_id // total
717+
if image_id == 0:
718+
pbar_value = 1
719+
720+
widget.progress.setValue(100 * pbar_value)
716721

717722
if widget.show_res and image_id <= widget.show_res_nbr:
718723

719724
zoom = widget.zoom
720725

721726
# print(data["original"].shape)
722-
print(data["result"].shape)
727+
# print(data["result"].shape)
723728

724729
viewer.dims.ndisplay = 3
725730
viewer.scale_bar.visible = True

napari_cellseg3d/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def sphericity_axis(semi_major, semi_minor):
6767
a = semi_major
6868
b = semi_minor
6969

70-
root = (a**2 - b**2) ** (1 / 2)
70+
root = np.sqrt(a**2 - b**2)
7171
try:
7272
result = (
7373
2
@@ -77,6 +77,9 @@ def sphericity_axis(semi_major, semi_minor):
7777
except ZeroDivisionError:
7878
print("Zero division in sphericity calculation was replaced by 0")
7979
result = 0
80+
except ValueError as e:
81+
print(f"Error encountered in calculation : {e}")
82+
result = "Error in calculation"
8083

8184
return result
8285

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ install_requires =
5050
tifffile>=2022.2.9
5151
imageio-ffmpeg>=0.4.5
5252
torch>=1.11
53+
tqdm
5354
monai>=0.9.0
5455
nibabel
5556
scikit-image

0 commit comments

Comments
 (0)