{"id":15601070,"url":"https://github.com/lucidrains/med-seg-diff-pytorch","last_synced_at":"2025-04-05T08:04:49.329Z","repository":{"id":63695489,"uuid":"569880189","full_name":"lucidrains/med-seg-diff-pytorch","owner":"lucidrains","description":"Implementation of MedSegDiff in Pytorch - SOTA medical segmentation using DDPM and filtering of features in fourier space","archived":false,"fork":false,"pushed_at":"2023-12-03T14:29:00.000Z","size":254,"stargazers_count":228,"open_issues_count":8,"forks_count":27,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-29T07:07:25.062Z","etag":null,"topics":["artificial-intelligence","deep-learning","denoising-diffusion","medicine","segmentation"],"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/lucidrains.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}},"created_at":"2022-11-23T20:36:54.000Z","updated_at":"2025-03-18T10:26:49.000Z","dependencies_parsed_at":"2023-12-03T15:36:35.833Z","dependency_job_id":null,"html_url":"https://github.com/lucidrains/med-seg-diff-pytorch","commit_stats":{"total_commits":55,"total_committers":4,"mean_commits":13.75,"dds":0.5454545454545454,"last_synced_commit":"dbdce0f25df541a29188eb5c27578e6613af0631"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fmed-seg-diff-pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fmed-seg-diff-pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fmed-seg-diff-pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fmed-seg-diff-pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucidrains","download_url":"https://codeload.github.com/lucidrains/med-seg-diff-pytorch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305933,"owners_count":20917208,"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":["artificial-intelligence","deep-learning","denoising-diffusion","medicine","segmentation"],"created_at":"2024-10-03T02:13:43.906Z","updated_at":"2025-04-05T08:04:49.305Z","avatar_url":"https://github.com/lucidrains.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cimg src=\"./docs/med-seg-diff.png\" width=\"450px\"\u003e\u003c/img\u003e\n\n## MedSegDiff - Pytorch\n\nImplementation of \u003ca href=\"https://arxiv.org/abs/2211.00611\"\u003eMedSegDiff\u003c/a\u003e in Pytorch - SOTA medical segmentation out of Baidu using DDPM and enhanced conditioning on the feature level, with filtering of features in fourier space.\n\n## Appreciation\n\n- \u003ca href=\"https://stability.ai/\"\u003eStabilityAI\u003c/a\u003e for the generous sponsorship, as well as my other sponsors out there\n\n- \u003ca href=\"https://github.com/isamu-isozaki\"\u003eIsamu\u003c/a\u003e and \u003ca href=\"https://github.com/dsbuddy\"\u003eDaniel\u003c/a\u003e for adding a training script for a skin lesion dataset!\n\n## Install\n\n```bash\n$ pip install med-seg-diff-pytorch\n```\n\n## Usage\n\n```python\nimport torch\nfrom med_seg_diff_pytorch import Unet, MedSegDiff\n\nmodel = Unet(\n    dim = 64,\n    image_size = 128,\n    mask_channels = 1,          # segmentation has 1 channel\n    input_img_channels = 3,     # input images have 3 channels\n    dim_mults = (1, 2, 4, 8)\n)\n\ndiffusion = MedSegDiff(\n    model,\n    timesteps = 1000\n).cuda()\n\nsegmented_imgs = torch.rand(8, 1, 128, 128)  # inputs are normalized from 0 to 1\ninput_imgs = torch.rand(8, 3, 128, 128)\n\nloss = diffusion(segmented_imgs, input_imgs)\nloss.backward()\n\n# after a lot of training\n\npred = diffusion.sample(input_imgs)     # pass in your unsegmented images\npred.shape                              # predicted segmented images - (8, 3, 128, 128)\n```\n\n## Training\n\nCommand to run\n```bash\naccelerate launch driver.py --mask_channels=1 --input_img_channels=3 --image_size=64 --data_path='./data' --dim=64 --epochs=100 --batch_size=1 --scale_lr --gradient_accumulation_steps=4\n```\nIf you want to add in self condition where we condition with the mask we have so far, do --self_condition\n\n## Todo\n\n- [x] some basic training code, with Trainer taking in custom dataset tailored for medical image formats  - thanks to \u003ca href=\"https://github.com/isamu-isozaki\"\u003e@isamu-isozaki\u003c/a\u003e\n- [x] full blown transformer of any depth in the middle, as done in \u003ca href=\"https://arxiv.org/abs/2301.11093\"\u003esimple diffusion\u003c/a\u003e\n\n\n## Citations\n\n```bibtex\n@article{Wu2022MedSegDiffMI,\n    title   = {MedSegDiff: Medical Image Segmentation with Diffusion Probabilistic Model},\n    author  = {Junde Wu and Huihui Fang and Yu Zhang and Yehui Yang and Yanwu Xu},\n    journal = {ArXiv},\n    year    = {2022},\n    volume  = {abs/2211.00611}\n}\n```\n\n```bibtex\n@inproceedings{Hoogeboom2023simpleDE,\n    title   = {simple diffusion: End-to-end diffusion for high resolution images},\n    author  = {Emiel Hoogeboom and Jonathan Heek and Tim Salimans},\n    year    = {2023}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Fmed-seg-diff-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucidrains%2Fmed-seg-diff-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Fmed-seg-diff-pytorch/lists"}