dreams.models.optimization package

Submodules

dreams.models.optimization.losses_metrics module

class dreams.models.optimization.losses_metrics.CosSimLoss

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(inputs, targets)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class dreams.models.optimization.losses_metrics.FingerprintMetrics(prefix=None, device=None)

Bases: MetricCollection

TODO: threshold argument for binary metrics

Initialize internal Module state, shared by both nn.Module and ScriptModule.

class dreams.models.optimization.losses_metrics.FocalLoss(gamma, alpha=None, binary=False, return_softmax_out=False)

Bases: Module

https://arxiv.org/pdf/1708.02002v2.pdf :param alpha: A vector summing up to one for multi-class classification, a positive-class scalar from (0, 1)

range for binary classification.

Parameters:

return_softmax_out – If True, the return value of forward method is (loss, softmax probabilities) instead of loss.

forward(inputs, targets)
Parameters:
  • inputs – Class logits of shape (…, num_classes).

  • targets – One-hot class labels (…, num_classes).

Returns:

Unreduced focal loss of shape (…).

class dreams.models.optimization.losses_metrics.SmoothIoULoss

Bases: Module

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(inputs, targets, smooth=1)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

dreams.models.optimization.samplers module

class dreams.models.optimization.samplers.MaxVarBatchSampler(dataset: Dataset, max_var_features: ndarray, batch_size: int, swap_width=5)

Bases: BatchSampler

dreams.models.optimization.schedulers module

class dreams.models.optimization.schedulers.NoamScheduler(optimizer, warmup_steps)

Bases: _LRScheduler

Implements the Noam Learning rate schedule. This corresponds to increasing the learning rate linearly for the first warmup_steps training steps, and decreasing it thereafter proportionally to the inverse square root of the step number, scaled by the inverse square root of the dimensionality of the model. warmup_steps: The number of steps to linearly increase the learning rate.

get_lr()

Module contents