{"id":26786885,"url":"https://github.com/marrlab/domainlab","last_synced_at":"2026-03-15T17:03:36.329Z","repository":{"id":44352804,"uuid":"485323078","full_name":"marrlab/DomainLab","owner":"marrlab","description":"modular domain generalization: https://pypi.org/project/domainlab/","archived":false,"fork":false,"pushed_at":"2025-03-18T10:07:30.000Z","size":119333,"stargazers_count":44,"open_issues_count":39,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-04T12:12:34.764Z","etag":null,"topics":["domain-generalization-causality-deep-learning"],"latest_commit_sha":null,"homepage":"https://marrlab.github.io/DomainLab/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marrlab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-25T10:23:09.000Z","updated_at":"2025-03-18T10:07:34.000Z","dependencies_parsed_at":"2024-07-11T14:41:13.162Z","dependency_job_id":null,"html_url":"https://github.com/marrlab/DomainLab","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marrlab%2FDomainLab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marrlab%2FDomainLab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marrlab%2FDomainLab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marrlab%2FDomainLab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marrlab","download_url":"https://codeload.github.com/marrlab/DomainLab/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675607,"owners_count":20977378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["domain-generalization-causality-deep-learning"],"created_at":"2025-03-29T12:17:09.255Z","updated_at":"2026-03-15T17:03:36.231Z","avatar_url":"https://github.com/marrlab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DomainLab: modular python package for training domain invariant neural networks\n\n![GH Actions CI ](https://github.com/marrlab/DomainLab/actions/workflows/ci.yml/badge.svg?branch=master)\n[![codecov](https://codecov.io/gh/marrlab/DomainLab/branch/master/graph/badge.svg)](https://app.codecov.io/gh/marrlab/DomainLab)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/bc22a1f9afb742efb02b87284e04dc86)](https://www.codacy.com/gh/marrlab/DomainLab/dashboard)\n[![Documentation](https://img.shields.io/badge/Documentation-Here)](https://marrlab.github.io/DomainLab/)\n[![pages-build-deployment](https://github.com/marrlab/DomainLab/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/marrlab/DomainLab/actions/workflows/pages/pages-build-deployment)\n\n## Distribution shifts, domain generalization and DomainLab\n\nNeural networks trained using data from a specific distribution (domain) usually fail to generalize to novel distributions (domains). Domain generalization aims at learning domain invariant features by utilizing data from multiple domains (data sites, cohorts, batches, vendors) so the learned feature can be generalized to new unseen domains (distributions).\n\nDomainLab is a software platform with state-of-the-art domain generalization algorithms implemented and designed by maximal decoupling of different software components thus enhancing maximal code reuse.\n\n### DomainLab\nDomainLab decouples the following concepts or objects:\n- task $M$: In DomainLab, a task is a container for datasets from different domains. (e.g. from distribution $D_1$ and $D_2$). The task offers a static protocol to evaluate the generalization performance of a neural network: which dataset(s) is used for training, and which dataset(s) is used for testing.  \n- neural network: a map $\\phi$ from the input data to the feature space and a map $\\varphi$ from the feature space to output $\\hat{y}$ (e.g. decision variable).\n- model: structural risk in the form of $\\ell() + \\mu R()$  where\n  - $\\ell(Y, \\hat{y}=\\varphi(\\phi(X)))$ is the task-specific empirical loss (e.g. cross entropy for classification task).\n  - $R(\\phi(X))$ is the penalty loss to boost domain invariant feature extraction using $\\phi$.\n  - $\\mu$ is the corresponding multiplier to each penalty function factor.\n- trainer:  an object that guides the data flow to model and append further domain invariant losses\nlike inter-domain feature alignment.\n\nWe offer detailed documentation on how these models and trainers work on our documentation page: https://marrlab.github.io/DomainLab/\n\nDomainLab makes it possible to combine models with models, trainers with models, and trainers with trainers in a decorator pattern like the line of code below\n\n```\nTrainer A(\n\t\t  Trainer B(Model C(\n\t\t\t\t\t\t    Model D(network E),\n\t\t\t\t\t\t\tnetwork E,\n\t\t\t\t\t\t\tnetwork F\n\t\t\t\t\t\t   )\n\t\t\t\t   )\n\t     )\n```\n\nwhich 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. All models share the same neural network for feature extraction, but can have different auxiliary networks for $R()$.\n\n\u003cdiv style=\"align: center; text-align:center;\"\u003e\n\u003cfigure\u003e  \n\u003cimg src=\"https://github.com/marrlab/DomainLab/blob/master/docs/figs/invarfeat4dg.png?raw=true\" style=\"width:300px;\"/\u003e \n\u003c/figure\u003e\n\u003c/div\u003e\n\n## Getting started\n\n### Installation\nFor the development version in Github, see [Installation and Dependencies handling](./docs/doc_install.md)\n\nWe 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.\n\n### Task specification\nWe offer various ways for the user to specify a scenario to evaluate the generalization performance via training on a limited number of datasets. See detail in\n[Task Specification](./docs/doc_tasks.md) \n\n### Example and usage\n#### Available arguments for commandline\n\nThe following command tells which arguments/hyperparameters/multipliers are available to be set by the user and which model they are associated with\n\n```shell\npython main_out.py --help\n```\n\nor \n\n```\ndomainlab --help\n```\n\n#### Command line configuration file\n\n`domainlab -c ./examples/conf/vlcs_diva_mldg_dial.yaml` (if you install via pip)\n\nor if you clone this the code repository for DomainLab\n\n`python main_out.py -c ./examples/conf/vlcs_diva_mldg_dial.yaml`\n\nwhere the configuration file below can be downloaded [here](https://raw.githubusercontent.com/marrlab/DomainLab/master/examples/conf/vlcs_diva_mldg_dial.yaml)\n```\nte_d: caltech                       # domain name of test domain\ntpath: examples/tasks/task_vlcs.py  # python file path to specify the task\nbs: 2                               # batch size\nmodel: dann_diva                    # combine model DANN with DIVA\nepos: 1                             # number of epochs\ntrainer: mldg_dial                  # combine trainer MLDG and DIAL\ngamma_y: 700000.0                   # hyperparameter of diva\ngamma_d: 100000.0                   # hyperparameter of diva\nnpath: examples/nets/resnet.py      # neural network for class classification\nnpath_dom: examples/nets/resnet.py  # neural network for domain classification\n```\nSee details in [Command line usage](./docs/doc_usage_cmd.md)\n\n#### or Programm against DomainLab API\n\nSee example here: [Transformer as feature extractor, decorate JIGEN with DANN, training using MLDG decorated by DIAL](https://github.com/marrlab/DomainLab/blob/master/examples/api/jigen_dann_transformer.py)\n\n\n### Benchmark different methods\nDomainLab provides a powerful benchmark functionality.\nTo 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 documentation and tutorial](./docs/doc_benchmark.md)\n\nOne could simply run\n`bash run_benchmark_slurm.sh your_benchmark_configuration.yaml` to launch different experiments with specified configuraiton.\n\n\nFor example,  the following result (without any augmentation like flip) is for PACS dataset using ResNet. The reader should note that using different neural network, whether pre-trained or not, what kind of preprocessinga and augmentation to use can lead to very different result distributions, which is one of the features DomainLab provide: the above factors get decoupled in DomainLab. \n\n\u003cdiv style=\"align: center; text-align:center;\"\u003e\n\u003cfigure\u003e  \n\u003cimg src=\"https://github.com/marrlab/DomainLab/blob/master/docs/figs/stochastic_variation_two_rows.png?raw=true\" style=\"width:800px;\"/\u003e\n\u003cdiv class=\"caption\" style=\"align: center; text-align:center;\"\u003e\n\u003cfigcaption\u003eBenchmark results plot generated from DomainLab, where each rectangle represent one model trainer combination, each bar inside the rectangle represent a unique hyperparameter index associated with that method combination, each dot represent a random seeds.\u003c/figcaption\u003e\n\u003c/div\u003e\n\u003c/figure\u003e\n\u003c/div\u003e\n\n\n### Citation\n\nSource: https://arxiv.org/pdf/2403.14356.pdf\n\n```bibtex\n@misc{sun2024domainlab,\n  title={DomainLab: A modular Python package for domain generalization in deep learning},\n  author={Sun, Xudong and Feistner, Carla and Gossmann, Alexej and Schwarz, George and Umer, Rao Muhammad and Beer, Lisa and Rockenschaub, Patrick and Shrestha, Rahul Babu and Gruber, Armin and Chen, Nutan and others},\n  journal={https://arxiv.org/pdf/2403.14356.pdf},\n  year={2024}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarrlab%2Fdomainlab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarrlab%2Fdomainlab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarrlab%2Fdomainlab/lists"}