# Ray dataset with multiple images per batch

**URL:** <https://discuss.ray.io/t/ray-dataset-with-multiple-images-per-batch/12008>\
**Category:** Uncategorized\
**Created:** [September 1, 2023, 5:31pm UTC](https://discuss.ray.io/t/ray-dataset-with-multiple-images-per-batch/12008 "2023-09-01T17:31:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ybrandt](https://avatars.discourse-cdn.com/v4/letter/y/bcef8e/32.png) [@ybrandt](https://discuss.ray.io/u/ybrandt)\
**Post date:** [September 1, 2023, 5:31pm UTC](https://discuss.ray.io/t/ray-dataset-with-multiple-images-per-batch/12008/1 "2023-09-01T17:31:17Z")

</div>

Hi,

I’d like to convert a Pytorch dataset to a Ray dataset.  
Every batch has three keys: id (int), image:ndarray, mask:ndarray  
However, I can’t find an out-of-the-box solution from Ray data to read two images from disk.

Currently, I see 2 Options:

1. Read a CSV with the ids and use the transform step to read the images
2. Build a custom Datasource, that reads two images from disk

Am I missing something?

Cheers,  
Yannick

---

<div class="post-metadata">

**Author:** ![amogkam](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/amogkam/32/17_2.png) [@amogkam](https://discuss.ray.io/u/amogkam)\
**Post date:** [September 1, 2023, 5:42pm UTC](https://discuss.ray.io/t/ray-dataset-with-multiple-images-per-batch/12008/2 "2023-09-01T17:42:21Z")

</div>

You can use the `read_images` API? [Working with Images — Ray 2.6.1](https://docs.ray.io/en/latest/data/working-with-images.html)

---

<div class="post-metadata">

**Author:** ![ybrandt](https://avatars.discourse-cdn.com/v4/letter/y/bcef8e/32.png) [@ybrandt](https://discuss.ray.io/u/ybrandt)\
**Post date:** [September 1, 2023, 5:45pm UTC](https://discuss.ray.io/t/ray-dataset-with-multiple-images-per-batch/12008/3 "2023-09-01T17:45:13Z")

</div>

Thx for the quick reply, but wouldn’t this just give me a dataset with either image or mask?

---

<div class="post-metadata">

**Author:** ![amogkam](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/amogkam/32/17_2.png) [@amogkam](https://discuss.ray.io/u/amogkam)\
**Post date:** [September 1, 2023, 9:55pm UTC](https://discuss.ray.io/t/ray-dataset-with-multiple-images-per-batch/12008/4 "2023-09-01T21:55:03Z")

</div>

How is your data stored?

---

<div class="post-metadata">

**Author:** ![ybrandt](https://avatars.discourse-cdn.com/v4/letter/y/bcef8e/32.png) [@ybrandt](https://discuss.ray.io/u/ybrandt)\
**Post date:** [September 1, 2023, 10:02pm UTC](https://discuss.ray.io/t/ray-dataset-with-multiple-images-per-batch/12008/5 "2023-09-01T22:02:53Z")

</div>

data  
\_\_\_\_images  
\_\_\_\_\_\_\_\_\_1.tiff  
\_\_\_\_\_\_\_\_\_2.tiff  
\_\_\_\_masks  
\_\_\_\_\_\_\_\_\_1.tiff  
\_\_\_\_\_\_\_\_\_2.tiff

---

<div class="post-metadata">

**Author:** ![amogkam](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/amogkam/32/17_2.png) [@amogkam](https://discuss.ray.io/u/amogkam)\
**Post date:** [September 1, 2023, 10:36pm UTC](https://discuss.ray.io/t/ray-dataset-with-multiple-images-per-batch/12008/6 "2023-09-01T22:36:41Z")

</div>

Got it. Then I would go with your first approach.
