Creating parquet
Hi
@nielsr
, I am looking for any tutorial or script to show how to load the image dataset like you did here; with the image displayed as a column in a dataframe along with other columns of metadata.
I'll keep looking but if you have naything handy, it would be great if you could share.
Thanks
Hi,
The Parquet files are created automatically when doing dataset.push_to_hub
.
Note that you can for instance start from a dataframe, then turn it into a HuggingFace Dataset using the from_pandas
method, and then do push_to_hub
.
In code:
from datasets import Dataset
import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3]})
dataset = Dataset.from_pandas(df)
# assuming you're logged in with your token
dataset.push_to_hub("nielsr/my-awesome-dataset")
Thanks!
And to include images like you have in the dataset? I tried the below and the image cannot be converted to a Dataset
. I'll try encoding the image as bytes, but I'm not sure if the Dataset
automatically knows when to decode.
import os, glob
from PIL import Image
from datasets import Dataset
import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3],
"b": [Image.open(i) for i in glob.glob('orix/data/ChiSig/*')[:3]]})
dataset = Dataset.from_pandas(df) # Fails here --- ('Could not convert <PIL.JpegImagePlug etc..
# assuming you're logged in with your token
dataset.push_to_hub("nielsr/my-awesome-dataset")
ps. I did try the below... it looks like the dataset needs to be public for the Viewer to show, like here, which solves one problem. However the images are still not showing...
import glob
from PIL import Image
import datasets
feats=datasets.Features({"images": datasets.Image(), })
img_names = glob.glob('orix/data/ChiSig/*')[:20]
test_data = {"images": [Image.open(i) for i in img_names]}
test_dataset=datasets.Dataset.from_dict(test_data,features=feats)
test_dataset.push_to_hub("darragh/demo_data_raw3")
Yes you need to add the features
argument to the from_pandas
method as well (to indicate the type of each column), like so:
from datasets import Dataset, Features, Image, Value
import pandas as pd
import requests
import PIL
# we need to define the features ourselves
features = Features({
'a': Value(dtype='int32'),
'b': Image(decode=True),
})
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = PIL.Image.open(requests.get(url, stream=True).raw)
df = pd.DataFrame({"a": [1, 2],
"b": [image, image]})
dataset = Dataset.from_pandas(df, features=features)
However, this fails for me so I've asked @mariosasko here: https://github.com/huggingface/datasets/issues/4796#issuecomment-1213110543
And regarding the Viewer, it takes some time for it to display the images. I've pinged one of our team members for this!
I believe in private datasets it does not appear; once I made public it appeared pretty quickly.
Oh ok, yes the Viewer is currently disabled for private datasets. But we're working on adding support for private datasets as well!
Hi I have a image dataset folder which contains around 43,591 images
while manually drag and drop folders to hugging face its taking only 3800 files.
Can u tell me why this is happening?
And how to convert image prefetch_dataset to parquet type.
Thanks .