napari_cellseg3d.code_models.models.wnet.soft_Ncuts
Implementation of a 3D Soft N-Cuts loss based on https://arxiv.org/abs/1711.08506 and https://ieeexplore.ieee.org/document/868688.
The implementation was adapted and approximated to reduce computational and memory cost. This faster version was proposed on https://github.com/fkodom/wnet-unsupervised-image-segmentation.
Classes:
| Name | Description |
|---|---|
SoftNCutsLoss |
Implementation of a 3D Soft N-Cuts loss based on https://arxiv.org/abs/1711.08506 and https://ieeexplore.ieee.org/document/868688. |
SoftNCutsLoss
Bases: Module
Implementation of a 3D Soft N-Cuts loss based on https://arxiv.org/abs/1711.08506 and https://ieeexplore.ieee.org/document/868688.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_shape
|
(H, W, D)
|
shape of the images as a tuple. |
required |
intensity_sigma
|
scalar
|
scale of the gaussian kernel of pixels brightness. |
required |
spatial_sigma
|
scalar
|
scale of the gaussian kernel of pixels spacial distance. |
required |
radius
|
scalar
|
radius of pixels for which we compute the weights |
None
|
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the Soft N-Cuts loss. |
forward |
Forward pass of the Soft N-Cuts loss. |
gaussian_kernel |
Computes the Gaussian kernel. |
Source code in napari_cellseg3d/code_models/models/wnet/soft_Ncuts.py
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 | |
__init__
__init__(data_shape, device, intensity_sigma, spatial_sigma, radius=None)
Initialize the Soft N-Cuts loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_shape
|
(H, W, D)
|
shape of the images as a tuple. |
required |
device
|
device
|
device on which the loss is computed. |
required |
intensity_sigma
|
scalar
|
scale of the gaussian kernel of pixels brightness. |
required |
spatial_sigma
|
scalar
|
scale of the gaussian kernel of pixels spacial distance. |
required |
radius
|
scalar
|
radius of pixels for which we compute the weights |
None
|
Source code in napari_cellseg3d/code_models/models/wnet/soft_Ncuts.py
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 | |
forward
forward(labels, inputs)
Forward pass of the Soft N-Cuts loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Tensor
|
Tensor of shape (N, K, H, W, D) containing the predicted class probabilities for each pixel. |
required |
inputs
|
Tensor
|
Tensor of shape (N, C, H, W, D) containing the input images. |
required |
Returns:
| Type | Description |
|---|---|
|
The Soft N-Cuts loss of shape (N,). |
Source code in napari_cellseg3d/code_models/models/wnet/soft_Ncuts.py
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 | |
gaussian_kernel
gaussian_kernel(radius, sigma)
Computes the Gaussian kernel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
int
|
The radius of the kernel. |
required |
sigma
|
float
|
The standard deviation of the Gaussian distribution. |
required |
Returns:
| Type | Description |
|---|---|
|
The Gaussian kernel of shape (1, 1, 2radius+1, 2radius+1, 2*radius+1). |
Source code in napari_cellseg3d/code_models/models/wnet/soft_Ncuts.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |