Library of modular Domain Generalization
Project description
DomainLab: modular python package for training domain invariant neural networks
Distribution shifts, domain generalization and DomainLab
Neural networks trained using data from a specific distribution (domain) usually fails to generalize to novel distributions (domains). Domain generalization aims at learning domain invariant features by utilizing data from multiple domains (data sites, corhorts, batches, vendors) so the learned feature can generalize to new unseen domains (distributions).
DomainLab is a software platform with state-of-the-art domain generalization algorithms implemented, designed by maximal decoupling of different software components thus enhances maximal code reuse.
As an input to the software, the user need to provide
- the neural network to be trained for the task (e.g. classification)
- task specification which contains dataset(s) from domain(s).
DomainLab decouples the following concepts or objects:
- neural network: a map from the input data to the feature space and output (e.g. decision variable).
- model: structural risk in the form of $\ell() + \mu R()$ where $\ell()$ is the task specific empirical loss (e.g. cross entropy for classification task) and $R()$ is the penalty loss for inter-domain alignment (domain invariant regularization).
- trainer: an object that guides the data flow to model and append further domain invariant losses.
DomainLab makes it possible to combine models with models, trainers with models, and trainers with trainers in a decorator pattern like line of code Trainer A(Trainer B(Model C(Model D(network E), network E, network F)))
which correspond to $\ell() + \mu_a R_a() + \mu_b R_b + \mu_c R_c() + \mu_d R_d()$, where Model C and Model D share neural network E, but Model C has an extra neural network F.
We offer detailed documentation on how these models and trainers work in our documentation page: https://marrlab.github.io/DomainLab/
Getting started
Installation
For development version in Github, see Installation and Dependencies handling
We also offer a PyPI version here https://pypi.org/project/domainlab/ which one could install via pip install domainlab
and it is recommended to create a virtual environment for it.
Task specification
In DomainLab, a task is a container for datasets from different domains. See detail in Task Specification
Example and usage
Either clone this repo and use command line
python main_out.py -c ./examples/conf/vlcs_diva_mldg_dial.yaml
where the configuration file below can be downloaded here
te_d: caltech # domain name of test domain
tpath: examples/tasks/task_vlcs.py # python file path to specify the task
bs: 2 # batch size
model: diva # specify model
epos: 1 # number of epochs
trainer: mldg,dial # combine trainer MLDG and DIAL
gamma_y: 700000.0 # hyperparameter of diva
gamma_d: 100000.0 # hyperparameter of diva
npath: examples/nets/resnet.py # neural network for class classification
npath_dom: examples/nets/resnet.py # neural network for domain classification
See details in Command line usage
or Programm against DomainLab API
See example here: Transformer as feature extractor, decorate JIGEN with DANN, training using MLDG decorated by DIAL
Benchmark different methods
DomainLab provides a powerful benchmark functionality. To benchmark several algorithms(combination of neural networks, models, trainers and associated hyperparameters), a single line command along with a benchmark configuration files is sufficient. See details in Benchmarks
One could simply run
bash run_benchmark_slurm.sh examples/benchmark/benchmark_pacs_resnet.yaml
to get the following result (without any augmentation like flip)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file domainlab-0.3.1.tar.gz
.
File metadata
- Download URL: domainlab-0.3.1.tar.gz
- Upload date:
- Size: 3.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.4 Linux/4.15.0-213-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8fa9b969972c6d1c99b24dd3cb16c683a67888c18bab57cd5e646c352030bf1 |
|
MD5 | eaddc1f1ab32ee9266a001c233c3090c |
|
BLAKE2b-256 | 7986a95a929942209abfb9292f29c1d8105c6dca1e614156dbeaec603941525e |
Provenance
File details
Details for the file domainlab-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: domainlab-0.3.1-py3-none-any.whl
- Upload date:
- Size: 3.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.4 Linux/4.15.0-213-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7adbc18c8904c2301346aafa0b51e4bc273894fc69f3d602e62cdb216c099828 |
|
MD5 | 36e477a9513eeaf21002719fed52d311 |
|
BLAKE2b-256 | 10e4d3e69a06b514dcae78a3625820b2ab549731ad2e9d9354145d43e30c04e4 |