{"id":15906597,"url":"https://github.com/kisonho/magnet","last_synced_at":"2025-08-01T07:31:21.495Z","repository":{"id":122155393,"uuid":"546883538","full_name":"kisonho/magnet","owner":"kisonho","description":"Modality-Agnostic Learning for Medical Image Segmentation Using Multi-modality Self-distillation","archived":false,"fork":false,"pushed_at":"2024-12-23T17:02:08.000Z","size":371,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-09T08:25:53.992Z","etag":null,"topics":["computer-vision","machine-learning","medical-imaging","segmentation","self-distillation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kisonho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-10-06T20:05:53.000Z","updated_at":"2025-03-26T09:30:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"d0b3affe-6604-45e6-99c1-9537284dbecf","html_url":"https://github.com/kisonho/magnet","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"purl":"pkg:github/kisonho/magnet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kisonho%2Fmagnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kisonho%2Fmagnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kisonho%2Fmagnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kisonho%2Fmagnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kisonho","download_url":"https://codeload.github.com/kisonho/magnet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kisonho%2Fmagnet/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268185559,"owners_count":24209392,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["computer-vision","machine-learning","medical-imaging","segmentation","self-distillation"],"created_at":"2024-10-06T13:40:49.750Z","updated_at":"2025-08-01T07:31:21.142Z","avatar_url":"https://github.com/kisonho.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Modality-Agnostic Learning for Medical Image Segmentation Using Multi-modality Self-distillation\nThis is the official implementation of **[MAG-MS](https://arxiv.org/pdf/2306.03730)**.\n\nFor the official implementation of **[MAGNET: A Modality-Agnostic Networks for Medical Image Segmentation](https://ieeexplore.ieee.org/document/10230587)**, please check to branch [stable-1.1](https://github.com/kisonho/magnet/tree/stable-1.1).\n\nMAG-MS is designed to be compatible with MAGNET (v1). The new MAGNET (v2) used in MAG-MS is designed to support multi-modality self-distillation and multi-modality feature distillation.\n\n![](res/structure_v2.jpg)\n\n## Pre-request\n* Python \u003e= 3.9\n* [PyTorch](https://pytorch.org) \u003e= 1.12.1\n* [torchmanager](https://github.com/kisonho/torchmanager) \u003e= 1.1\n* [Monai](https://monai.io) \u003e= 1.1\n\n## Installation\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install MAG-MS.\n```bash\npip install magms\n```\n\n## Get Started\n1. Load datasets\n```python\ntraining_dataset = ...\nvalidation_dataset = ...\n```\n\n2. Simpy build the MAGNET (UNETR backbone) with `magnet.build` function, or use the `magnet.build_v2` (UNETR backbone)/`magnet.build_v2_unet` (3D UNet backbone) function for the new MAGNET used in MAG-MS\n```python\nnum_modalities: int = ...\nnum_classes: int = ...\nimg_size: Union[int, Sequence[int]] = ...\nmodel = magnet.build_v2(num_modalities, num_classes, img_size, target_dict=target_dict)\n```\n\n3. Or use the deeper `magnet.nn` framework to customize MAGNET backbone\n```python\nencoder1: torch.nn.Module = ...\nencoder2: torch.nn.Module = ...\nfusion: torch.nn.Module = ...\ndecoder: torch.nn.Module = ...\nmodel = magnet.nn.MAGNET2(encoder1, encoder2, fusion=fusion, decoder=decoder)\n```\n\n4. Define MAGMS loss function\n```python\nmain_loss_fn: list[Callable[[Any, Any], torch.Tensor]] = ...\nkldiv_loss_fn: list[Callable[[Any, Any], torch.Tensor]] = ...\nmse_loss_fn: list[Callable[[Any, Any], torch.Tensor]] = ...\nself_distillation_loss_fn = magnet.losses.MAGSelfDistillationLoss(main_loss_fn, kldiv_loss_fn)\nfeature_distillation_loss_fn = magnet.losses.MAGFeatureDistillationLoss(self_distillation_loss_fn, mse_loss_fn)\nloss_fn = feature_distillation_loss_fn\n```\n\n5. Compile manager and train/test\n```python\noptimizer = ...\nmetric_fns = ...\n\nepochs = ...\ncallbacks = ...\n\nmanager = magnet.Manager(model, optimizer, loss_fn=loss_fn, metric_fns=metric_fns)\nmanager.fit(training_dataset, epochs, val_dataset=validation_dataset, callbacks=callbacks)\nsummary.test(validation_dataset)\nprint(summary)\n```\n\n## Monai Support\n* Using `magnet.MonaigManager` instead of `Manager` \n* Post processing support with `post_labels` and `post_predicts`\n```python\npost_labels = [...]\npost_predicts = [...]\n\nmanager = magnet.MonaigManager(model, post_labels=post_labels, post_predicts=post_predicts, optimizer=optimizer, loss_fn=loss_fn, metric_fns=metric_fns)\n```\n\n## Cite this work\n```bibtex\n@article{he2023modality,\n  title={Modality-Agnostic Learning for Medical Image Segmentation Using Multi-modality Self-distillation},\n  author={He, Qisheng and Summerfield, Nicholas and Dong, Ming and Glide-Hurst, Carri},\n  journal={arXiv preprint arXiv:2306.03730},\n  year={2023}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkisonho%2Fmagnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkisonho%2Fmagnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkisonho%2Fmagnet/lists"}