dann
The Domain Adversarial Neural Network (DANN) approach uses a domain discriminator trained on distinguishing the source and target features produced by a shared feature extractor. A Gradient Reversal Layer (GRL) is used to train the feature extractor on making its source and target outputs indistinguishable.
Source --> FeatEx --> Source Feats -----------> Regressor --> RUL Prediction
^ | |
| | v
Target -- --> Target Feats --> GRL --> DomainDisc --> Domain Prediction
It was originally introduced by Ganin et al. for image classification.
Used In
- da Costa et al. (2020). Remaining useful lifetime prediction via deep domain adaptation. Reliability Engineering & System Safety, 195, 106682. 10.1016/J.RESS.2019.106682
- Krokotsch et al. (2020). A Novel Evaluation Framework for Unsupervised Domain Adaption on Remaining Useful Lifetime Estimation. 2020 IEEE International Conference on Prognostics and Health Management (ICPHM). 10.1109/ICPHM49022.2020.9187058
DannApproach
Bases: AdaptionApproach
The DANN approach introduces a domain discriminator that is trained on distinguishing source and target features as a binary classification problem. The features are produced by a shared feature extractor. The loss in the domain discriminator is binary cross-entropy.
The regressor and domain discriminator need the same number of input units as the feature extractor has output units. The discriminator is not allowed to have an activation function on its last layer and needs to use only a single output neuron because BCEWithLogitsLoss is used.
Examples:
>>> from rul_adapt import model
>>> from rul_adapt import approach
>>> feat_ex = model.CnnExtractor(1, [16, 16, 1], 10, fc_units=16)
>>> reg = model.FullyConnectedHead(16, [1])
>>> disc = model.FullyConnectedHead(16, [8, 1], act_func_on_last_layer=False)
>>> dann = approach.DannApproach(1.0)
>>> dann.set_model(feat_ex, reg, disc)
domain_disc
property
The domain discriminator network.
__init__(dann_factor, loss_type='mae', rul_score_mode='phm08', evaluate_degraded_only=False, **optim_kwargs)
Create a new DANN approach.
The strength of the domain discriminator's influence on the feature
extractor is controlled by the dann_factor
. The higher it is, the stronger
the influence.
Possible options for the regression loss are mae
, mse
and rmse
.
The domain discriminator is set by the set_model
function together with the
feature extractor and regressor. For more information, see the approach module page.
For more information about the possible optimizer keyword arguments, see here.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dann_factor |
float
|
Strength of the domain DANN loss. |
required |
loss_type |
Literal['mae', 'mse', 'rmse']
|
Type of regression loss. |
'mae'
|
rul_score_mode |
Literal['phm08', 'phm12']
|
The mode for the val and test RUL score, either 'phm08' or 'phm12'. |
'phm08'
|
evaluate_degraded_only |
bool
|
Whether to only evaluate the RUL score on degraded samples. |
False
|
**optim_kwargs |
Any
|
Keyword arguments for the optimizer, e.g. learning rate. |
{}
|
configure_optimizers()
Configure an optimizer for the whole model.
forward(inputs)
Predict the RUL values for a batch of input features.
set_model(feature_extractor, regressor, domain_disc=None, *args, **kwargs)
Set the feature extractor, regressor, and domain discriminator for this approach.
The discriminator is not allowed to have an activation function on its last layer and needs to use only a single output neuron. It is wrapped by a DomainAdversarialLoss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature_extractor |
Module
|
The feature extraction network. |
required |
regressor |
Module
|
The RUL regression network. |
required |
domain_disc |
Optional[Module]
|
The domain discriminator network. |
None
|
test_step(batch, batch_idx, dataloader_idx)
Execute one test step.
The batch
argument is a list of two tensors representing features and
labels. A RUL prediction is made from the features and the validation RMSE
and RUL score are calculated. The metrics recorded for dataloader idx zero
are assumed to be from the source domain and for dataloader idx one from the
target domain. The metrics are written to the configured logger under the
prefix test
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch |
List[Tensor]
|
A list containing a feature and a label tensor. |
required |
batch_idx |
int
|
The index of the current batch. |
required |
dataloader_idx |
int
|
The index of the current dataloader (0: source, 1: target). |
required |
training_step(batch, batch_idx)
Execute one training step.
The batch
argument is a list of three tensors representing the source
features, source labels and target features. Both types of features are fed
to the feature extractor. Then the regression loss for the source domain and
the DANN loss between domains is computed. The regression, DANN and combined
loss are logged.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch |
List[Tensor]
|
A list of a source feature, source label and target feature tensors. |
required |
batch_idx |
int
|
The index of the current batch. |
required |
Returns: The combined loss.
validation_step(batch, batch_idx, dataloader_idx)
Execute one validation step.
The batch
argument is a list of two tensors representing features and
labels. A RUL prediction is made from the features and the validation RMSE
and RUL score are calculated. The metrics recorded for dataloader idx zero
are assumed to be from the source domain and for dataloader idx one from the
target domain. The metrics are written to the configured logger under the
prefix val
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch |
List[Tensor]
|
A list containing a feature and a label tensor. |
required |
batch_idx |
int
|
The index of the current batch. |
required |
dataloader_idx |
int
|
The index of the current dataloader (0: source, 1: target). |
required |