titok-pytorch


Nametitok-pytorch JSON
Version 0.0.5 PyPI version JSON
download
home_pageNone
SummaryTiTok - Pytorch
upload_time2024-06-20 13:42:23
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT License Copyright (c) 2024 Phil Wang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords artificial intelligence deep learning image compression image generation vector quantization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="./titok.png" width="400px"></img>

## TiTok - Pytorch (wip)

Implementation of TiTok, proposed by Bytedance in <a href="https://yucornetto.github.io/projects/titok.html">An Image is Worth 32 Tokens for Reconstruction and Generation</a>

## Install

```bash
$ pip install titok-pytorch
```

## Usage

```python
import torch
from titok_pytorch import TiTokTokenizer

images = torch.randn(2, 3, 256, 256)

titok = TiTokTokenizer(
    dim = 1024,
    patch_size = 32,
    num_latent_tokens = 32,   # they claim only 32 tokens needed
    codebook_size = 4096      # codebook size 4096
)

loss = titok(images)
loss.backward()

# after much training
# extract codes for gpt, maskgit, whatever

codes = titok.tokenize(images) # (2, 32)

# reconstructing images from codes

recon_images = titok.codebook_ids_to_images(codes)

assert recon_images.shape == images.shape
```

## Todo

- [ ] add multi-resolution patches

## Citations

```bibtex
@article{yu2024an,
  author    = {Qihang Yu and Mark Weber and Xueqing Deng and Xiaohui Shen and Daniel Cremers and Liang-Chieh Chen},
  title     = {An Image is Worth 32 Tokens for Reconstruction and Generation},
  journal   = {arxiv: 2406.07550},
  year      = {2024}
}
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "titok-pytorch",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "artificial intelligence, deep learning, image compression, image generation, vector quantization",
    "author": null,
    "author_email": "Phil Wang <lucidrains@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/c4/d5/c23e3ae618858f2c760b160555efb18ace98eda8e485379c38cf9e295e2d/titok_pytorch-0.0.5.tar.gz",
    "platform": null,
    "description": "<img src=\"./titok.png\" width=\"400px\"></img>\n\n## TiTok - Pytorch (wip)\n\nImplementation of TiTok, proposed by Bytedance in <a href=\"https://yucornetto.github.io/projects/titok.html\">An Image is Worth 32 Tokens for Reconstruction and Generation</a>\n\n## Install\n\n```bash\n$ pip install titok-pytorch\n```\n\n## Usage\n\n```python\nimport torch\nfrom titok_pytorch import TiTokTokenizer\n\nimages = torch.randn(2, 3, 256, 256)\n\ntitok = TiTokTokenizer(\n    dim = 1024,\n    patch_size = 32,\n    num_latent_tokens = 32,   # they claim only 32 tokens needed\n    codebook_size = 4096      # codebook size 4096\n)\n\nloss = titok(images)\nloss.backward()\n\n# after much training\n# extract codes for gpt, maskgit, whatever\n\ncodes = titok.tokenize(images) # (2, 32)\n\n# reconstructing images from codes\n\nrecon_images = titok.codebook_ids_to_images(codes)\n\nassert recon_images.shape == images.shape\n```\n\n## Todo\n\n- [ ] add multi-resolution patches\n\n## Citations\n\n```bibtex\n@article{yu2024an,\n  author    = {Qihang Yu and Mark Weber and Xueqing Deng and Xiaohui Shen and Daniel Cremers and Liang-Chieh Chen},\n  title     = {An Image is Worth 32 Tokens for Reconstruction and Generation},\n  journal   = {arxiv: 2406.07550},\n  year      = {2024}\n}\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Phil Wang  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "TiTok - Pytorch",
    "version": "0.0.5",
    "project_urls": {
        "Homepage": "https://pypi.org/project/titok-pytorch/",
        "Repository": "https://github.com/lucidrains/titok-pytorch"
    },
    "split_keywords": [
        "artificial intelligence",
        " deep learning",
        " image compression",
        " image generation",
        " vector quantization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f7597098442f96023cd13ed9c9101148e069b5e3d1bfa8bbb86bac27278ae406",
                "md5": "adce9264bd54d91ca3aabf5fb70e816d",
                "sha256": "bf7e2c69c848c8386dc578ac2063191b2ffe757ac250f2b623013bc66d78f791"
            },
            "downloads": -1,
            "filename": "titok_pytorch-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "adce9264bd54d91ca3aabf5fb70e816d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 5220,
            "upload_time": "2024-06-20T13:42:22",
            "upload_time_iso_8601": "2024-06-20T13:42:22.372174Z",
            "url": "https://files.pythonhosted.org/packages/f7/59/7098442f96023cd13ed9c9101148e069b5e3d1bfa8bbb86bac27278ae406/titok_pytorch-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c4d5c23e3ae618858f2c760b160555efb18ace98eda8e485379c38cf9e295e2d",
                "md5": "a6558be2e5afc9901420e2b20a772b3e",
                "sha256": "49ffa0c92faf03b5cc536f84243c42c277a4b001b04adce42c4b3537c9238f1f"
            },
            "downloads": -1,
            "filename": "titok_pytorch-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "a6558be2e5afc9901420e2b20a772b3e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 1323635,
            "upload_time": "2024-06-20T13:42:23",
            "upload_time_iso_8601": "2024-06-20T13:42:23.958196Z",
            "url": "https://files.pythonhosted.org/packages/c4/d5/c23e3ae618858f2c760b160555efb18ace98eda8e485379c38cf9e295e2d/titok_pytorch-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-20 13:42:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lucidrains",
    "github_project": "titok-pytorch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "titok-pytorch"
}
        
Elapsed time: 4.29580s