{"id":15601030,"url":"https://github.com/lucidrains/uformer-pytorch","last_synced_at":"2025-04-14T12:41:00.321Z","repository":{"id":62586118,"uuid":"377665681","full_name":"lucidrains/uformer-pytorch","owner":"lucidrains","description":"Implementation of Uformer, Attention-based Unet, in Pytorch","archived":false,"fork":false,"pushed_at":"2021-10-26T15:28:20.000Z","size":89,"stargazers_count":93,"open_issues_count":1,"forks_count":16,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-04T18:16:31.138Z","etag":null,"topics":["artificial-intelligence","deep-learning","image-segmentation","transformer","unet"],"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}},"created_at":"2021-06-17T00:56:03.000Z","updated_at":"2024-09-25T03:24:36.000Z","dependencies_parsed_at":"2022-11-03T22:05:11.493Z","dependency_job_id":null,"html_url":"https://github.com/lucidrains/uformer-pytorch","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fuformer-pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fuformer-pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fuformer-pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fuformer-pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucidrains","download_url":"https://codeload.github.com/lucidrains/uformer-pytorch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248883027,"owners_count":21177137,"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","image-segmentation","transformer","unet"],"created_at":"2024-10-03T02:12:35.812Z","updated_at":"2025-04-14T12:41:00.294Z","avatar_url":"https://github.com/lucidrains.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"./uformer.png\" width=\"450px\"/\u003e\n\n## Uformer - Pytorch\n\nImplementation of \u003ca href=\"https://arxiv.org/abs/2106.03106\"\u003eUformer\u003c/a\u003e, Attention-based Unet, in Pytorch. It will only offer the concat-cross-skip connection.\n\nThis repository will be geared towards use in a project \u003ca href=\"https://github.com/lucidrains/ddpm-proteins\"\u003efor learning protein structures\u003c/a\u003e. Specifically, it will include the ability to condition on time steps (needed for DDPM), as well as 2d relative positional encoding using rotary embeddings (instead of the bias on the attention matrix in the paper).\n\n## Install\n\n```bash\n$ pip install uformer-pytorch\n```\n\n## Usage\n\n```python\nimport torch\nfrom uformer_pytorch import Uformer\n\nmodel = Uformer(\n    dim = 64,           # initial dimensions after input projection, which increases by 2x each stage\n    stages = 4,         # number of stages\n    num_blocks = 2,     # number of transformer blocks per stage\n    window_size = 16,   # set window size (along one side) for which to do the attention within\n    dim_head = 64,\n    heads = 8,\n    ff_mult = 4\n)\n\nx = torch.randn(1, 3, 256, 256)\npred = model(x) # (1, 3, 256, 256)\n```\n\nTo condition on time for DDPM training\n\n```python\nimport torch\nfrom uformer_pytorch import Uformer\n\nmodel = Uformer(\n    dim = 64,\n    stages = 4,\n    num_blocks = 2,\n    window_size = 16,\n    dim_head = 64,\n    heads = 8,\n    ff_mult = 4,\n    time_emb = True    # set this to true\n)\n\nx = torch.randn(1, 3, 256, 256)\ntime = torch.arange(1)\npred = model(x, time = time) # (1, 3, 256, 256)\n```\n\n## Citations\n\n```bibtex\n@misc{wang2021uformer,\n    title   = {Uformer: A General U-Shaped Transformer for Image Restoration}, \n    author  = {Zhendong Wang and Xiaodong Cun and Jianmin Bao and Jianzhuang Liu},\n    year    = {2021},\n    eprint  = {2106.03106},\n    archivePrefix = {arXiv},\n    primaryClass = {cs.CV}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Fuformer-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucidrains%2Fuformer-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Fuformer-pytorch/lists"}