cassetta.models
Overview
Models are end-to-end, task-specific networks. They usually rely on a more generic backbone architecture.
| MODULE | DESCRIPTION |
|---|---|
segmentation |
Models for semantic segmentation |
registration |
Models for image registration |
make_model
Instantiate a model
A model can be:
- the name of a cassetta model, such as
"SegNet"; - the fully qualified path to a model, such as
"cassetta.models.ElasticRegNet", or"monai.networks.nets.ResNet"; - a
nn.Modulesubclass, such as [SegNet][cassetta.models.SegNet]; - an already instantiated
nn.Module, such as [SegNet(3, 1, 5)][cassetta.models.SegNet].
| PARAMETER | DESCRIPTION |
|---|---|
model |
Instantiated or non-instantiated model
TYPE:
|
*args |
Positional arguments pass to the model constructor
TYPE:
|
**kwargs |
Keyword arguments pass to the model constructor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
model
|
Instantiated model
TYPE:
|
Source code in cassetta/models/__init__.py
cassetta.models.segmentation
SegNet
SegNet(ndim, inp_channels, out_channels, kernel_size=3, activation='Softmax', backbone='UNet', opt_backbone=None)
Bases: LoadableMixin, Sequential
A generic segmentation network that works with any backbone
Diagram
flowchart LR
i["C"]:::i ---fx("Conv"):::w-->
fi["F"] ---b("Backbone"):::w -->
fo["F"] ---fk("Conv 1x1x1"):::w-->
l["K"] ---s(("σ")):::d-->
o["K"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
classDef n fill:none,stroke:none;
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output classes
TYPE:
|
kernel_size |
Kernel size of the initial feature extraction layer
TYPE:
|
activation |
Final activation function
TYPE:
|
backbone |
Generic backbone module. Can be already instantiated. Examples:
[
TYPE:
|
opt_backbone |
Parameters of the backbone (if backbone is not pre-instantiated)
TYPE:
|
Source code in cassetta/models/segmentation.py
predict_logits
Run the forward pass and return the logits (pre-softmax)
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Logits
TYPE:
|
Source code in cassetta/models/segmentation.py
cassetta.models.registration
ElasticRegNet
ElasticRegNet(ndim, symmetric=False, nb_steps=0, inp_channels=1, kernel_size=3, activation=None, backbone='UNet', opt_backbone=None)
Bases: LoadableMixin, Sequential
A generic pairwise nonlinear registration network that works with any backbone
Not tested yet -- do not use
Diagram
flowchart LR
subgraph "Prediction"
cat(("c")):::d-->
mf["C*2"] ---fx("Conv"):::w-->
fi["F"] ---b("Backbone"):::w -->
fo["F"] ---fk("Conv 1x1x1"):::w
end
mov["C"]:::i & fix["C"]:::i ---cat
fk --> o["D"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
classDef n fill:none,stroke:none;
flowchart LR
mf["(mov, fix)"]:::i ---p1("Prediction"):::w--> v1["D"]
fm["(fix, mov)"]:::i ---p2("Prediction"):::w--> v2["D"]
v1 & v2 ---minus(("-")):::d--> o["D"]:::o
p1 -.-|"shared weights"| p2
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
classDef n fill:none,stroke:none;
flowchart LR
mov["<b>mov</b>\nC"]:::i & fix["<b>fix</b>\nC"]:::i ---
pred("Prediction"):::w-->
vel["<b>velocity</b>\nD"] ---exp("Exp"):::d -->
flow["<b>flow</b>\nD"]
mov & flow ---w("Pull"):::d--> out["<b>moved</b>\nC"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
classDef n fill:none,stroke:none;
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
symmetric |
Make the network symmetric by averaging
TYPE:
|
nb_steps |
Number of scaling and squaring steps.
TYPE:
|
inp_channels |
Number of input channels, per image.
TYPE:
|
kernel_size |
Kernel size of the initial feature extraction layer
TYPE:
|
activation |
Final activation function
TYPE:
|
backbone |
Generic backbone module. Can be already instantiated. Examples:
[
TYPE:
|
opt_backbone |
Parameters of the backbone (if backbone is not pre-instantiated). Note that, unless user-defined, we set
TYPE:
|
Source code in cassetta/models/registration.py
forward
Predict the encoding of the displacement field
| PARAMETER | DESCRIPTION |
|---|---|
mov |
Moving image
TYPE:
|
fix |
Fixed image
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
vel
|
TYPE:
|
Source code in cassetta/models/registration.py
predict_flow
Predict the forward displacement field, used to warp mov to fix
| PARAMETER | DESCRIPTION |
|---|---|
mov |
Moving image
TYPE:
|
fix |
Fixed image
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
flow
|
Voxel displacement field
TYPE:
|
Source code in cassetta/models/registration.py
predict_flows
Predict the forward displacement field (used to warp mov to fix)
and thr backward displacement field (used to warp fix to mov)
| PARAMETER | DESCRIPTION |
|---|---|
mov |
Moving image
TYPE:
|
fix |
Fixed image
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
flow_forward
|
Forward voxel displacement field
TYPE:
|
flow_backward
|
Backward voxel displacement field
TYPE:
|
Source code in cassetta/models/registration.py
predict_moved
Predict the warped moving image
| PARAMETER | DESCRIPTION |
|---|---|
mov |
Moving image
TYPE:
|
fix |
Fixed image
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
moved
|
Moved image
TYPE:
|
Source code in cassetta/models/registration.py
predict_both_moved
Predict the warped moving image, and the warped fixed image.
| PARAMETER | DESCRIPTION |
|---|---|
mov |
Moving image
TYPE:
|
fix |
Fixed image
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
warped_mov
|
Moving image warped to fixed space
TYPE:
|
warped_fix
|
Fixed image warped to moving space
TYPE:
|