{"id":16272081,"url":"https://github.com/sshh12/cida","last_synced_at":"2026-05-15T21:37:34.513Z","repository":{"id":70737699,"uuid":"359980123","full_name":"sshh12/cida","owner":"sshh12","description":"An unofficial refactor of the code used by the ICML 2020 paper \"Continuously Indexed Domain Adaptation\"","archived":false,"fork":false,"pushed_at":"2021-06-09T02:25:15.000Z","size":55,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-21T00:08:10.520Z","etag":null,"topics":["cida","domain-adaptation","extrapolation","mnist","pytorch"],"latest_commit_sha":null,"homepage":"","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/sshh12.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":"2021-04-20T23:48:10.000Z","updated_at":"2021-06-09T02:25:17.000Z","dependencies_parsed_at":"2023-02-22T22:15:23.506Z","dependency_job_id":null,"html_url":"https://github.com/sshh12/cida","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sshh12/cida","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshh12%2Fcida","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshh12%2Fcida/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshh12%2Fcida/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshh12%2Fcida/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sshh12","download_url":"https://codeload.github.com/sshh12/cida/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshh12%2Fcida/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266263057,"owners_count":23901353,"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":["cida","domain-adaptation","extrapolation","mnist","pytorch"],"created_at":"2024-10-10T18:16:02.172Z","updated_at":"2026-05-15T21:37:29.473Z","avatar_url":"https://github.com/sshh12.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Continuously Indexed Domain Adaptation (CIDA)\n\nAn unofficial refactor of the code used by the ICML 2020 paper [Continuously Indexed Domain Adaptation](http://wanghao.in/paper/ICML20_CIDA.pdf). [[Official Code]](https://github.com/hehaodele/CIDA).\n\n## Install\n\n```\n$ pip install git+https://github.com/sshh12/cida.git --upgrade\n```\n\n## Usage\n\n\u003e The code should work for any dataset that serves data in the correct format (see [RotatedMNIST](https://github.com/sshh12/cida/blob/main/cida/datasets/rotated_mnist.py)), although I created this repo for my specific use case so some trivial/generic features may be missing. Fill free to create an issue/PR.\n\n**Important Note**: Domain adaptation models are a bit different from other models in terms of the train/test datasets. Rather than being distinct, the CIDA model is trained on both the train and test sets (e.g. the `.fit()` DataLoaders should feed both) however the model ignores the labels for any examples where `is_train` is set to `False`. This allows the model to learn the continuous relationship between the train and test domains while also optimizing the classification/regression task given in the `is_train` data. At no point (except of course in evaluation) does the model see the labels for the test data.\n\n### Classification (Rotated MNIST)\n\n```python\nfrom torch.utils.data import DataLoader\nfrom cida.datasets import RotatedMNIST\nfrom cida.conv_model import ConvPCIDAClassifier\nimport os\n\nif __name__ == \"__main__\":\n    # RotatedMNIST.download()\n    dataset = RotatedMNIST(\n        os.path.join(\"data\", \"MNIST\", \"processed\", \"training.pt\"), rotate_range=(0, 360), train_range=(0, 45)\n    )\n    dataloader = DataLoader(\n        dataset=dataset,\n        shuffle=True,\n        batch_size=100,\n        num_workers=1,\n    )\n    val_dataloader = DataLoader(\n        dataset=dataset,\n        shuffle=True,\n        batch_size=100,\n        num_workers=1,\n    )\n    model = ConvPCIDAClassifier(\n        classes=10, input_dims=28 * 28, domain_dims=1, domains_to_labels=RotatedMNIST.domains_to_labels, verbose=True\n    )\n    model = model.to(\"cpu\")\n    model.fit(dataloader, val_dataloader, epochs=100)\n    print(model.predict(next(iter(val_dataloader))))\n```\n\n### Regression\n\n```python\nfrom torch.utils.data import DataLoader\nfrom cida.regr_model import PCIDARegressor\nimport os\n\ndef mse(y_pred, y):\n    return ((y_pred - y) ** 2).mean()\n\nif __name__ == \"__main__\":\n    dataset = MyRegressionDataset()\n    dataloader = DataLoader(\n        dataset=dataset,\n        shuffle=True,\n        batch_size=128,\n        num_workers=1,\n    )\n    val_dataloader = DataLoader(\n        dataset=dataset,\n        shuffle=True,\n        batch_size=128,\n        num_workers=1,\n    )\n    model = PCIDARegressor(\n        input_dims=1000,\n        domain_dims=1,\n        domains_to_labels=dataset.domains_to_labels,\n        lr=3e-4,\n        beta1=0.9,\n        gamma=0.99,\n        weight_decay=5e-4,\n        lambda_gan=lambda epoch: 3.0,\n        latent_size=64,\n        test_domain_known=True,\n        metrics={\"mse\": mse},\n        verbose=True,\n    )\n    model = model.to(\"cuda\")\n    model.fit(dataloader, val_dataloader, epochs=100, save_metric=\"test_mse\", save_fn=\"cida-best.pth\")\n```\n\n## Reference\n\nFor citing the original paper:\n\n```\n@inproceedings{DBLP:conf/icml/WangHK20,\n  author    = {Hao Wang and\n               Hao He and\n               Dina Katabi},\n  title     = {Continuously Indexed Domain Adaptation},\n  booktitle = {ICML},\n  year      = {2020}\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshh12%2Fcida","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsshh12%2Fcida","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshh12%2Fcida/lists"}