CompoVIS / README.md
guodaosun's picture
Update README.md
3b16fd2 verified
|
Raw
History Blame Contribute Delete
8.22 kB
metadata
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.
compositional understanding
Fig 1. Compositional Understanding: Clip model chose the disturbed incorrect caption, confused in understanding the relationship between entities and attributes.

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"
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:

Image 1 Image 2 Image 3
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/.

@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}},
}

Contact Information