Support for nested image lists (multi-view arrays) and improvements on image file handling - #1
Support for nested image lists (multi-view arrays) and improvements on image file handling#1dalgarak wants to merge 4 commits into
Conversation
- Refactor `ImageArray._from_sequence` and `_from_sequence_of_strings` to recursively process and preserve `list` and `np.ndarray` structures. - Prevent "Too many open files" OS errors by enforcing immediate file handle closure via `img.copy()` during load. - Fix `ArrowTypeError` in Parquet serialization by introducing dynamic PyArrow schema resolution (`pa.list_`) and recursive encoding/decoding in `_encode_pil_image` and `_decode_pil_image`. - Update `ImageArray.feature` to dynamically return Hugging Face `Sequence` type for multi-view data. - Fix `PILMethods.enable` to prevent truncation of lists into single elements when wrapping back into a pandas Series. - Enhance `html_formatter` to render multiple image thumbnails horizontally within Jupyter Notebooks when dealing with nested lists.
|
Hi ! In this PR I undertsand you are adding Maybe we can focus first on your use case for lists import pandas as pd
from pandas_image_methods import PILMethods, ListMethods
pd.api.extensions.register_series_accessor("pil")(PILMethods)
pd.api.extensions.register_series_accessor("list")(ListMethods)
df = pd.DataFrame({"file_paths": [["path/to/image.png"]]})
df["images"] = df["file_paths"].list.pil.open()
df["images"] = df["image"].list.pil.rotate(90)
# 0 [<PIL.Image.Image size=200x200>]
# Name: images, dtype: object, List methods enabledwdyt ? Otherwise I'm a bit concerned about the ambiguities of appliying |
…guity, and reverts _encode_pil/_decode_pil_images (2) add ListMethods, DictMethods over Nested PILMethods Proxy (3) remove auto-registration
|
LGTM! Thanks for the suggestion. I've implemented ListMethods and DictMethods as you suggested. Here's the summary of the changes:
I noticed a UserWarning when overriding the default pandas .list attribute, but it's working as intended. Also confirmed that Dataset.from_pandas(df) correctly recognizes the features as List[Image]. tested with: expected results: |
Feat: Support for nested image lists (multi-view arrays) & improvements on image file handling
Motivation & Context
When working with multi-view datasets, such as the InternScience/SFE dataset, a single DataFrame cell often contains an array of image paths (e.g.,
['front.png', 'side.png', 'top.png']).While fixing the string paths themselves can be done with simple mapping operations, the original library strictly fails to generate an image-embedded Parquet file from these nested lists, throwing an
ArrowTypeError. The primary motivation of this PR is to fix the core serialization pipeline so that saving and loading image-embedded Parquet files works flawlessly for multi-view data.Changes
The following functions were refactored to support recursive processing of list and np.ndarray structures and hf dataset compatibility:
Supplementary Improvements