Skip to content

Commit 9c9f8a1

Browse files
committed
bugfix open_file_dialog import
1 parent b8a192c commit 9c9f8a1

File tree

11 files changed

+64
-37
lines changed

11 files changed

+64
-37
lines changed

src/napari_cellseg_annotator/interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
from qtpy.QtCore import QUrl
21
from qtpy.QtCore import Qt
2+
from qtpy.QtCore import QUrl
33
from qtpy.QtGui import QDesktopServices
44
from qtpy.QtWidgets import QFileDialog
55
from qtpy.QtWidgets import QGridLayout
66
from qtpy.QtWidgets import QGroupBox
77
from qtpy.QtWidgets import QLabel
8-
from qtpy.QtWidgets import QSpinBox
98
from qtpy.QtWidgets import QLayout
109
from qtpy.QtWidgets import QPushButton
1110
from qtpy.QtWidgets import QScrollArea
1211
from qtpy.QtWidgets import QSizePolicy
12+
from qtpy.QtWidgets import QSpinBox
1313
from qtpy.QtWidgets import QVBoxLayout
1414
from qtpy.QtWidgets import QWidget
1515

src/napari_cellseg_annotator/model_framework.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
from qtpy.QtWidgets import QTabWidget
1515

1616
# local
17-
from napari_cellseg_annotator import utils
1817
from napari_cellseg_annotator import interface as ui
18+
from napari_cellseg_annotator import utils
1919
from napari_cellseg_annotator.log_utility import Log
20-
from napari_cellseg_annotator.models import TRAILMAP_test as TMAP
2120
from napari_cellseg_annotator.models import model_SegResNet as SegResNet
2221
from napari_cellseg_annotator.models import model_VNet as VNet
22+
from napari_cellseg_annotator.models import TRAILMAP_test as TMAP
2323

2424
warnings.formatwarning = utils.format_Warning
2525

src/napari_cellseg_annotator/model_instance_seg.py

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
from __future__ import print_function, division
1+
from __future__ import division
2+
from __future__ import print_function
3+
24
import os
3-
from dask_image.imread import imread
4-
from PIL import Image
55

66
import numpy as np
7+
from dask_image.imread import imread
8+
from PIL import Image
79
from skimage.measure import label
810
from skimage.morphology import remove_small_objects
911
from skimage.segmentation import watershed
1012
from skimage.transform import resize
1113

1214

13-
def binary_connected(volume, thres=0.5, thres_small=3, scale_factors=(1.0, 1.0, 1.0)):
15+
def binary_connected(
16+
volume, thres=0.5, thres_small=3, scale_factors=(1.0, 1.0, 1.0)
17+
):
1418
r"""Convert binary foreground probability maps to instance masks via
1519
connected-component labeling.
1620
@@ -21,20 +25,35 @@ def binary_connected(volume, thres=0.5, thres_small=3, scale_factors=(1.0, 1.0,
2125
scale_factors (tuple): scale factors for resizing in :math:`(Z, Y, X)` order. Default: (1.0, 1.0, 1.0)
2226
"""
2327
semantic = volume[0]
24-
foreground = (semantic > int(255 * thres))
28+
foreground = semantic > int(255 * thres)
2529
segm = label(foreground)
2630
segm = remove_small_objects(segm, thres_small)
2731

2832
if not all(x == 1.0 for x in scale_factors):
29-
target_size = (int(semantic.shape[0] * scale_factors[0]),
30-
int(semantic.shape[1] * scale_factors[1]),
31-
int(semantic.shape[2] * scale_factors[2]))
32-
segm = resize(segm, target_size, order=0, anti_aliasing=False, preserve_range=True)
33+
target_size = (
34+
int(semantic.shape[0] * scale_factors[0]),
35+
int(semantic.shape[1] * scale_factors[1]),
36+
int(semantic.shape[2] * scale_factors[2]),
37+
)
38+
segm = resize(
39+
segm,
40+
target_size,
41+
order=0,
42+
anti_aliasing=False,
43+
preserve_range=True,
44+
)
3345

3446
return segm
3547

3648

37-
def binary_watershed(volume, thres1=0.9, thres2=0.3, thres_small=3, scale_factors=(1.0, 1.0, 1.0), seed_thres=3):
49+
def binary_watershed(
50+
volume,
51+
thres1=0.9,
52+
thres2=0.3,
53+
thres_small=3,
54+
scale_factors=(1.0, 1.0, 1.0),
55+
seed_thres=3,
56+
):
3857
r"""Convert binary foreground probability maps to instance masks via
3958
watershed segmentation algorithm.
4059
@@ -58,10 +77,18 @@ def binary_watershed(volume, thres1=0.9, thres2=0.3, thres_small=3, scale_factor
5877
segm = remove_small_objects(segm, thres_small)
5978

6079
if not all(x == 1.0 for x in scale_factors):
61-
target_size = (int(semantic.shape[0] * scale_factors[0]),
62-
int(semantic.shape[1] * scale_factors[1]),
63-
int(semantic.shape[2] * scale_factors[2]))
64-
segm = resize(segm, target_size, order=0, anti_aliasing=False, preserve_range=True)
80+
target_size = (
81+
int(semantic.shape[0] * scale_factors[0]),
82+
int(semantic.shape[1] * scale_factors[1]),
83+
int(semantic.shape[2] * scale_factors[2]),
84+
)
85+
segm = resize(
86+
segm,
87+
target_size,
88+
order=0,
89+
anti_aliasing=False,
90+
preserve_range=True,
91+
)
6592

6693
return segm
6794

@@ -89,12 +116,16 @@ def write_tiff_stack(vol, fname):
89116
y_pred = y_pred.astype("uint8")
90117

91118
# Run post process
92-
output_watershed_path = base_path + "/data/testing/instance-segmentation-w.tiff"
93-
output_connected_path = base_path + "/data/testing/instance-segmentation-c.tiff"
119+
output_watershed_path = (
120+
base_path + "/data/testing/instance-segmentation-w.tiff"
121+
)
122+
output_connected_path = (
123+
base_path + "/data/testing/instance-segmentation-c.tiff"
124+
)
94125

95126
bw_result = binary_watershed(y_pred)
96127
bc_result = binary_connected(y_pred)
97128

98129
# Save instance predictions
99130
write_tiff_stack(bw_result, output_watershed_path)
100-
write_tiff_stack(bc_result, output_connected_path)
131+
write_tiff_stack(bc_result, output_connected_path)

src/napari_cellseg_annotator/model_workers.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
import numpy as np
66
import torch
7+
from monai.data import CacheDataset
78
from monai.data import DataLoader
89
from monai.data import Dataset
910
from monai.data import decollate_batch
1011
from monai.data import pad_list_data_collate
1112
from monai.data import PatchDataset
12-
from monai.data import CacheDataset
1313
from monai.inferers import sliding_window_inference
1414
from monai.metrics import DiceMetric
1515
from monai.transforms import AsDiscrete
@@ -100,7 +100,7 @@ def __init__(
100100
"""
101101

102102
super().__init__(self.inference)
103-
self._signals = LogSignal() # add custom signals
103+
self._signals = LogSignal() # add custom signals
104104
self.log_signal = self._signals.log_signal
105105
###########################################
106106
###########################################
@@ -554,10 +554,7 @@ def train(self):
554554
transform=Compose(load_single_images, train_transforms),
555555
)
556556
print("Cache dataset : val")
557-
val_ds = CacheDataset(
558-
data=val_files,
559-
transform=load_single_images
560-
)
557+
val_ds = CacheDataset(data=val_files, transform=load_single_images)
561558
print("Dataloader")
562559
train_loader = DataLoader(
563560
train_ds,

src/napari_cellseg_annotator/plugin_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from qtpy.QtWidgets import QSizePolicy
88
from qtpy.QtWidgets import QWidget
99

10-
from napari_cellseg_annotator import utils
1110
from napari_cellseg_annotator import interface as ui
1211

1312

@@ -90,7 +89,7 @@ def show_filetype_choice(self):
9089

9190
def show_file_dialog(self):
9291
"""Open file dialog and process path depending on single file/folder loading behaviour"""
93-
f_or_dir_name = utils.open_file_dialog(
92+
f_or_dir_name = ui.open_file_dialog(
9493
self, self._default_path, self.file_handling_box.isChecked()
9594
)
9695
if not self.file_handling_box.isChecked():

src/napari_cellseg_annotator/plugin_crop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from qtpy.QtWidgets import QVBoxLayout
1414
from tifffile import imwrite
1515

16-
from napari_cellseg_annotator import utils
1716
from napari_cellseg_annotator import interface as ui
17+
from napari_cellseg_annotator import utils
1818
from napari_cellseg_annotator.plugin_base import BasePlugin
1919

2020
DEFAULT_CROP_SIZE = 64

src/napari_cellseg_annotator/plugin_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from qtpy.QtWidgets import QWidget
88

99
# local
10-
from napari_cellseg_annotator import utils
1110
from napari_cellseg_annotator import interface as ui
11+
from napari_cellseg_annotator import utils
1212

1313

1414
class Helper(QWidget):

src/napari_cellseg_annotator/plugin_model_inference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from qtpy.QtWidgets import QWidget
1212

1313
# local
14-
from napari_cellseg_annotator import utils
1514
from napari_cellseg_annotator import interface as ui
15+
from napari_cellseg_annotator import utils
1616
from napari_cellseg_annotator.model_framework import ModelFramework
1717
from napari_cellseg_annotator.model_workers import InferenceWorker
1818

src/napari_cellseg_annotator/plugin_model_training.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
from monai.losses import FocalLoss
1818
from monai.losses import GeneralizedDiceLoss
1919
from monai.losses import TverskyLoss
20-
from qtpy.QtWidgets import QCheckBox
2120

2221
# Qt
22+
from qtpy.QtWidgets import QCheckBox
2323
from qtpy.QtWidgets import QComboBox
2424
from qtpy.QtWidgets import QLabel
2525
from qtpy.QtWidgets import QProgressBar
2626
from qtpy.QtWidgets import QSizePolicy
2727
from qtpy.QtWidgets import QSpinBox
2828

2929
# local
30-
from napari_cellseg_annotator import utils
3130
from napari_cellseg_annotator import interface as ui
31+
from napari_cellseg_annotator import utils
3232
from napari_cellseg_annotator.model_framework import ModelFramework
3333
from napari_cellseg_annotator.model_workers import TrainingWorker
3434

src/napari_cellseg_annotator/plugin_review.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from qtpy.QtWidgets import QSizePolicy
1414
from qtpy.QtWidgets import QVBoxLayout
1515

16-
from napari_cellseg_annotator import utils
1716
from napari_cellseg_annotator import interface as ui
17+
from napari_cellseg_annotator import utils
1818
from napari_cellseg_annotator.launch_review import launch_review
1919
from napari_cellseg_annotator.plugin_base import BasePlugin
2020

@@ -90,7 +90,8 @@ def build(self):
9090
data_group_w, data_group_l = ui.make_group("Data")
9191

9292
data_group_l.addWidget(
93-
ui.combine_blocks(self.filetype_choice, self.file_handling_box), alignment = ui.LEFT_AL
93+
ui.combine_blocks(self.filetype_choice, self.file_handling_box),
94+
alignment=ui.LEFT_AL,
9495
)
9596
self.filetype_choice.setVisible(False)
9697

0 commit comments

Comments
 (0)