Datasets:
bug fix
Browse files- scripts/to_parquet.py +13 -5
- violin-test.parquet +2 -2
scripts/to_parquet.py
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
from datasets import Dataset, Image
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
|
| 6 |
df = pd.read_json("data/metadata.jsonl", lines=True)
|
| 7 |
|
| 8 |
|
| 9 |
-
|
| 10 |
-
return os.path.join(os.getcwd(),"data", path)
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
-
ds = Dataset.from_pandas(df)
|
| 16 |
ds = ds.cast_column("image", Image())
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
ds.to_parquet("violin-test.parquet", batch_size=10000)
|
|
|
|
| 1 |
+
import os
|
| 2 |
import pandas as pd
|
| 3 |
from datasets import Dataset, Image
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
df = pd.read_json("data/metadata.jsonl", lines=True)
|
| 7 |
|
| 8 |
|
| 9 |
+
df['image'] = df['file_name'].apply(lambda x: os.path.join(os.getcwd(), "data", x))
|
|
|
|
| 10 |
|
| 11 |
+
ds = Dataset.from_pandas(df)
|
| 12 |
+
|
| 13 |
+
# 3. Define the transformation and trigger the read.
|
| 14 |
+
def load_image_bytes(example):
|
| 15 |
+
# No operation is required here, but the map process will trigger encoding and decoding of the Image() type.
|
| 16 |
+
# Force the path to be converted to in-memory image data.
|
| 17 |
+
return {"image": example["image"]}
|
| 18 |
|
| 19 |
|
|
|
|
| 20 |
ds = ds.cast_column("image", Image())
|
| 21 |
|
| 22 |
+
ds = ds.map(load_image_bytes, num_proc=1)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
print(f"first entry: {ds[0]}")
|
| 26 |
|
| 27 |
ds.to_parquet("violin-test.parquet", batch_size=10000)
|
violin-test.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:399d0a9956f159293e8027e28d76e873df3e7091839c5cb94b1d54aee0f5bd99
|
| 3 |
+
size 1981175
|