Official implementation of Charm tokenizer for ViTs
Project description
Charm: The Missing Piece in ViT fine-tuning for Image Aesthetic Assessment
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
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): Used to set 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:
- While random patch selection during training helps avoid overfitting,for consistent results during inference, fully deterministic patch selection approaches should be used.
- For the training code, check our GitHub Page.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Charm_tokenizer-1.0.12.tar.gz.
File metadata
- Download URL: Charm_tokenizer-1.0.12.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbd2835688ced46b13982e1e370b9d1938e4638d7924c9263c8c468e5e50ba1d
|
|
| MD5 |
1172161d8b46b869724a37b2935ffe87
|
|
| BLAKE2b-256 |
b3d26705e8b12cd5be439b621dd8b9c8225d61fcff59740b2bb32a0479ad5374
|
File details
Details for the file Charm_tokenizer-1.0.12-py3-none-any.whl.
File metadata
- Download URL: Charm_tokenizer-1.0.12-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69f9a72d4edcaf6f0c5efc29b8f9dfa7e390979aea9161b72cde6181e2bc03d0
|
|
| MD5 |
828be6e645779e515bf34965c09c1396
|
|
| BLAKE2b-256 |
ba93b08916bdc1c9d3be43a5be5276cddf19133be355a36e77b606d3caeee48b
|