inference
darts_segmentation.inference
¶
Shared utilities for the inference modules.
create_patches
¶
create_patches(
tensor_tiles: torch.Tensor,
patch_size: int,
overlap: int,
return_coords: bool = False,
) -> torch.Tensor
Create patches from a tensor.
Parameters:
-
tensor_tiles
(torch.Tensor
) –The input tensor. Shape: (BS, C, H, W).
-
patch_size
(int
) –The size of the patches.
-
overlap
(int
) –The size of the overlap.
-
return_coords
(bool
, default:False
) –Whether to return the coordinates of the patches. Can be used for debugging. Defaults to False.
Returns:
Source code in darts-segmentation/src/darts_segmentation/inference.py
patch_coords
¶
patch_coords(
h: int, w: int, patch_size: int, overlap: int
) -> collections.abc.Generator[
tuple[int, int, int, int], None, None
]
Yield patch coordinates based on height, width, patch size and margin size.
Parameters:
-
h
(int
) –Height of the image.
-
w
(int
) –Width of the image.
-
patch_size
(int
) –Patch size.
-
overlap
(int
) –Margin size.
Yields:
-
tuple[int, int, int, int]
–tuple[int, int, int, int]: The patch coordinates y, x, patch_idx_y and patch_idx_x.
Source code in darts-segmentation/src/darts_segmentation/inference.py
predict_in_patches
¶
predict_in_patches(
model: torch.nn.Module,
tensor_tiles: torch.Tensor,
patch_size: int,
overlap: int,
batch_size: int,
reflection: int,
device: torch.device,
return_weights: bool = False,
) -> torch.Tensor
Predict on a tensor.
Parameters:
-
model
(torch.nn.Module
) –The model to use for prediction.
-
tensor_tiles
(torch.Tensor
) –The input tensor. Shape: (BS, C, H, W).
-
patch_size
(int
) –The size of the patches.
-
overlap
(int
) –The size of the overlap.
-
batch_size
(int
) –The batch size for the prediction, NOT the batch_size of input tiles. Tensor will be sliced into patches and these again will be infered in batches.
-
reflection
(int
) –Reflection-Padding which will be applied to the edges of the tensor.
-
device
(torch.device
) –The device to use for the prediction.
-
return_weights
(bool
, default:False
) –Whether to return the weights. Can be used for debugging. Defaults to False.
Returns:
Source code in darts-segmentation/src/darts_segmentation/inference.py
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 |
|