@@ -14,11 +14,13 @@ class Helper(QWidget):
1414 def __init__ (self , viewer : "napari.viewer.Viewer" ):
1515 super ().__init__ ()
1616
17- # TODO change url after renaming, moving and redeploying docs
18- self .help_url = "https://c-achard.github.io/cellseg-annotator-test/" # "https://github.com/C-Achard/cellseg-annotator-test/tree/main"
17+ self .help_url = "https://adaptivemotorcontrollab.github.io/cellseg3d-docs/"
1918
2019 self .about_url = "https://wysscenter.ch/advances/3d-computer-vision-for-brain-analysis"
2120 self ._viewer = viewer
21+
22+ self .info_label = ui .make_label (f"napari-cellseg3d v.{ 0.01 } " , self )
23+
2224 self .btn1 = ui .make_button (
2325 "Help..." , lambda : ui .open_url (self .help_url )
2426 )
@@ -27,26 +29,6 @@ def __init__(self, viewer: "napari.viewer.Viewer"):
2729 )
2830 self .btnc = ui .make_button ("Close" , self .remove_from_viewer )
2931
30- ###################
31- ###################
32- ###################
33- ###################
34- # TODO test remove later
35- self .test = False # utils.ENABLE_TEST_MODE()
36-
37- if self .test :
38- self .dock = None
39-
40- self .epoch = ui .make_n_spinboxes (1 , 0 , 1000 , step = 2 )
41- self .epoch .setValue (0 )
42- self .epoch .setRange (0 , 1000 )
43- self .epoch .setSingleStep (2 )
44- self .epoch .valueChanged .connect (self .update_loss_plot )
45- ###################
46- ###################
47- ###################
48- ###################
49-
5032 self .build ()
5133
5234 def build (self ):
@@ -57,130 +39,14 @@ def build(self):
5739 self .btn2 ,
5840 self .btnc ,
5941 ]
42+ #################
6043 if self .test :
6144 widgets .append (self .epoch )
45+ #################
6246 ui .add_widgets (vbox , widgets )
6347 self .setLayout (vbox )
6448 # self.show()
6549 # self._viewer.window.add_dock_widget(self, name="Help/About...", area="right")
6650
6751 def remove_from_viewer (self ):
68- if self .test and self .dock is not None : # TODO remove
69- self ._viewer .window .remove_dock_widget (self .dock )
7052 self ._viewer .window .remove_dock_widget (self )
71-
72- ################
73- ################
74- ################
75- ################ TESTING
76- def update_loss_plot (self ):
77- if not self .test :
78- return
79- import matplotlib .pyplot as plt
80- import numpy as np
81-
82- epoch = self .epoch .value ()
83- length = epoch
84- loss = np .random .rand (length )
85- dice_metric = np .random .rand (int (length / 2 ))
86-
87- # print("plot upd")
88- # print(epoch)
89- # print(loss)
90- # print(dice_metric)
91- if epoch < 4 :
92- return
93- elif epoch == 4 :
94-
95- import matplotlib .pyplot as plt
96- import numpy as np
97- from matplotlib .backends .backend_qt5agg import (
98- FigureCanvasQTAgg as FigureCanvas ,
99- )
100- from matplotlib .figure import Figure
101-
102- bckgrd_color = (0 , 0 , 0 , 0 ) # '#262930'
103- with plt .style .context ("dark_background" ):
104-
105- self .canvas = FigureCanvas (Figure (figsize = (7 , 2.5 )))
106- # loss plot
107- self .train_loss_plot = self .canvas .figure .add_subplot (1 , 2 , 1 )
108- # dice metric validation plot
109- self .dice_metric_plot = self .canvas .figure .add_subplot (1 , 2 , 2 )
110-
111- self .canvas .figure .set_facecolor (bckgrd_color )
112- self .dice_metric_plot .set_facecolor (bckgrd_color )
113- self .train_loss_plot .set_facecolor (bckgrd_color )
114-
115- self .canvas .figure .tight_layout ()
116-
117- self .canvas .figure .subplots_adjust (
118- left = 0.1 ,
119- bottom = 0.2 ,
120- right = 0.95 ,
121- top = 0.9 ,
122- wspace = 0.2 ,
123- hspace = 0 ,
124- )
125-
126- self .canvas .setSizePolicy (QSizePolicy .Minimum , QSizePolicy .Minimum )
127-
128- # tab_index = self.addTab(self.canvas, "Loss plot")
129- # self.setCurrentIndex(tab_index)
130- self .dock = self ._viewer .window .add_dock_widget (
131- self .canvas , area = "bottom"
132- )
133- self .plot_loss (loss , dice_metric )
134- else :
135- with plt .style .context ("dark_background" ):
136-
137- self .train_loss_plot .cla ()
138- self .dice_metric_plot .cla ()
139-
140- self .plot_loss (loss , dice_metric )
141-
142- def plot_loss (self , loss , dice_metric ):
143- import matplotlib .pyplot as plt
144- import numpy as np
145-
146- if not self .test :
147- return
148- self .val_interval = 2
149-
150- # update loss
151- with plt .style .context ("dark_background" ):
152- self .train_loss_plot .set_title ("Epoch average loss" )
153- self .train_loss_plot .set_xlabel ("Epoch" )
154- self .train_loss_plot .set_ylabel ("Loss" )
155- x = [i + 1 for i in range (len (loss ))]
156- y = loss
157- self .train_loss_plot .plot (x , y )
158- # update metrics
159- x = [self .val_interval * (i + 1 ) for i in range (len (dice_metric ))]
160- y = dice_metric
161-
162- epoch_min = (np .argmax (y ) + 1 ) * self .val_interval
163- dice_min = np .max (y )
164-
165- self .dice_metric_plot .plot (x , y , zorder = 1 )
166- self .dice_metric_plot .set_title (
167- "Validation metric : Mean Dice coefficient"
168- )
169- self .dice_metric_plot .set_xlabel ("Epoch" )
170- self .dice_metric_plot .set_ylabel ("Dice" )
171-
172- self .dice_metric_plot .scatter (
173- epoch_min ,
174- dice_min ,
175- c = "r" ,
176- label = "Maximum Dice coeff." ,
177- zorder = 5 ,
178- )
179- self .dice_metric_plot .legend (
180- facecolor = "#262930" , loc = "lower right"
181- )
182- self .canvas .draw_idle ()
183- ##########################
184- ##########################
185- ##########################
186- ########################## END of testing
0 commit comments