| |
| |
| |
|
|
|
|
| |
|
|
|
|
| |
| |
|
|
| |
|
|
| |
| |
| |
| |
| |
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
|
|
|
|
| import os |
| import pandas as pd |
| from datasets import Dataset, Image, Features, Value |
|
|
| |
| df = pd.read_json("data/test.jsonl", lines=True) |
|
|
| |
| def __force_embed_images(example): |
| image_cols = ["ground_truth", "image1_path", "image2_path"] |
| data_root = os.path.abspath("data") |
| |
| for col in image_cols: |
| val = example.get(col) |
| |
| if val and isinstance(val, str): |
| full_path = os.path.join(data_root, val.replace('\\', '/')) |
| if os.path.exists(full_path): |
| with open(full_path, "rb") as f: |
| img_bytes = f.read() |
| example[col] = {"bytes": img_bytes} |
| else: |
| example[col] = None |
| else: |
| example[col] = None |
| return example |
|
|
| |
|
|
| target_features = Features({ |
| "id": Value("string"), |
| "prompt": Value("string"), |
| "task": Value("int64"), |
| "ground_truth": Image(), |
| "color_1": Value("string"), |
| "color_2": Value("string"), |
| "hex_val_1": Value("string"), |
| "hex_val_2": Value("string"), |
| "direction": Value("string"), |
| "shape": Value("string"), |
| "position": Value("string"), |
| "size_ratio": Value("string"), |
| "center_x": Value("string"), |
| "center_y": Value("string"), |
| "mask_type": Value("string"), |
| "image_id": Value("string"), |
| "image1_path": Image(), |
| "image2_path": Image(), |
| }) |
|
|
| |
|
|
| ds = Dataset.from_pandas(df) |
|
|
| |
|
|
| ds = ds.map( |
| __force_embed_images, |
| features=target_features, |
| num_proc=1 |
| ) |
|
|
| |
| ds.to_parquet("violin-test.parquet") |
| print("Success! All images manually embedded into parquet.") |