| import os |
| import pandas as pd |
| from datasets import Dataset, Image, Features, Value |
|
|
|
|
| df = pd.read_json("data/metadata.jsonl", lines=True) |
|
|
|
|
| def get_full_path(file_name): |
| return os.path.join(os.getcwd(), "data", file_name) |
|
|
| df['image_path'] = df['file_name'].apply(get_full_path) |
|
|
| |
| def __force_embed_image(example): |
| |
| with open(example["image_path"], "rb") as f: |
| image_bytes = f.read() |
| return {"image": {"bytes": image_bytes}} |
|
|
|
|
| ds = Dataset.from_pandas(df) |
|
|
|
|
| ds = ds.map(__force_embed_image, remove_columns=["image_path"], num_proc=1) |
|
|
|
|
| ds = ds.cast_column("image", Image()) |
|
|
|
|
| ds.to_parquet("violin-test.parquet") |