base
BaseLightningModule(model, optimizer=None, lr_scheduler=None, lr_scheduler_interval='epoch')
¶
Bases: LightningModule
Base lightning module.
Parameters:
-
model
(
Module
) –Network Module used for extract features
-
optimizer
(
Optimizer | None
, default:None
) –optimizer of the training. If None a default Adam is used.
-
lr_scheduler
(
object | None
, default:None
) –lr scheduler. If None a default ReduceLROnPlateau is used.
Source code in quadra/modules/base.py
28 29 30 31 32 33 34 35 36 37 38 39 |
|
configure_optimizers()
¶
Get default optimizer if not passed a value.
Returns:
-
tuple[list[Any], list[dict[str, Any]]]
–optimizer and lr scheduler as Tuple containing a list of optimizers and a list of lr schedulers
Source code in quadra/modules/base.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
forward(x)
¶
Forward method Args: x: input tensor.
Returns:
-
Tensor
–model inference
Source code in quadra/modules/base.py
41 42 43 44 45 46 47 48 49 |
|
optimizer_zero_grad(epoch, batch_idx, optimizer, optimizer_idx=0)
¶
Redefine optimizer zero grad.
Source code in quadra/modules/base.py
74 75 76 |
|
SSLModule(model, criterion, classifier=None, optimizer=None, lr_scheduler=None, lr_scheduler_interval='epoch')
¶
Bases: BaseLightningModule
Base module for self supervised learning.
Parameters:
-
model
(
Module
) –Network Module used for extract features
-
criterion
(
Module
) –SSL loss to be applied
-
classifier
(
ClassifierMixin | None
, default:None
) –Standard sklearn classifiers
-
optimizer
(
Optimizer | None
, default:None
) –optimizer of the training. If None a default Adam is used.
-
lr_scheduler
(
object | None
, default:None
) –lr scheduler. If None a default ReduceLROnPlateau is used.
Source code in quadra/modules/base.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
calculate_accuracy(batch)
¶
Calculate accuracy on a batch of data.
Source code in quadra/modules/base.py
123 124 125 126 127 128 129 130 131 132 133 |
|
fit_estimator()
¶
Fit a classifier on the embeddings extracted from the current trained model.
Source code in quadra/modules/base.py
109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
SegmentationModel(model, loss_fun, optimizer=None, lr_scheduler=None)
¶
Bases: BaseLightningModule
Generic segmentation model.
Parameters:
-
model
(
Module
) –segmentation model to be used.
-
loss_fun
(
Callable
) –loss function to be used.
-
optimizer
(
Optimizer | None
, default:None
) –Optimizer to be used. Defaults to None.
-
lr_scheduler
(
object | None
, default:None
) –lr scheduler to be used. Defaults to None.
Source code in quadra/modules/base.py
177 178 179 180 181 182 183 184 185 |
|
compute_loss(pred_masks, target_masks)
¶
Compute loss Args: pred_masks: predicted masks target_masks: target masks.
Returns:
-
Tensor
–The computed loss
Source code in quadra/modules/base.py
216 217 218 219 220 221 222 223 224 225 226 227 |
|
forward(x)
¶
Forward method Args: x: input tensor.
Returns:
-
Tensor
–model inference
Source code in quadra/modules/base.py
187 188 189 190 191 192 193 194 195 196 |
|
predict_step(batch, batch_idx, dataloader_idx=None)
¶
Predict step.
Source code in quadra/modules/base.py
268 269 270 271 272 273 274 275 276 277 278 |
|
step(batch)
¶
Compute loss Args: batch: batch.
Returns:
Source code in quadra/modules/base.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
test_step(batch, batch_idx)
¶
Test step.
Source code in quadra/modules/base.py
255 256 257 258 259 260 261 262 263 264 265 266 |
|
training_step(batch, batch_idx)
¶
Training step.
Source code in quadra/modules/base.py
229 230 231 232 233 234 235 236 237 238 239 240 |
|
validation_step(batch, batch_idx)
¶
Validation step.
Source code in quadra/modules/base.py
242 243 244 245 246 247 248 249 250 251 252 253 |
|
SegmentationModelMulticlass(model, loss_fun, optimizer=None, lr_scheduler=None)
¶
Bases: SegmentationModel
Generic multiclass segmentation model.
Parameters:
-
model
(
Module
) –segmentation model to be used.
-
loss_fun
(
Callable
) –loss function to be used.
-
optimizer
(
Optimizer | None
, default:None
) –Optimizer to be used. Defaults to None.
-
lr_scheduler
(
object | None
, default:None
) –lr scheduler to be used. Defaults to None.
Source code in quadra/modules/base.py
291 292 293 294 295 296 297 298 |
|
step(batch)
¶
Compute step Args: batch: batch.
Returns:
Source code in quadra/modules/base.py
300 301 302 303 304 305 306 307 308 309 310 311 312 |
|