deeptrees.model
The following flavors of models inputs are possible with DeepTrees: - 4-channel (RGBi). - 5-channel (RGBi+NDVI). See sample config –> https://codebase.helmholtz.cloud/taimur.khan/DeepTrees/-/blob/main/config/train/train_halle.yaml - 7-channel (RGBi+NDVI+GCI+Hue). See sample config –> https://codebase.helmholtz.cloud/taimur.khan/DeepTrees/-/blob/main/config/train/train_halle_7ch.yaml
deeptrees.model.deeptrees_model
deeptrees.model.distance_model
- class deeptrees.model.distance_model.DistanceModel(in_channels, architecture='Unet', backbone='resnet18', encoder_weights=None)[source]
Bases:
LightningModule- __init__(in_channels, architecture='Unet', backbone='resnet18', encoder_weights=None)[source]
Distance transform model
The model is the second part in the tree crown delineation model.
- Parameters:
in_channels (int) – Number of input channels
architecture (str) – One of ‘Unet, Unet++, Linknet, FPN, PSPNet, PAN, DeepLabV3, DeepLabV3+’
backbone (str) – One of the backbones supported by the [pytorch segmentation models package](https://github.com/qubvel/segmentation_models.pytorch)
encoder_weights (str | None) – Encoder pretrained weights to load in SMP (e.g. “imagenet”). Use None to skip.
- forward(img, mask_and_outline, from_logits=False)[source]
Distance transform forward pass
- Parameters:
img (torch.Tensor) – Input image
mask_and_outline (torch.Tensor) – Tensor containing mask and outlines concatenated in channel dimension, coming from the first sub-network.
from_logits (bool) – If set to true, sigmoid activation is applied to the mask_and_outline tensor.
- Returns:
Model output of dimension N1HW
deeptrees.model.inference_model
- class deeptrees.model.inference_model.InferenceModel(model)[source]
Bases:
ModuleJust a wrapper to apply the sigmoid activation to mask and outlines during inference..
- __init__(model)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]
Perform a forward pass through the model. :type x: torch.Tensor :param x: Input tensor to the model. :type x: torch.Tensor
- Returns:
If the model output contains two elements, returns a tuple (y, metric) where y is the output tensor with sigmoid activation applied to the first two columns, and metric is the second element of the output. If the model output contains only one element, returns y with sigmoid activation applied to the first two columns.
- Return type:
torch.Tensor or tuple
deeptrees.model.segmentation_model
- class deeptrees.model.segmentation_model.SegmentationModel(in_channels=4, architecture='Unet', backbone='resnet18', encoder_weights=None)[source]
Bases:
LightningModule- __init__(in_channels=4, architecture='Unet', backbone='resnet18', encoder_weights=None)[source]
Segmentation model
A segmentation model which takes an input image and returns a foreground / background mask along with object outlines.
- Parameters:
in_channels (int) – Number of input channels
architecture (str) – One of ‘Unet, Unet++, Linknet, FPN, PSPNet, PAN, DeepLabV3, DeepLabV3+’
backbone (str) – One of the backbones supported by the [pytorch segmentation models package](https://github.com/qubvel/segmentation_models.pytorch)
encoder_weights (str | None) – Encoder pretrained weights to load in SMP (e.g. “imagenet”). Use None to skip.
between. (one means only the mask loss is relevant. Linear in)