napari_cellseg3d.code_models.model_framework
Basic napari plugin framework for inference and training.
Classes:
| Name | Description |
|---|---|
ModelFramework |
A framework with buttons to use for loading images, labels, models, etc. for both inference and training. |
ModelFramework
Bases: BasePluginFolder
A framework with buttons to use for loading images, labels, models, etc. for both inference and training.
Methods:
| Name | Description |
|---|---|
__init__ |
Creates a plugin framework with the following elements. |
check_device_choice |
Checks the device choice in the UI and returns the corresponding torch device. |
create_dataset_dict_no_labs |
Creates unsupervised data dictionary for MONAI transforms and training. |
create_train_dataset_dict |
Creates data dictionary for MONAI transforms and training. |
display_status_report |
Adds a text log, a progress bar and a "save log" button on the left side of the viewer (usually when starting a worker). |
empty_cuda_cache |
Empties the cuda cache if the device is a cuda device. |
get_available_models |
Getter for module (class and functions) associated to currently selected model. |
get_device |
Tries to use the device specified by user and uses it for tensor operations. |
get_unsupervised_image_filepaths |
Returns a list of filepaths to images in the unsupervised images folder. |
save_log |
Saves the worker's log to disk at self.results_path when called. |
save_log_to_path |
Saves the worker log to a specific path. Cannot be used with connect. |
send_log |
Emit a signal to print in a Log. |
Attributes:
| Name | Type | Description |
|---|---|---|
available_models |
dict: dictionary of available models, with string as key for name in widget display |
|
weights_config |
str : path to custom weights defined by user |
|
worker |
Worker from model_workers.py, either inference or training |
Source code in napari_cellseg3d/code_models/model_framework.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
available_models
instance-attribute
available_models = config.MODEL_LIST
dict: dictionary of available models, with string as key for name in widget display
weights_config
instance-attribute
weights_config = config.WeightsInfo()
str : path to custom weights defined by user
worker
instance-attribute
worker = None
Worker from model_workers.py, either inference or training
__init__
__init__(viewer: Viewer, parent=None, loads_images=True, loads_labels=True, has_results=True)
Creates a plugin framework with the following elements.
-
A button to choose an image folder containing the images of a dataset (e.g. dataset/images)
-
A button to choose a label folder containing the labels of a dataset (e.g. dataset/labels)
-
A button to choose a results folder to save results in (e.g. dataset/inference_results)
-
A file extension choice to choose which file types to load in the data folders
-
A docked module with a log, a progress bar and a save button (see :py:func:
~display_status_report)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewer
|
Viewer
|
viewer to load the widget in |
required |
parent
|
parent QWidget |
None
|
|
loads_images
|
if True, will contain UI elements used to load napari image layers |
True
|
|
loads_labels
|
if True, will contain UI elements used to load napari label layers |
True
|
|
has_results
|
if True, will add UI to choose a results path |
True
|
Source code in napari_cellseg3d/code_models/model_framework.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
check_device_choice
check_device_choice()
Checks the device choice in the UI and returns the corresponding torch device.
Source code in napari_cellseg3d/code_models/model_framework.py
335 336 337 338 339 340 341 342 343 344 345 346 | |
create_dataset_dict_no_labs
create_dataset_dict_no_labs()
Creates unsupervised data dictionary for MONAI transforms and training.
Source code in napari_cellseg3d/code_models/model_framework.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
create_train_dataset_dict
create_train_dataset_dict()
Creates data dictionary for MONAI transforms and training.
Returns:
| Type | Description |
|---|---|
|
A dict with the following keys: "image", "label" |
Source code in napari_cellseg3d/code_models/model_framework.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
display_status_report
display_status_report()
Adds a text log, a progress bar and a "save log" button on the left side of the viewer (usually when starting a worker).
Source code in napari_cellseg3d/code_models/model_framework.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
empty_cuda_cache
empty_cuda_cache()
Empties the cuda cache if the device is a cuda device.
Source code in napari_cellseg3d/code_models/model_framework.py
362 363 364 365 366 367 | |
get_available_models
staticmethod
get_available_models()
Getter for module (class and functions) associated to currently selected model.
Source code in napari_cellseg3d/code_models/model_framework.py
303 304 305 306 | |
get_device
staticmethod
get_device(show=True)
Tries to use the device specified by user and uses it for tensor operations.
If not available, automatically discovers any cuda device. If none is available (CUDA not installed), uses cpu instead.
Source code in napari_cellseg3d/code_models/model_framework.py
348 349 350 351 352 353 354 355 356 357 358 359 360 | |
get_unsupervised_image_filepaths
get_unsupervised_image_filepaths()
Returns a list of filepaths to images in the unsupervised images folder.
Source code in napari_cellseg3d/code_models/model_framework.py
242 243 244 245 246 247 248 | |
save_log
save_log(do_timestamp=True)
Saves the worker's log to disk at self.results_path when called.
Source code in napari_cellseg3d/code_models/model_framework.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
save_log_to_path
save_log_to_path(path, do_timestamp=True)
Saves the worker log to a specific path. Cannot be used with connect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
path to save folder |
required |
do_timestamp
|
bool
|
whether to add a timestamp to the log name. Defaults to True. |
True
|
Source code in napari_cellseg3d/code_models/model_framework.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
send_log
send_log(text)
Emit a signal to print in a Log.
Source code in napari_cellseg3d/code_models/model_framework.py
128 129 130 131 | |