Skip to main content

TiTok - Pytorch

Project description

TiTok - Pytorch (wip)

Implementation of TiTok, proposed by Bytedance in An Image is Worth 32 Tokens for Reconstruction and Generation

Install

$ pip install titok-pytorch

Usage

import torch
from titok_pytorch import TiTokTokenizer

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

titok = TiTokTokenizer(
    dim = 512,
    num_latent_tokens = 32,   # they claim only 32 tokens needed
    codebook_size = 8192      # codebook size 8192
)

loss = titok(images)
loss.backward()

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

codes = titok.tokenize(images)

# reconstructing images from codes

recon_images = titok.codebook_ids_to_images(codes)

assert recon_images.shape == images.shape

Todo

  • add multi-resolution patches
  • add lfq

Citations

@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}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

titok_pytorch-0.0.3.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

titok_pytorch-0.0.3-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file titok_pytorch-0.0.3.tar.gz.

File metadata

  • Download URL: titok_pytorch-0.0.3.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for titok_pytorch-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ef2e56246c577dcfa0eea1dea90923d1d7d35cce8be9835e9494cb8a17568253
MD5 2b6f15ca666388931b7caafd7391def9
BLAKE2b-256 5b2b937a9ea2a4d1c10a2b2b2f1d7d3fcc247101b4a30c616c8aa8da4dc17c6a

See more details on using hashes here.

File details

Details for the file titok_pytorch-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for titok_pytorch-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 38460270a2703f4838ec591ec5b4cb0cc7356b9b11418f38aef67f9c78767f5d
MD5 e3820f78c17e986f3cd3a068b498cddd
BLAKE2b-256 84ef7d4e9538a81d4cd07b769fe7105df7a6ad9083a8cddc5ee574f90ccfd2fd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page