File size: 8,222 Bytes
d9a36d9 06b250e 56112dd d9a36d9 56112dd 05e45c7 d9a36d9 a6be9cb 05e45c7 6bd2a78 05e45c7 7c7eef6 40a6419 05e45c7 2d1c702 3226efb 2d1c702 3226efb 2d1c702 3226efb 2d1c702 3226efb 05e45c7 5e60101 05e45c7 3b16fd2 05e45c7 9268746 d5f79ea 9268746 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | ---
configs:
- config_name: Color
data_files: data/CLEVR_mini_attribution_color.json
- config_name: Count
data_files: data/CLEVR_mini_attribution_count.json
- config_name: Material
data_files: data/CLEVR_mini_attribution_material.json
license: mit
size_categories:
- 10K<n<80K
---
# CLEVR-Per Dataset README
## Overview
**CLEVR-Per** is a cross-modal dataset integrating images, baseline (true) captions, and permuted (false) captions to facilitate research on "compositional understanding" tasks in vision-language models.
The dataset is designed to explore VLMs' ability to understand semantic changes in vision and textual entities by swapping attributes vocabulary, creating different semantic expressions.
CLEVR-Per contains three subsets: **ColPer** (color semantics permutation), **CntPer** (quantity semantics permutation), and **MatPer** (material semantics permutation), each focusing on specific types of semantic transformations.
## Supported Tasks
**CLEVR-Per** is suitable for the following tasks:
- **Compositional Understanding Evaluation**: Assessing the model's ability to understand semantic changes. The model selects the most relevant description from baseline caption and permuted caption for a given image, testing its compositional understanding.
- **Adversarial Sample Generation**: Researchers can generate diverse adversarial samples using baseline and permuted caption for contrastive training, improving the model's ability to detect erroneous semantics.
<figure>
<img src="./introduction.png" alt="compositional understanding" style="width: 700px;" >
<figcaption>Fig 1. Compositional Understanding: Clip model chose the disturbed incorrect caption, confused in understanding the relationship between entities and attributes.</figcaption>
</figure>
## Data Source and Statistics
The **CLEVR-Per** dataset is derived from **CLEVR** [1], with all baseline and permuted captions generated based on predefined rules and templates.
### Dataset Statistics and Example
| Subset | Number of Images | Baseline Captions | Permuted Captions |
|---------|------------------|--------------------------|-----------------------|
| **ColPer** | 4000 | 16905 | 16905 |
| **CntPer** | 4000 | 7292 | 7292 |
| **MatPer** | 4000 | 10589 | 10589 |
### Data Structure
| Field Name | Data Type | Description |
|--------------------|-------------|--------------------------------------------|
| **image_id** | string | Identifier for the image sample |
| **image_path** | string | Path or URL of the image sample |
| **obj1_name** | string | Name of the first entity in caption |
| **obj2_name** | string | Name of the second entity in caption |
| **true_caption** | string | Baseline caption describing the image |
| **false_caption** | string | Caption formed by swapping attributes in the baseline caption |
| **attributes** | list | List of attributes related to both entities |
| **id** | int | Unique Identifier for the sample |
### Example
| Field Name | Data Type | Description |
|--------------------|-------------|--------------------------------------------|
| **image_id** | string | `000001` |
| **image_path** | string | `CLEVR_mini_000001.png` |
| **obj1_name** | string | `sphere` |
| **obj2_name** | string | `cube` |
| **true_caption** | string | `"yellow sphere and purple cube."` |
| **false_caption** | string | `"purple sphere and yellow cube."` |
| **attributes** | list | `["yellow", "purple"]` |
| **id** | int | `100` |
## Build Your Dataset with Simple Code
Using simple code, you can build your richer and more diverse negative sample dataset obased on CLEVR-Per.
For example:
- "is This a test true caption"
- "caption This is a true test"
- "a test This is true caption"
```python
import random
def generate_negative_samples(true_caption, num_samples=3):
"""
Efficiently generates negative samples by shuffling the word order of a given caption.
Args:
true_caption (str): The original caption.
num_samples (int): The number of negative samples to generate (default: 3).
Returns:
list: A list of generated negative samples.
"""
words = true_caption.split()
word_count = len(words)
# Limit the number of unique permutations to the factorial of word count if needed
max_unique_permutations = min(num_samples, len(set(random.sample(words, word_count)) for _ in range(num_samples)))
# Use a set to avoid duplicates
negative_samples = {
' '.join(random.sample(words, word_count))
for _ in range(max_unique_permutations * 10) # Extra sampling to reduce duplicates
}
# Convert to list and limit the final count
return list(negative_samples)[:num_samples]
# Example usage
true_caption = "This is a test true caption"
negative_samples = generate_negative_samples(true_caption)
print(negative_samples)
```
For example:
|  |  |  |
|-------------------------|-------------------------|-------------------------|
```python
import random
from PIL import Image
import os
def generate_shuffled_images(image_path, grid_size=(4, 4), num_images=3, output_dir="shuffled_images"):
"""
Efficiently generates multiple images by shuffling blocks of the original image.
Args:
image_path (str): Path to the input image.
grid_size (tuple): Number of rows and columns to split the image (e.g., (4, 4)).
num_images (int): Number of shuffled images to generate.
output_dir (str): Directory to save the generated images.
Returns:
None
"""
# Load the image and determine dimensions
image = Image.open(image_path)
img_width, img_height = image.size
rows, cols = grid_size
block_width, block_height = img_width // cols, img_height // rows
# Ensure output directory exists
os.makedirs(output_dir, exist_ok=True)
# Pre-split the image into blocks (avoiding redundant operations)
blocks = [
image.crop((c * block_width, r * block_height, (c + 1) * block_width, (r + 1) * block_height))
for r in range(rows) for c in range(cols)
]
# Generate shuffled images
for i in range(num_images):
random.shuffle(blocks) # In-place shuffle for better efficiency
shuffled_image = Image.new('RGB', (img_width, img_height))
for idx, block in enumerate(blocks):
r, c = divmod(idx, cols)
shuffled_image.paste(block, (c * block_width, r * block_height))
# Save the shuffled image
output_path = os.path.join(output_dir, f"shuffled_image_{i + 1}.png")
shuffled_image.save(output_path)
print(f"Generated: {output_path}")
# Example usage
input_image_path = "/mnt/data/2276b7b0-17f8-458c-bbc0-24abf62ab34b.png"
generate_shuffled_images(image_path=input_image_path, grid_size=(4, 4), num_images=3)
```
## References
[1]. **CLEVR**. CLEVR: A Diagnostic Dataset for Compositional Language and Elementary Visual Reasoning. *Justin Johnson*, 2017. https://cs.stanford.edu/people/jcjohns/clevr/.
### If you use this dataset, please cite it as follows. My homepage https://tongli97.github.io/.
<pre>
@misc{cleverper_dataset,
author = {Tong Li, Guodao Sun*, Xueqian Zheng, Qi Jiang, Wang Xia, Xu Tan, Haidong Gao, Jingwei Tang, Yunchao Wang, Haixia Wang, Ronghua Liang},
title = {CompoVis: Is Cross-modal Semantic Alignment of CLIP Optimal? A Visual Analysis Attempt},
year = {2026},
publisher = {IEEE Transactions on Multimedia},
DOI = {10.1109/TMM.2026.3660158}
howpublished = {\url{https://huggingface.co/datasets/guodaosun/CompoVIS}},
}
</pre>
## Contact Information
- **Author**: Tong Li (李童)
- **Email**: litong@zjut.edu.cn
- **Project Page**: https://tongli97.github.io/ |