CoolFace
Datasetpublic

Zhongchenchen/SenseBench_subset

SenseBench A benchmark for remote sensing low-level visual perception and description in large vision-language models. 🏠 github | 🤗 Hugging Face Fullset Overview SenseBench is a remote sensing benchmark for evaluating low-level visual perception and description in large vision-language models. Supported Tasks Visual question answering Text generation Language English Data format Each example contains image paths… See the full description on the dataset page: https://huggingface.co/datasets/Zhongchenchen/SenseBench_subset.

sourceHugging Facecc-by-4.0updated 5mo agoView on Hugging Face
1likes58downloads
sample.py119 linesDownload Raw Back to root
1"""Stratified sampling of SenseBench dataset (1000 instances).2 3Sampling strategy:4- Preserve the original distribution of task types5- Preserve the original distribution of image_count (single/paired)6- Fixed random seed for reproducibility7- Output structure: Perception/{single,paired}, Description/{single,paired}8"""9 10import json11import random12import shutil13from pathlib import Path14from collections import Counter15 16SEED = 4217N_SAMPLE = 100018SRC_DIR = Path("/home/anxiao/zhongchen/Sensebench/data_hf")19DST_DIR = Path("/home/anxiao/zhongchen/Sensebench/codex_code/seleted")20 21 22def main():23    random.seed(SEED)24 25    records = []26    with open(SRC_DIR / "questions.jsonl", encoding="utf-8") as f:27        for line in f:28            records.append(json.loads(line))29 30    total = len(records)31    print(f"Total records: {total}")32 33    # Stratify by (task_category, image_count)34    groups = {}35    for r in records:36        meta = r["meta"]37        cat = "Description" if meta["task"] == "description" else "Perception"38        sub = "paired" if meta["image_count"] == "multi" else "single"39        key = (cat, sub)40        groups.setdefault(key, []).append(r)41 42    print("\nOriginal distribution:")43    for key in sorted(groups):44        print(f"  {key}: {len(groups[key])} ({len(groups[key])/total*100:.1f}%)")45 46    # Proportional sampling47    sampled = []48    for key in sorted(groups):49        group = groups[key]50        n = max(1, round(len(group) / total * N_SAMPLE))51        sampled.extend(random.sample(group, min(n, len(group))))52 53    if len(sampled) > N_SAMPLE:54        sampled = random.sample(sampled, N_SAMPLE)55    elif len(sampled) < N_SAMPLE:56        remaining = [r for r in records if r not in sampled]57        sampled.extend(random.sample(remaining, N_SAMPLE - len(sampled)))58 59    random.shuffle(sampled)60 61    # Print sampled distribution62    sampled_counter = Counter()63    for r in sampled:64        meta = r["meta"]65        cat = "Description" if meta["task"] == "description" else "Perception"66        sub = "paired" if meta["image_count"] == "multi" else "single"67        sampled_counter[(cat, sub)] += 168 69    print(f"\nSampled: {len(sampled)}")70    print("Sampled distribution:")71    for key in sorted(sampled_counter):72        n = sampled_counter[key]73        print(f"  {key}: {n} ({n/len(sampled)*100:.1f}%)")74 75    # Create subdirs and copy images76    for cat in ["Perception", "Description"]:77        for sub in ["single", "paired"]:78            (DST_DIR / cat / sub).mkdir(parents=True, exist_ok=True)79 80    copied = set()81    with open(DST_DIR / "questions.jsonl", "w", encoding="utf-8") as f:82        for r in sampled:83            meta = r["meta"]84            cat = "Description" if meta["task"] == "description" else "Perception"85            sub = "paired" if meta["image_count"] == "multi" else "single"86 87            new_images = []88            for img_rel in r["images"]:89                img_name = Path(img_rel).name90                new_images.append(f"{cat}/{sub}/{img_name}")91 92                if img_name not in copied:93                    src_img = SRC_DIR / img_rel94                    dst_img = DST_DIR / cat / sub / img_name95                    if src_img.exists() and not dst_img.exists():96                        shutil.copy2(src_img, dst_img)97                    copied.add(img_name)98 99            r["images"] = new_images100            f.write(json.dumps(r, ensure_ascii=False) + "\n")101 102    # Stats103    print("\nOutput:")104    total_size = 0105    for cat in ["Perception", "Description"]:106        for sub in ["single", "paired"]:107            d = DST_DIR / cat / sub108            n = len(list(d.iterdir()))109            s = sum(f.stat().st_size for f in d.iterdir()) / (1024**2)110            total_size += s111            print(f"  {cat}/{sub}: {n} images, {s:.1f} MB")112    print(f"  Total: {total_size:.1f} MB")113    print(f"  Seed: {SEED}")114    print(f"\nOutput: {DST_DIR}")115 116 117if __name__ == "__main__":118    main()119