{"id":15600970,"url":"https://github.com/lucidrains/cross-transformers-pytorch","last_synced_at":"2025-04-30T11:14:07.795Z","repository":{"id":62565425,"uuid":"320637701","full_name":"lucidrains/cross-transformers-pytorch","owner":"lucidrains","description":"Implementation of Cross Transformer for spatially-aware few-shot transfer, in Pytorch","archived":false,"fork":false,"pushed_at":"2021-03-30T04:04:32.000Z","size":93,"stargazers_count":52,"open_issues_count":1,"forks_count":12,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-30T11:14:05.639Z","etag":null,"topics":["artificial-intelligence","attention-mechanism","deep-learning","few-shot-learning","transformers"],"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":"2020-12-11T17:17:19.000Z","updated_at":"2025-03-10T14:12:40.000Z","dependencies_parsed_at":"2022-11-03T18:51:38.263Z","dependency_job_id":null,"html_url":"https://github.com/lucidrains/cross-transformers-pytorch","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fcross-transformers-pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fcross-transformers-pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fcross-transformers-pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fcross-transformers-pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucidrains","download_url":"https://codeload.github.com/lucidrains/cross-transformers-pytorch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251687151,"owners_count":21627534,"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","attention-mechanism","deep-learning","few-shot-learning","transformers"],"created_at":"2024-10-03T02:10:36.911Z","updated_at":"2025-04-30T11:14:07.739Z","avatar_url":"https://github.com/lucidrains.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"./x-attn.png\" width=\"600px\"\u003e\u003c/img\u003e\n\n## Cross Transformers - Pytorch (wip)\n\nImplementation of \u003ca href=\"https://arxiv.org/abs/2007.11498\"\u003eCross Transformer\u003c/a\u003e for spatially-aware few-shot transfer, in Pytorch\n\n## Install\n\n```bash\n$ pip install cross-transformers-pytorch\n```\n\n## Usage\n\n```python\nimport torch\nfrom torch import nn\nimport torch.nn.functional as F\nfrom torchvision import models\nfrom cross_transformers_pytorch import CrossTransformer\n\nresnet = models.resnet34(pretrained = True)\nmodel = nn.Sequential(*[*resnet.children()][:-2])\n\ncross_transformer = CrossTransformer(\n    dim = 512,\n    dim_key = 128,\n    dim_value = 128\n)\n\n# (batch, channels, height, width)\nimg_query = torch.randn(1, 3, 224, 224)\n\n# (batch, classes, num supports, channels, height, width)\nimg_supports = torch.randn(1, 2, 4, 3, 224, 224)\n\nlabels = torch.randint(0, 2, (1,))\n\ndists = cross_transformer(model, img_query, img_supports) # (1, 2)\n\nloss = F.cross_entropy(dists, labels)\nloss.backward()\n```\n\n## Citations\n\n```bibtex\n@misc{doersch2020crosstransformers,\n    title={CrossTransformers: spatially-aware few-shot transfer}, \n    author={Carl Doersch and Ankush Gupta and Andrew Zisserman},\n    year={2020},\n    eprint={2007.11498},\n    archivePrefix={arXiv},\n    primaryClass={cs.CV}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Fcross-transformers-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucidrains%2Fcross-transformers-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Fcross-transformers-pytorch/lists"}