Views
No views yet
| Model | Type | Parameters | Description |
|---|---|---|---|
| DeTok-BB | Tokenizer | 172M | Base tokenizer with denoising training |
| DeTok-BB-decoder_ft | Tokenizer | 172M | Base tokenizer with additional decoder fine-tuning |
| Model | FID-50K | Inception Score | Parameters |
|---|---|---|---|
| MAR-Base + MAR-VAE | 2.31 | 281.7 | 208M |
| MAR-Base + DeTok-BB | 1.61 | 289.7 | 208M |
| MAR-Base + DeTok-BB-decoder_ft | 1.55 | 291.0 | 208M |
| MAR-Large + MAR-VAE | 1.78 | 296.0 | 479M |
| MAR-Huge + MAR-VAE | 1.55 | 303.7 | 943M |
| MAR-Large + DeTok-BB | 1.43 | 303.5 | 479M |
| MAR-Large + DeTok-BB-decoder_ft | 1.32 | 304.1 | 479M |
1git clone https://github.com/Jiawei-Yang/DeTok.git
2cd DeTok
3pip install -r requirements.txtDeTok-BB-decoder_ft checkpoint (recommended) from here and place it in your working directory (e.g., detok-BB-gamm3.0-m0.7-decoder_tuned.pth).DeTok_BB tokenizer:1import torch
2from PIL import Image
3from torchvision.transforms import transforms
4from models.detok import DeTok_BB # Import from the cloned DeTok repository
5
6# --- Configuration (matching DeTok-BB-decoder_ft architecture from paper) ---
7model_params = {
8 "img_size": 256,
9 "patch_size": 16,
10 "in_chans": 3,
11 "embed_dim": 768,
12 "depths": [2, 2, 8, 2],
13 "num_heads": [3, 6, 12, 24],
14}
15tokenizer_weights_path = "detok-BB-gamm3.0-m0.7-decoder_tuned.pth" # Path to your downloaded weights
16
17# 1. Initialize and load the tokenizer
18tokenizer = DeTok_BB(**model_params).eval()
19if torch.cuda.is_available():
20 tokenizer = tokenizer.cuda()
21
22# Load checkpoint state_dict
23checkpoint = torch.load(tokenizer_weights_path, map_location='cpu')
24tokenizer.load_state_dict(checkpoint['model'])
25
26# 2. Prepare your image
27transform = transforms.Compose([
28 transforms.Resize(model_params["img_size"]),
29 transforms.CenterCrop(model_params["img_size"]),
30 transforms.ToTensor(),
31 transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
32])
33
34# Replace 'path/to/your/image.jpg' with your actual image file
35image = Image.new('RGB', (model_params["img_size"], model_params["img_size"]), color = 'red') # Example dummy image
36# image = Image.open("path/to/your/image.jpg").convert("RGB")
37
38pixel_values = transform(image).unsqueeze(0) # Add batch dimension
39
40if torch.cuda.is_available():
41 pixel_values = pixel_values.cuda()
42
43# 3. Extract latent embeddings
44with torch.no_grad():
45 latent_embeddings = tokenizer.encode(pixel_values)
46
47print(f"Shape of latent embeddings: {latent_embeddings.shape}")
48# Expected output for a 256x256 input image with 16x16 patches is (1, 256, 768),
49# representing 256 image patches with 768-dimensional embeddings.1@article{yang2025detok,
2 title={Latent Denoising Makes Good Visual Tokenizers},
3 author={Jiawei Yang and Tianhong Li and Lijie Fan and Yonglong Tian and Yue Wang},
4 journal={arXiv preprint arXiv:2507.15856},
5 year={2025}
6}