LodeSTAR#

class deeplay.applications.detection.lodestar.lodestar.LodeSTAR(*args, **kwargs)#

Bases: Application

Self-supervised object detection using LodeSTAR

Creates a trainable model for self-supervised object detection using the LodeSTAR method.

Should be trained on a dataset of crops of objects. The model will learn to detect objects in the crops and output the coordinates of the center of the object.

Parameters#

optimizer: Optimizer

Optimizer to use for training.

modelnn.Module, optional

Backbone model. Should return a tensor of shape (B, outputs + 1, H’, W’) where B is the batch size, outputs is the number of measures to predict, and H’ and W’ are the height and width of the output which do not have to match the input. If None, a default model will be used.

num_outputsint

Number of outputs from the model. Should be 2 for x and y coordinates.

transformsTransforms, optional

Set of transforms to apply to the input. If None, a default set of transforms will be used. These define the geometric transformations that the model will be consistent to.

n_transformsint

Number of transformed images to use for training. The model will be trained to be consistent across these.

between_lossCallable, optional

Loss function for between-image disagreement. If None, nn.L1Loss will be used.

within_lossCallable, optional

Loss function for within-image disagreement. If None, nn.L1Loss will be used.

between_loss_weightfloat

Weight for between-image disagreement loss.

within_loss_weightfloat

Weight for within-image disagreement loss.

Methods Summary

compute_loss(y_hat, inverse_fn)

detect(x[, alpha, beta, cutoff, mode])

Detects objects in a batch of images

detect_single(y_pred, weights[, alpha, ...])

Detects objects in a single image

find_local_maxima(pred, score[, cutoff, mode])

Finds the local maxima in a score-map, indicating detections

forward(x)

Same as torch.nn.Module.forward().

get_detection_score(pred, weights[, alpha, beta])

Calculates the detection score as weights^alpha * consistency^beta.

local_consistency(pred)

Calculate the consistency metric

normalize(weights)

on_train_end()

Called at the end of training before logger experiment is closed.

pooled(x[, mask])

Pooled output from model.

reduce(X, weights)

test_preprocess(batch)

train_preprocess(batch)

transform_data(batch)

val_preprocess(batch)

Methods Documentation

compute_loss(y_hat, inverse_fn)#
detect(x, alpha=0.5, beta=0.5, cutoff=0.97, mode='quantile')#

Detects objects in a batch of images

Parameters#

xarray-like

Input to model

alpha, beta: float

Geometric weight of the weight-map vs the consistenct metric for detection.

cutoff: float

Threshold for detection

mode: string

Mode for thresholding. Can be either “quantile” or “ratio” or “constant”. If “quantile”, then ratio defines the quantile of scores to accept. If “ratio”, then cutoff defines the ratio of the max score as threshhold. If constant, the cutoff is used directly as treshhold.

detect_single(y_pred, weights, alpha=0.5, beta=0.5, cutoff=0.97, mode='quantile')#

Detects objects in a single image

Parameters#

y_pred, weights: array-like

Output from model

alpha, beta: float

Geometric weight of the weight-map vs the consistenct metric for detection.

cutoff: float

Threshold for detection

mode: string

Mode for thresholding. Can be either “quantile” or “ratio” or “constant”. If “quantile”, then ratio defines the quantile of scores to accept. If “ratio”, then cutoff defines the ratio of the max score as threshhold. If constant, the cutoff is used directly as treshhold.

static find_local_maxima(pred, score, cutoff=0.9, mode='quantile')#

Finds the local maxima in a score-map, indicating detections

Parameters
pred, score: array-like

Output from model, score-map

cutoff, mode: float, string

Treshholding parameters. Mode can be either “quantile” or “ratio” or “constant”. If “quantile”, then ratio defines the quantile of scores to accept. If “ratio”, then cutoff defines the ratio of the max score as threshhold. If constant, the cutoff is used directly as treshhold.

forward(x)#

Same as torch.nn.Module.forward().

Args:

*args: Whatever you decide to pass into the forward method. **kwargs: Keyword arguments are also possible.

Return:

Your model’s output

classmethod get_detection_score(pred, weights, alpha=0.5, beta=0.5)#

Calculates the detection score as weights^alpha * consistency^beta.

Parameters#

pred, weights: array-like

Output from model

alpha, beta: float

Geometric weight of the weight-map vs the consistenct metric for detection.

static local_consistency(pred)#

Calculate the consistency metric

Parameters#

predarray-like

first output from model

normalize(weights)#
on_train_end() None#

Called at the end of training before logger experiment is closed.

pooled(x, mask=1)#

Pooled output from model.

Predict and pool the output from the model. Useful to acquire a single output from the model. Masking is supported by setting the mask to 0 where the output should be ignored.

Parameters#

xarray-like

Input to model

maskarray-like

Mask for pooling. Should be the same shape as the output from the model with a single channel.

reduce(X, weights)#
test_preprocess(batch)#
train_preprocess(batch)#
transform_data(batch)#
val_preprocess(batch)#