# How to extract Images from Arrow datasets

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-extract-images-from-arrow-datasets%2F133217%3E%5C
**Category:** Beginners\
**Created:** [December 27, 2024, 10:03am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-extract-images-from-arrow-datasets%2F133217 "2024-12-27T10:03:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DimOnHF](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@DimOnHF](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FDimOnHF)%5C
**Post date:** [December 27, 2024, 10:03am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-extract-images-from-arrow-datasets%2F133217%2F1 "2024-12-27T10:03:42Z")

</div>

Hello all,

I’m new working with Arrow format. And I just can’t find any support on how to extract the Image data from the arrow dataset I downloaded on HG.

I have the arrow file locally with the JSON file as well but can’t find a way to extract the data from it.

from datasets import Dataset  
ds = Dataset.from\_file(“path/to/data.arrow”)

→ doesn’t work as “TypeError: expected bytes, WindowsPath found”

---

<div class="post-metadata">

**Author:** ![Alanturner2](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/alanturner2/32/37542_2.png) [@Alanturner2](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FAlanturner2)%5C
**Post date:** [December 27, 2024, 10:16am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-extract-images-from-arrow-datasets%2F133217%2F2 "2024-12-27T10:16:46Z")

</div>

Here’s how you can do it:

python

Copy code

```auto
from datasets import Dataset

# Ensure the file path is a string
file_path = "path/to/data.arrow" # Replace with your actual file path

# Load the dataset
ds = Dataset.from_file(file_path)

```

If you’re using Python’s `pathlib` to handle file paths, convert the `Path` object to a string before passing it to the `from_file` method:

python

Copy code

```auto
from datasets import Dataset
from pathlib import Path

# Define the file path using pathlib
file_path = Path("path/to/data.arrow") # Replace with your actual file path

# Convert the Path object to a string
ds = Dataset.from_file(str(file_path))

```

Regarding the image data extraction, once you’ve successfully loaded the dataset, you can access the image data assuming the dataset contains an image column. The `datasets` library provides an `Image` feature to handle image data. If your dataset includes file paths to images, you can cast the relevant column to the `Image` feature to facilitate image processing:

python

Copy code

```auto
from datasets import Dataset, Image

# Load the dataset
ds = Dataset.from_file("path/to/data.arrow")

# Cast the image column to the Image feature
ds = ds.cast_column("image_column_name", Image()) # Replace 'image_column_name' with your actual column name

# Access an image
image = ds[0]["image"]

```

This approach will decode the image file into a PIL image object, allowing for further manipulation or analysis. For more detailed information on processing image data with the `datasets` library, refer to the official documentation.

---

<div class="post-metadata">

**Author:** ![DimOnHF](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@DimOnHF](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FDimOnHF)%5C
**Post date:** [December 27, 2024, 10:30am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-extract-images-from-arrow-datasets%2F133217%2F4 "2024-12-27T10:30:47Z")

</div>

Thank you very much @Alanturner2 !!!

Indeed the issues comes from using Path without converting it to a string !

---

<div class="post-metadata">

**Author:** ![Alanturner2](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/alanturner2/32/37542_2.png) [@Alanturner2](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FAlanturner2)%5C
**Post date:** [December 27, 2024, 10:41am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-extract-images-from-arrow-datasets%2F133217%2F5 "2024-12-27T10:41:06Z")

</div>

I hoped your success in your project.  
I am so happy. Cheer up! I hope your success!
