{"id":29021673,"url":"https://github.com/mapiv/sparsetransformer","last_synced_at":"2025-06-26T02:07:32.239Z","repository":{"id":267137787,"uuid":"900353625","full_name":"MapIV/SparseTransformer","owner":"MapIV","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-17T05:27:25.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-17T20:00:08.544Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/MapIV.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-08T15:08:21.000Z","updated_at":"2025-03-19T09:00:15.000Z","dependencies_parsed_at":"2025-04-17T07:46:13.111Z","dependency_job_id":"b6012ce6-9949-475d-a771-1252739ffd76","html_url":"https://github.com/MapIV/SparseTransformer","commit_stats":null,"previous_names":["mapiv/sparsetransformer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MapIV/SparseTransformer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MapIV%2FSparseTransformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MapIV%2FSparseTransformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MapIV%2FSparseTransformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MapIV%2FSparseTransformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MapIV","download_url":"https://codeload.github.com/MapIV/SparseTransformer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MapIV%2FSparseTransformer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261984645,"owners_count":23240305,"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":[],"created_at":"2025-06-26T02:07:27.192Z","updated_at":"2025-06-26T02:07:32.226Z","avatar_url":"https://github.com/MapIV.png","language":"Python","readme":"# SpTr: PyTorch Spatially Sparse Transformer Library\n\nThis repository is forked from [SparseTransformer](https://github.com/dvlab-research/SparseTransformer)\n\nThis library provides a **fast** and **memory-efficient** implementation for sparse transformer with **varying token numbers** (e.g., window transformer for 3D point cloud).\n\nThis library has been used by the following works:\n\n* Spherical Transformer for LiDAR-based 3D Recognition (CVPR 2023): \\[Paper\\] [\\[Code\\]](https://github.com/dvlab-research/SphereFormer)\n\n* Stratified Transformer for 3D Point Cloud Segmentation (CVPR 2022): [\\[Paper\\]](https://openaccess.thecvf.com/content/CVPR2022/papers/Lai_Stratified_Transformer_for_3D_Point_Cloud_Segmentation_CVPR_2022_paper.pdf) [\\[Code\\]](https://github.com/dvlab-research/Stratified-Transformer)\n\n## Installation\n### Install Dependency\n```\npip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html\npip install torch_scatter\npip install torch_geometric\n```\n\n### Compile sptr\n```\npython3 setup.py install\n```\n\n\n## Usage\nSpTr can be easily used in most current transformer-based 3D point cloud networks, with only several minor modifications. First, define the attention module `sptr.VarLengthMultiheadSA`. Then, wrap the input features and indices into `sptr.SparseTrTensor`, and foward it into the module. That's all. A simple example is as follows. For more complex usage, you can refer to the code of above works (e.g., SphereFormer, StratifiedFormer).\n### Example\n```\nimport sptr\n\n# Define module\ndim = 48\nnum_heads = 3\nindice_key = 'sptr_0'\nwindow_size = np.array([0.4, 0.4, 0.4])  # can also be integers for voxel-based methods\nshift_win = False  # whether to adopt shifted window\nself.attn = sptr.VarLengthMultiheadSA(\n    dim,\n    num_heads,\n    indice_key,\n    window_size,\n    shift_win\n)\n\n# Wrap the input features and indices into SparseTrTensor. Note: indices can be either intergers for voxel-based methods or floats (i.e., xyz) for point-based methods\n# feats: [N, C], indices: [N, 4] with batch indices in the 0-th column\ninput_tensor = sptr.SparseTrTensor(feats, indices, spatial_shape=None, batch_size=None)\noutput_tensor = self.attn(input_tensor)\n\n# Extract features from output tensor\noutput_feats = output_tensor.query_feats\n```\n\n## Authors\n\nXin Lai (a Ph.D student at CSE CUHK) - Initial CUDA implementation, maintainance.\n\nFanbin Lu (a Ph.D student at CSE CUHK) - Improve CUDA implementation, maintainance.\n\nYukang Chen (a Ph.D student at CSE CUHK) - Maintainance.\n\n\n## Cite\n\nIf you find this project useful, please consider citing\n```\n@inproceedings{lai2023spherical,\n  title={Spherical Transformer for LiDAR-based 3D Recognition},\n  author={Lai, Xin and Chen, Yukang and Lu, Fanbin and Liu, Jianhui and Jia, Jiaya},\n  booktitle={CVPR},\n  year={2023}\n}\n```\n```\n@inproceedings{lai2022stratified,\n  title={Stratified transformer for 3d point cloud segmentation},\n  author={Lai, Xin and Liu, Jianhui and Jiang, Li and Wang, Liwei and Zhao, Hengshuang and Liu, Shu and Qi, Xiaojuan and Jia, Jiaya},\n  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},\n  pages={8500--8509},\n  year={2022}\n}\n```\n\n## License\n\nThis project is licensed under the Apache license 2.0 License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapiv%2Fsparsetransformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmapiv%2Fsparsetransformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapiv%2Fsparsetransformer/lists"}