{"id":13869857,"url":"https://github.com/lucidrains/TimeSformer-pytorch","last_synced_at":"2025-07-15T18:32:13.041Z","repository":{"id":47736989,"uuid":"337924729","full_name":"lucidrains/TimeSformer-pytorch","owner":"lucidrains","description":"Implementation of TimeSformer from Facebook AI, a pure attention-based solution for video classification","archived":false,"fork":false,"pushed_at":"2021-08-25T00:52:32.000Z","size":185,"stargazers_count":719,"open_issues_count":14,"forks_count":85,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-06-27T06:18:46.475Z","etag":null,"topics":["artificial-intelligence","attention-mechanism","deep-learning","transformers","video-classification"],"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-02-11T04:01:17.000Z","updated_at":"2025-06-04T14:25:35.000Z","dependencies_parsed_at":"2022-07-26T17:45:30.664Z","dependency_job_id":null,"html_url":"https://github.com/lucidrains/TimeSformer-pytorch","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/lucidrains/TimeSformer-pytorch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2FTimeSformer-pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2FTimeSformer-pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2FTimeSformer-pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2FTimeSformer-pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucidrains","download_url":"https://codeload.github.com/lucidrains/TimeSformer-pytorch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2FTimeSformer-pytorch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265451456,"owners_count":23767769,"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","transformers","video-classification"],"created_at":"2024-08-05T20:01:19.876Z","updated_at":"2025-07-15T18:32:12.773Z","avatar_url":"https://github.com/lucidrains.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003cimg src=\"./diagram.png\" width=\"600px\"\u003e\u003c/img\u003e\n\n## TimeSformer - Pytorch\n\nImplementation of \u003ca href=\"https://arxiv.org/abs/2102.05095\"\u003eTimeSformer\u003c/a\u003e, from Facebook AI. A pure and simple attention-based solution for reaching SOTA on video classification. This repository will only house the best performing variant, 'Divided Space-Time Attention', which is nothing more than attention along the time axis before the spatial.\n\n\u003ca href=\"https://ai.facebook.com/blog/timesformer-a-new-architecture-for-video-understanding/\"\u003ePress release\u003c/a\u003e\n\n## Install\n\n``` bash\n$ pip install timesformer-pytorch\n```\n\n## Usage\n\n```python\nimport torch\nfrom timesformer_pytorch import TimeSformer\n\nmodel = TimeSformer(\n    dim = 512,\n    image_size = 224,\n    patch_size = 16,\n    num_frames = 8,\n    num_classes = 10,\n    depth = 12,\n    heads = 8,\n    dim_head =  64,\n    attn_dropout = 0.1,\n    ff_dropout = 0.1\n)\n\nvideo = torch.randn(2, 8, 3, 224, 224) # (batch x frames x channels x height x width)\nmask = torch.ones(2, 8).bool() # (batch x frame) - use a mask if there are variable length videos in the same batch\n\npred = model(video, mask = mask) # (2, 10)\n```\n\n## Citations\n\n```bibtex\n@misc{bertasius2021spacetime,\n    title   = {Is Space-Time Attention All You Need for Video Understanding?}, \n    author  = {Gedas Bertasius and Heng Wang and Lorenzo Torresani},\n    year    = {2021},\n    eprint  = {2102.05095},\n    archivePrefix = {arXiv},\n    primaryClass = {cs.CV}\n}\n```\n\n```bibtex\n@misc{su2021roformer,\n    title   = {RoFormer: Enhanced Transformer with Rotary Position Embedding},\n    author  = {Jianlin Su and Yu Lu and Shengfeng Pan and Bo Wen and Yunfeng Liu},\n    year    = {2021},\n    eprint  = {2104.09864},\n    archivePrefix = {arXiv},\n    primaryClass = {cs.CL}\n}\n```\n\n```bibtex\n@article{tokshift2021,\n    title   = {Token Shift Transformer for Video Classification},\n    author  = {Hao Zhang, Yanbin Hao, Chong-Wah Ngo},\n    journal = {ACM Multimedia 2021},\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2FTimeSformer-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucidrains%2FTimeSformer-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2FTimeSformer-pytorch/lists"}