Shortcuts

Adversarial Entropy Minimization (ADVENT)

class dalib.adaptation.segmentation.advent.Discriminator(num_classes, ndf=64)[source]

Domain discriminator model from ADVENT: Adversarial Entropy Minimization for Domain Adaptation in Semantic Segmentation (CVPR 2019)

Distinguish pixel-by-pixel whether the input predictions come from the source domain or the target domain. The source domain label is 1 and the target domain label is 0.

Parameters
  • num_classes (int) – num of classes in the predictions

  • ndf (int) – dimension of the hidden features

Shape:
  • Inputs: \((minibatch, C, H, W)\) where \(C\) is the number of classes

  • Outputs: \((minibatch, 1, H, W)\)

class dalib.adaptation.segmentation.advent.DomainAdversarialEntropyLoss(discriminator)[source]

The Domain Adversarial Entropy Loss

Minimizing entropy with adversarial learning through training a domain discriminator.

Parameters

domain_discriminator (torch.nn.Module) – A domain discriminator object, which predicts the domains of predictions. Its input shape is \((minibatch, C, H, W)\) and output shape is \((minibatch, 1, H, W)\)

Inputs:
  • logits (tensor): logits output of segmentation model

  • domain_label (str, optional): whether the data comes from source or target. Choices: [‘source’, ‘target’]. Default: ‘source’

Shape:
  • logits: \((minibatch, C, H, W)\) where \(C\) means the number of classes

  • Outputs: scalar.

Examples:

>>> B, C, H, W = 2, 19, 512, 512
>>> discriminator = Discriminator(num_classes=C)
>>> dann = DomainAdversarialEntropyLoss(discriminator)
>>> # logits output on source domain and target domain
>>> y_s, y_t = torch.randn(B, C, H, W), torch.randn(B, C, H, W)
>>> loss = 0.5 * (dann(y_s, "source") + dann(y_t, "target"))
eval()[source]

Sets the module in evaluation mode. In the training mode, all the parameters in discriminator will be set requires_grad=False.

This is equivalent with self.train(False).

forward(logits, domain_label='source')[source]
train(mode=True)[source]

Sets the discriminator in training mode. In the training mode, all the parameters in discriminator will be set requires_grad=True.

Parameters

mode (bool) – whether to set training mode (True) or evaluation mode (False). Default: True.

Docs

Access comprehensive documentation for Transfer Learning Library

View Docs

Tutorials

Get started for transfer learning

Get Started