Skip to main content

Official implementation of Charm tokenizer for ViTs

Project description

Charm: The Missing Piece in ViT fine-tuning for Image Aesthetic Assessment

Accepted at CVPR 2025

Overall framework

We introduce Charm , a novel tokenization approach that preserves Composition, High-resolution, Aspect Ratio, and Multi-scale information simultaneously. By preserving critical aesthetic information, Charm achieves significant performance improvement across different image aesthetic and quality assessment datasets.

Quick Inference

  • Step 1) Check our GitHub Page and install the requirements.
pip install -r requirements.txt

  • Step 2) Install Charm tokenizer.
pip install Charm-tokenizer

  • Step 3) Tokenization + Position embedding preparation

Charm tokenizer

from Charm_tokenizer.ImageProcessor import Charm_Tokenizer

img_path = r"img.png"

charm_tokenizer = Charm_Tokenizer(patch_selection='frequency', training_dataset='tad66k', without_pad_or_dropping=True)
tokens, pos_embed, mask_token = charm_tokenizer.preprocess(img_path)

Charm Tokenizer has the following input args:

  • patch_selection (str): The method for selecting important patches
    • Options: 'saliency', 'random', 'frequency', 'gradient', 'entropy', 'original'.
  • training_dataset (str): Sets the number of ViT input tokens to match a specific training dataset from the paper.
    • Aesthetic assessment datasets: 'aadb', 'tad66k', 'para', 'baid'.
    • Quality assessment datasets: 'spaq', 'koniq10k'.
  • backbone (str): The ViT backbone model (default: 'facebook/dinov2-small').
  • factor (float): The downscaling factor for less important patches (default: 0.5).
  • scales (int): The number of scales used for multiscale processing (default: 2).
  • random_crop_size (tuple): Used for the 'original' patch selection strategy (default: (224, 224)).
  • downscale_shortest_edge (int): Used for the 'original' patch selection strategy (default: 256).
  • without_pad_or_dropping (bool): Whether to avoid padding or dropping patches (default: True).

The output is the preprocessed tokens, their corresponding positional embeddings, and a mask token that indicates which patches are in high resolution and which are in low resolution.


  • Step 4) Predicting aesthetic/quality score
from Charm_tokenizer.Backbone import backbone

model = backbone(training_dataset='tad66k', device='cpu')
prediction = model.predict(tokens, pos_embed, mask_token)

Note:

  1. While random patch selection during training helps avoid overfitting,for consistent results during inference, fully deterministic patch selection approaches should be used.
  2. For the training code, check our GitHub Page.

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

Charm_tokenizer-1.0.10.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Charm_tokenizer-1.0.10-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file Charm_tokenizer-1.0.10.tar.gz.

File metadata

  • Download URL: Charm_tokenizer-1.0.10.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for Charm_tokenizer-1.0.10.tar.gz
Algorithm Hash digest
SHA256 349a166ff25df2e5cb4c17d5c058f401ab802583223bfda6d7b79db3be45fed1
MD5 2922c2a6fbf515586f9ebd7d1f153a68
BLAKE2b-256 0814c115340326204815c7bbec2dffc65a3c19d4185e95b40654c7392fe1b295

See more details on using hashes here.

File details

Details for the file Charm_tokenizer-1.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for Charm_tokenizer-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 311e43fbdcdbb3f8e6a2227f79822a697feff2a956072bbf1f65866664f5d23e
MD5 2eb653d396a31a8d4ce0a40aa82dabee
BLAKE2b-256 2ec713c36ae52827f0fd820c3d9f921a309ca893b6c6aada76de21a43b7e20a4

See more details on using hashes here.

Supported by

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