| --- |
| license: other |
| license_details: imagenet-agreement |
| --- |
| |
| The dataset now contains 990 images in addition to the previous 10 diverse samples. |
|
|
| # Analysis of Blind Spots in Pixio (ViT-H/16) – A Vision Transformer |
|
|
| ## 1. Model Selection |
|
|
| - **Model**: [`facebook/pixio-vith16`](https://huggingface.co/facebook/pixio-vith16) |
| - **Release Date**: 17 Dec 2025 |
| - **Parameters**: 631M |
| - **Modality**: Vision |
| - **Type**: Base model |
|
|
| The model is a Vision Transformer (ViT) with a patch size of 16 and a hidden size of 1280, using 32 layers. A distinctive feature of |
| Pixio is that it uses **8 class tokens** instead of a single `[CLS]` token, each capturing different semantic patterns in the image. |
| This architectural choice is key to the blind‑spot analysis described below. |
|
|
| --- |
|
|
| ## 2. Loading the Model |
|
|
| I loaded the model using the Hugging Face `transformers` library. The following code snippet shows how the model, image processor, and |
| configuration are loaded (expected input). A Hugging Face token is required because the model is gated. |
|
|
| ```python |
| import torch |
| import torchvision |
| from transformers import AutoImageProcessor, AutoModel, AutoConfig |
| from google.colab import userdata |
| |
| device = 'cuda' if torch.cuda.is_available() else 'cpu' |
| |
| config = AutoConfig.from_pretrained("facebook/pixio-vith16", |
| token=userdata.get("TOKEN")) |
| config.output_attentions = True |
| |
| processor = AutoImageProcessor.from_pretrained("facebook/pixio-vith16", |
| config=config, |
| trust_remote_code=True, |
| token=userdata.get("TOKEN")) |
| pixio_base = AutoModel.from_pretrained("facebook/pixio-vith16", |
| config=config, |
| token=userdata.get("TOKEN")).to(device) |
| pixio_base.eval() |
| |
| def transform_image(ex): |
| image = ex['image'].convert('RGB') |
| transform = torchvision.transforms.Compose([ |
| torchvision.transforms.Resize(256), |
| torchvision.transforms.CenterCrop(256), |
| torchvision.transforms.ToTensor(), |
| torchvision.transforms.Normalize(mean=[0.485, 0.456, 0.406], |
| std=[0.229, 0.224, 0.225]) |
| ]) |
| return transform(image), ex['label'] |
| ``` |
|
|
| After loading, I processed 1000 images from the ImageNet‑1k ([link](https://huggingface.co/datasets/ILSVRC/imagenet-1k)) validation set and saved the results locally. For each image I computed the |
| model’s hidden states and attentions once. |
|
|
| --- |
|
|
| ## 3. Blind‑Spot Detection Method: A Hybrid SVD‑Entropy Approach |
|
|
| I developed a hybrid approach combining two complementary metrics to identify inputs where the model is uncertain or internally inconsistent. |
| The expected output is a **transformers.modeling_outputs.BaseModelOutputWithPooling** type object containing last hidden state before the last norm operation , attentions for each layer etc. |
| We are concerned with these two.. |
| |
| ### 3.1 SVD Disagreement (using the 8 CLS tokens) |
| |
| Pixio outputs **8 class tokens** at the final layer: |
| `outputs.last_hidden_state[0, :8, :]` has shape `[8, 1280]`. |
| Each token learns to attend to different image patterns; ideally they should agree on a coherent representation. When |
| they **disagree**, the embeddings will point in different directions – We use singular values to represent this idea, with highest singular |
| value being used to calculate **disagreement**. |
| |
| I form a matrix |
| $$\mathbf{X} \in \mathbf{R}^{8 \times 1280}$$ |
| from these 8 token embeddings, center them, and perform a singular value decomposition: |
| |
| $$ |
| \mathbf{X}_{\text{centered}} = \mathbf{U} \mathbf{S} \mathbf{V}^\top . |
| $$ |
| |
| |
| The singular values |
| |
| $$ |
| \sigma_1 \ge \sigma_2 \ge \dots \ge \sigma_8 |
| $$ |
| |
| indicate how much variance is captured along each direction. If the tokens agree, |
| |
| $$\sigma_1$$ |
| |
| dominates; if they disagree,the energy is spread across many singular values. |
| |
| |
| |
| I define **SVD disagreement** as: |
|
|
| $$ |
| \text{disagreement} = 1 - \frac{\sigma_1}{\sum_{i=1}^{8} \sigma_i} |
| $$ |
| |
| A value close to 1 means high disagreement; close to 0 means strong consensus. |
| |
| ```python |
| cls_tokens = outputs.last_hidden_state[0, :8, :] # [8, 1280] |
| centered = cls_tokens - cls_tokens.mean(dim=0) |
| _, S, _ = torch.svd(centered) |
| disagreement = 1.0 - (S[0] / S.sum()) |
| ``` |
| |
| ### 3.2 Attention Entropy |
| |
| The last‑layer attention weights indicate where each token looks. I average over heads, then compute the attention that the 8 class tokens |
| collectively pay to the patch tokens (indices 8 and above). This gives a probability distribution |
| $$ |
| \mathbf{p} |
| $$ |
| |
| over patches: |
| |
| $$ |
| p_j = \frac{1}{8 \cdot H} \sum_{h=1}^{H} \sum_{k=1}^{8} \text{Attn}_{h,k,j} |
| $$ |
| |
| where |
| $$ |
| H |
| $$ |
| is the number of attention heads. |
| |
| |
| The entropy of this distribution measures how **diffuse** the attention is: |
| |
| $$ |
| \text{entropy} = -\sum_{j} p_j \log(p_j + \epsilon) |
| $$ |
| |
| High entropy means the model is not focusing on any specific region – another indicator of uncertainty. |
| |
| ```python |
| last_layer_attn = outputs.attentions[-1] # [1, heads, seq, seq] |
| cls_to_patch = last_layer_attn[0, :, :8, 8:].mean(dim=(0, 1)) # [num_patches] |
| probs = torch.nn.functional.softmax(cls_to_patch, dim=0) |
| entropy = -torch.sum(probs * torch.log(probs + 1e-10)) |
| ``` |
| |
| ### 3.3 Hybrid SVD‑Entropy Score |
| |
| I combine the two metrics into a single **hybrid SVD‑entropy score**: |
| |
| $$ |
| \text{score} = \text{disagreement} \times \text{entropy} |
| $$ |
| |
| Images with a high score are candidates for being “blind spots” – inputs where the model is likely to make mistakes. |
| |
| |
| --- |
| |
| ## 4. Diverse Sampling via Clustering |
| |
| To avoid selecting near‑duplicate images, I took the top‑1000 highest‑scoring images and clustered them based on **attended features**. |
| These features are the patch token embeddings, weighted by how much attention they receive from the 8 class token. |
| |
| |
| ```python |
| patch_tokens = outputs.last_hidden_state[0, 8:, :] # [num_patches, 1280] |
| attended_features = (patch_tokens * cls_to_patch.unsqueeze(-1)).sum(dim=0) |
| ``` |
| |
| I then applied k‑means clustering (k = 10) on these 1000 feature vectors. From each cluster I selected the image with the highest hybrid |
| score. This yielded **10 diverse, high‑uncertainty samples**. |
| |
| The full selection function: |
| |
| ```python |
| def get_svd_entropy_subset(base_dir, top_n=1000, final_k=10): |
| scores = [] |
| indices = sorted([int(f.split('.')[0]) for f in os.listdir(f"{base_dir}/disagreement")]) |
| for idx in indices: |
| d = torch.load(f"{base_dir}/disagreement/{idx:04d}.pt").item() |
| e = torch.load(f"{base_dir}/entropy/{idx:04d}.pt").item() |
| scores.append({'idx': idx, 'score': d * e, 'svd': d, 'entropy': e}) |
| |
| scores.sort(key=lambda x: x['score'], reverse=True) |
| candidates = scores[:top_n] |
| |
| feats = np.stack([torch.load(f"{base_dir}/attended_features/{c['idx']:04d}.pt").numpy() |
| for c in candidates]) |
| kmeans = KMeans(n_clusters=final_k, n_init=10).fit(feats) |
| |
| selected = [] |
| for i in range(final_k): |
| cluster_members = [candidates[j] for j, label in enumerate(kmeans.labels_) if label == i] |
| if cluster_members: |
| selected.append(max(cluster_members, key=lambda x: x['score'])) |
| return selected |
| ``` |
| |
|
|
|
|
| ## 5. Recommendations for Collecting a Fine‑Tuning Dataset |
|
|
| The same hybrid SVD‑entropy methodology can be used to **automatically mine** a large, diverse set of hard examples from any image collection |
| – for example, from the web, from existing datasets, or from a model’s own misclassifications. |
|
|
| My recommendation however is that the finetuning strategy should be task specific as it is plausible that the model's high entropy in its |
| attention hidden states might be useful for example for other tasks like image to text where it has to describe an image, therefore the |
| behaviour we discovered may not always be undesirable. High disagreement in the class tokens might also useful in such a task as well , as |
| the model would need to pull info from vastly different parts of the image to accurately describe it. |
|
|
|
|
| **Procedure:** |
|
|
| 1. **Gather a large (preferably labelled or label manually after collection) image corpus** – (e.g., CIFAR100, LAION‑5B, Open Images, or even random web crawls). |
| 2. **Run the hybrid SVD‑entropy pipeline** on each image: forward pass, compute SVD disagreement (using the 8 CLS tokens) and attention entropy. |
| 3. **Select the top 0.1% highest‑scoring images** – these are the candidates where the model is most uncertain. |
| 4. **Cluster the selected images** using the attended features (as in step 4) to ensure diversity. |
| 5. **sample from clusters** either uniformly or otherwise to create a collection of high difficulty images and finetune on them |
|
|
| **Dataset size:** |
| A few thousand to tens of thousands of such hard, diverse examples should suffice to noticeably improve the model’s robustness. |
| A good starting point would be **5 000 – 10 000** images, balanced across the clusters. |
| One could then iteratively re‑run my pipeline after each fine‑tuning round to discover new blind spots. |
|
|
| **architectural modifications suggestions:** |
|
|
| Coincidentally i have been reading the differential transformer paper , and i think finetuning a slightly altered model that uses differential |
| attention with the pretrained weights of pixio could be used to also improve performance as it significantly reduces noise in the attention |
| layers which could be one of the reasons for the attention dispersion observed in the samples selected. |
|
|
| I also think finetuning while minimizing the hybrid svd entropy metric as an additional loss function would be beneficial though it would |
| increase computation requirements(especially for svd) and might require full finetuning of all attention layers which would be |
| memory and time intensive. |
|
|
|
|
|
|
| --- |
|
|
| ## 6. Visualizing the diverse samples with attention heatmap overlay |
|
|
|  |
|
|
| ## References |
|
|
| Yang, L., Li, S.-W., Li, Y., Lei, X., Wang, D., Mohamed, A., Zhao, H., & Xu, H. (2025). In Pursuit of Pixel Supervision for Visual Pre-training. arXiv:2512.15715. |
|
|
| Russakovsky, O., Deng, J., Su, H., Krause, J., Satheesh, S., Ma, S., Huang, Z., Karpathy, A., Khosla, A., Bernstein, M., Berg, A. C., & Fei-Fei, L. (2015). ImageNet Large Scale Visual Recognition Challenge. International Journal of Computer Vision (IJCV), 115(3), 211-252. doi.org |
|
|
|
|