Datasets:
File size: 3,838 Bytes
c83afe9 | 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 | import csv
import json
import os
METADATA_DIR = "metadata"
OUTPUT_JSONL = "data/test.jsonl"
def read_csv(path):
with open(path, "r", encoding="utf-8") as f:
return list(csv.DictReader(f))
def build_metadata():
entries = []
# --- Task_Color_Var1 ---
path1 = os.path.join(METADATA_DIR, "Task_Color_Var1_metadata.csv")
if os.path.exists(path1):
for row in read_csv(path1):
id_val = row["id"].strip()
entries.append({
"id": f"id_{id_val}",
"prompt": row.get("prompt", "").strip(),
# "split": row.get("split", "test"),
"color_1": row.get("color_1", ""),
"hex_val_1": row.get("hex_val_1", ""),
"task": 1,
"ground_truth": f"Task_Color_Var1/id_{id_val}.png",
})
else:
print(f"Warning: {path1} not found, skipping Task_Color_Var1")
# --- Task_Color_Var2 ---
path2 = os.path.join(METADATA_DIR, "Task_Color_Var2_metadata.csv")
if os.path.exists(path2):
for row in read_csv(path2):
id_val = row["id"].strip()
entries.append({
"id": f"id_{id_val}",
"prompt": row.get("prompt", "").strip(),
# "split": row.get("split", "test"),
"color_1": row.get("color_1", ""),
"color_2": row.get("color_2", ""),
"hex_val_1": row.get("hex_val_1", ""),
"hex_val_2": row.get("hex_val_2", ""),
"direction": row.get("direction", ""),
"task": 2,
"ground_truth": f"Task_Color_Var2/id_{id_val}.png",
})
else:
print(f"Warning: {path2} not found, skipping Task_Color_Var2")
# --- Task_Geometric ---
path3 = os.path.join(METADATA_DIR, "Task_Geometric_metadata.csv")
if os.path.exists(path3):
for row in read_csv(path3):
id_val = row["id"].strip()
entries.append({
"id": f"id_{id_val}",
"prompt": row.get("prompt", "").strip(),
"shape": row.get("shape", ""),
"position": row.get("position", ""),
"size_ratio": row.get("size_ratio", ""),
"center_x": row.get("center_x", ""),
"center_y": row.get("center_y", ""),
"task": 3,
"ground_truth": f"Task_Geometric/id_{id_val}.png",
})
else:
print(f"Warning: {path3} not found, skipping Task_Geometric")
# --- Task_Image_Mask ---
for mask_type in ["inpainting", "outpainting", "random"]:
path4 = os.path.join(METADATA_DIR, f"Task_Image_Mask_{mask_type}_metadata.csv")
if not os.path.exists(path4):
print(f"Warning: {path4} not found, skipping Task_Image_Mask {mask_type}")
continue
for row in read_csv(path4):
id_val = row["id"].strip()
img1 = row.get("image1_path", "").strip().replace('\\', '/')
img2 = row.get("image2_path", "").strip().replace('\\', '/')
entries.append({
"id": f"id_{id_val}",
"prompt": row.get("prompt", "").strip(),
"mask_type": mask_type,
"image_id": row.get("image_id", ""),
"image1_path": img1,
"image2_path": img2,
"task": 4,
"ground_truth": f"Task_Image_Mask/{mask_type}/id_{id_val}.png",
})
os.makedirs(os.path.dirname(OUTPUT_JSONL), exist_ok=True)
with open(OUTPUT_JSONL, "w", encoding="utf-8") as f:
for entry in entries:
f.write(json.dumps(entry, ensure_ascii=False) + "\n")
print(f"Total {len(entries)} entries → {OUTPUT_JSONL}")
if __name__ == "__main__":
build_metadata()
|