Added support for JXL images.
MEMBER
I'm fine with the addition of jxl in the list of known image extensions, this way users that have the plugin can work with their JXL datasets. WDYT @mariosasko ?
2022-11-24T14:15:44Z
https://github.com/huggingface/datasets/pull/5289#issuecomment-1326511093
https://api.github.com/repos/huggingface/datasets/issues/5289
IC_kwDODunzps5PEPP1
https://api.github.com/repos/huggingface/datasets/issues/comments/1326511093/reactions
2022-11-24T14:15:44Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1326511093
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
NONE
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/datasets/pr_5289). All of your documentation changes will be reflected on that endpoint.
2022-11-24T14:25:00Z
https://github.com/huggingface/datasets/pull/5289#issuecomment-1326521578
https://api.github.com/repos/huggingface/datasets/issues/5289
IC_kwDODunzps5PERzq
https://api.github.com/repos/huggingface/datasets/issues/comments/1326521578/reactions
2022-11-24T14:25:00Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1326521578
https://avatars.githubusercontent.com/u/99929124?v=4
https://api.github.com/users/HuggingFaceDocBuilderDev/events{/privacy}
https://api.github.com/users/HuggingFaceDocBuilderDev/followers
https://api.github.com/users/HuggingFaceDocBuilderDev/following{/other_user}
https://api.github.com/users/HuggingFaceDocBuilderDev/gists{/gist_id}
https://github.com/HuggingFaceDocBuilderDev
HuggingFaceDocBuilderDev
U_kgDOBfTMJA
https://api.github.com/users/HuggingFaceDocBuilderDev/orgs
https://api.github.com/users/HuggingFaceDocBuilderDev/received_events
https://api.github.com/users/HuggingFaceDocBuilderDev/repos
https://api.github.com/users/HuggingFaceDocBuilderDev/starred{/owner}{/repo}
https://api.github.com/users/HuggingFaceDocBuilderDev/subscriptions
User
https://api.github.com/users/HuggingFaceDocBuilderDev
public
COLLABORATOR
I think we should wait for official support from Pillow. Plus, the linked plugin doesn't support `Image.save`, which is one of the requirements for a format to be included in `IMAGE_EXTENSIONS`.

@alexjc In the meantime, one option is to add these lines to the card:
```python
import importlib
import datasets

if ".jxl" not in datasets.packaged_modules.imagefolder.IMAGE_EXTENSIONS:
  datasets.packaged_modules.imagefolder.IMAGE_EXTENSIONS.append(".jxl")

if "jxl" not in datasets.packaged_modules._EXTENSION_TO_MODULE:
  datasets.packaged_modules._EXTENSION_TO_MODULE["jxl"] = ("imagefolder", {})

importlib.reload(datasets.load)
ds = datasets.load_dataset("texturedesign/td01_natural-ground-textures")
```
And you can add a note to the card that this dataset requires the "jxlpy" package to work. 

In this case, you can also disable the viewer to avoid the discrepancy between the data displayed in the preview and the loaded data.

Another option is to define the loading script and add `jxlpy` to the list of dependencies [here](https://github.com/huggingface/datasets-server/blob/3012da62054a025467616abc14b0b46e1f11ea13/workers/first_rows/pyproject.toml#L8) to enable the viewer. This option requires more work, so let us know if you need help.
2022-11-24T19:38:49Z
https://github.com/huggingface/datasets/pull/5289#issuecomment-1326796321
https://api.github.com/repos/huggingface/datasets/issues/5289
IC_kwDODunzps5PFU4h
https://api.github.com/repos/huggingface/datasets/issues/comments/1326796321/reactions
2022-11-24T19:38:49Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1326796321
https://avatars.githubusercontent.com/u/47462742?v=4
https://api.github.com/users/mariosasko/events{/privacy}
https://api.github.com/users/mariosasko/followers
https://api.github.com/users/mariosasko/following{/other_user}
https://api.github.com/users/mariosasko/gists{/gist_id}
https://github.com/mariosasko
mariosasko
MDQ6VXNlcjQ3NDYyNzQy
https://api.github.com/users/mariosasko/orgs
https://api.github.com/users/mariosasko/received_events
https://api.github.com/users/mariosasko/repos
https://api.github.com/users/mariosasko/starred{/owner}{/repo}
https://api.github.com/users/mariosasko/subscriptions
User
https://api.github.com/users/mariosasko
public
NONE
Thank you both for your thoughtful replies!

One questions and and update:
* The jxlpy plugin does support saving, in the `_save` function of the JXLImagePlugin file.  Did it not work?  I'm working on the upgrade to the latest JXL, so it'd be good to know if it failed so I can fix it.
* I wrote to the Pillow maintainer and the preferred solution would be to keep JXL as a separate plugin because they're a small team don't have the resources to maintain more code.

With that in mind, let me share the minimal set of features I'd need for this to work within the `datasets` library:
1. Using `load_dataset()` with the HuggingFace dataset name correctly downloads the JXL files so they are available locally. Even if the `file_name` field is left intact and not loaded as a PIL image, this is the first step.
2. With minimal monkey-patching, having the `load_dataset` correctly expand `file_name` into PIL `image` fields if JXL support is available.

If both of these work, then I can use HuggingFace's hub and the `datasets` library for an MVP even if not all features are there.  I don't need automatic thumbnails or previews of the dataset on the server.


Given the reply from the Pillow maintainer, what solution can we come up with that works in a more permanent way than waiting for Pillow integration (which may not happen) — assuming users install the `jxlpy` plugin separately?
2022-11-25T09:53:35Z
https://github.com/huggingface/datasets/pull/5289#issuecomment-1327249392
https://api.github.com/repos/huggingface/datasets/issues/5289
IC_kwDODunzps5PHDfw
https://api.github.com/repos/huggingface/datasets/issues/comments/1327249392/reactions
2022-11-25T09:53:35Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1327249392
https://avatars.githubusercontent.com/u/445208?v=4
https://api.github.com/users/alexjc/events{/privacy}
https://api.github.com/users/alexjc/followers
https://api.github.com/users/alexjc/following{/other_user}
https://api.github.com/users/alexjc/gists{/gist_id}
https://github.com/alexjc
alexjc
MDQ6VXNlcjQ0NTIwOA==
https://api.github.com/users/alexjc/orgs
https://api.github.com/users/alexjc/received_events
https://api.github.com/users/alexjc/repos
https://api.github.com/users/alexjc/starred{/owner}{/repo}
https://api.github.com/users/alexjc/subscriptions
User
https://api.github.com/users/alexjc
public
NONE
Link to my upgrade for the latest `libjxl`, pending review and merge. I tested load/save via Pillow extensively for this: https://github.com/olokelo/jxlpy/pull/13
2022-11-25T09:56:58Z
https://github.com/huggingface/datasets/pull/5289#issuecomment-1327257593
https://api.github.com/repos/huggingface/datasets/issues/5289
IC_kwDODunzps5PHFf5
https://api.github.com/repos/huggingface/datasets/issues/comments/1327257593/reactions
2022-11-25T09:56:58Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1327257593
https://avatars.githubusercontent.com/u/445208?v=4
https://api.github.com/users/alexjc/events{/privacy}
https://api.github.com/users/alexjc/followers
https://api.github.com/users/alexjc/following{/other_user}
https://api.github.com/users/alexjc/gists{/gist_id}
https://github.com/alexjc
alexjc
MDQ6VXNlcjQ0NTIwOA==
https://api.github.com/users/alexjc/orgs
https://api.github.com/users/alexjc/received_events
https://api.github.com/users/alexjc/repos
https://api.github.com/users/alexjc/starred{/owner}{/repo}
https://api.github.com/users/alexjc/subscriptions
User
https://api.github.com/users/alexjc
public
NONE
After more research, here's my latest suggestion:
* Depending on the build of pillow, the source (pip or conda), the platform even, certain formats may or may not be available — despite them being in the list.  For example, webp support is not consistently available.
* I'd suggest adding JXL to the list and simply catching the `PIL.UnidentifiedImageError` — printing a useful error message that sends them to a Wiki page to find out what to do.
* On that page would be included instructions how to install support for the format and what to do for the dataset to load correctly on any platform, both with or without conda, etc.

What do you think?
2022-11-28T20:27:23Z
https://github.com/huggingface/datasets/pull/5289#issuecomment-1329723081
https://api.github.com/repos/huggingface/datasets/issues/5289
IC_kwDODunzps5PQfbJ
https://api.github.com/repos/huggingface/datasets/issues/comments/1329723081/reactions
2022-11-28T20:27:23Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1329723081
https://avatars.githubusercontent.com/u/445208?v=4
https://api.github.com/users/alexjc/events{/privacy}
https://api.github.com/users/alexjc/followers
https://api.github.com/users/alexjc/following{/other_user}
https://api.github.com/users/alexjc/gists{/gist_id}
https://github.com/alexjc
alexjc
MDQ6VXNlcjQ0NTIwOA==
https://api.github.com/users/alexjc/orgs
https://api.github.com/users/alexjc/received_events
https://api.github.com/users/alexjc/repos
https://api.github.com/users/alexjc/starred{/owner}{/repo}
https://api.github.com/users/alexjc/subscriptions
User
https://api.github.com/users/alexjc
public
COLLABORATOR
> The jxlpy plugin does support saving, in the _save function of the JXLImagePlugin file. Did it not work? I'm working on the upgrade to the latest JXL, so it'd be good to know if it failed so I can fix it.

My bad, I was referring to [this](https://github.com/google/brunsli/blob/2dd949e53ed05796eb44a31cc759fbf9e6c53e2f/contrib/py/jxl_library_patches/jxl_pillow.py) version of the plugin.

I still think this involves too much work:
* would require a new doc page
* unofficial plugins have to be imported explicitly, leading to messier code on our side
* etc.

For now, it seems more reasonable to create a loading script (faster than ImageFolder, as ImageFolder has to resolve the image files first) for this particular case and add `jxlpy` to the list of the `datasets-server`'s dependencies. Also, one additional advantage of this approach is that it reports if any of the modules imported in a script is missing, which is handy in your case for the plugin lib. WDYT?
2022-11-29T15:06:58Z
https://github.com/huggingface/datasets/pull/5289#issuecomment-1330793753
https://api.github.com/repos/huggingface/datasets/issues/5289
IC_kwDODunzps5PUk0Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1330793753/reactions
2022-11-29T15:06:58Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1330793753
https://avatars.githubusercontent.com/u/47462742?v=4
https://api.github.com/users/mariosasko/events{/privacy}
https://api.github.com/users/mariosasko/followers
https://api.github.com/users/mariosasko/following{/other_user}
https://api.github.com/users/mariosasko/gists{/gist_id}
https://github.com/mariosasko
mariosasko
MDQ6VXNlcjQ3NDYyNzQy
https://api.github.com/users/mariosasko/orgs
https://api.github.com/users/mariosasko/received_events
https://api.github.com/users/mariosasko/repos
https://api.github.com/users/mariosasko/starred{/owner}{/repo}
https://api.github.com/users/mariosasko/subscriptions
User
https://api.github.com/users/mariosasko
public
NONE
OK, let me try it it and I'll report back.

Will the JXL files (even if unknown format) be automatically downloaded if they are linked from the `.jsonl` file?

(I had trouble getting that working before this patch.)
2022-11-29T17:10:51Z
https://github.com/huggingface/datasets/pull/5289#issuecomment-1330994475
https://api.github.com/repos/huggingface/datasets/issues/5289
IC_kwDODunzps5PVV0r
https://api.github.com/repos/huggingface/datasets/issues/comments/1330994475/reactions
2022-11-29T17:10:51Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1330994475
https://avatars.githubusercontent.com/u/445208?v=4
https://api.github.com/users/alexjc/events{/privacy}
https://api.github.com/users/alexjc/followers
https://api.github.com/users/alexjc/following{/other_user}
https://api.github.com/users/alexjc/gists{/gist_id}
https://github.com/alexjc
alexjc
MDQ6VXNlcjQ0NTIwOA==
https://api.github.com/users/alexjc/orgs
https://api.github.com/users/alexjc/received_events
https://api.github.com/users/alexjc/repos
https://api.github.com/users/alexjc/starred{/owner}{/repo}
https://api.github.com/users/alexjc/subscriptions
User
https://api.github.com/users/alexjc
public
COLLABORATOR
> Will the JXL files (even if unknown format) be automatically downloaded if they are linked from the .jsonl file?

No, they need to be downloaded explicitly.

Feel free to use 🤗 Hub discussions in your dataset repo to ping us for help (our usernames are the same there)
2022-11-29T17:46:34Z
https://github.com/huggingface/datasets/pull/5289#issuecomment-1331044873
https://api.github.com/repos/huggingface/datasets/issues/5289
IC_kwDODunzps5PViIJ
https://api.github.com/repos/huggingface/datasets/issues/comments/1331044873/reactions
2022-11-29T17:46:34Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1331044873
https://avatars.githubusercontent.com/u/47462742?v=4
https://api.github.com/users/mariosasko/events{/privacy}
https://api.github.com/users/mariosasko/followers
https://api.github.com/users/mariosasko/following{/other_user}
https://api.github.com/users/mariosasko/gists{/gist_id}
https://github.com/mariosasko
mariosasko
MDQ6VXNlcjQ3NDYyNzQy
https://api.github.com/users/mariosasko/orgs
https://api.github.com/users/mariosasko/received_events
https://api.github.com/users/mariosasko/repos
https://api.github.com/users/mariosasko/starred{/owner}{/repo}
https://api.github.com/users/mariosasko/subscriptions
User
https://api.github.com/users/mariosasko
public
NONE
Is it possible to add support for JXL files being downloaded without needing to add server-side rendering support?
2022-11-29T17:48:44Z
https://github.com/huggingface/datasets/pull/5289#issuecomment-1331050600
https://api.github.com/repos/huggingface/datasets/issues/5289
IC_kwDODunzps5PVjho
https://api.github.com/repos/huggingface/datasets/issues/comments/1331050600/reactions
2022-11-29T17:48:44Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1331050600
https://avatars.githubusercontent.com/u/445208?v=4
https://api.github.com/users/alexjc/events{/privacy}
https://api.github.com/users/alexjc/followers
https://api.github.com/users/alexjc/following{/other_user}
https://api.github.com/users/alexjc/gists{/gist_id}
https://github.com/alexjc
alexjc
MDQ6VXNlcjQ0NTIwOA==
https://api.github.com/users/alexjc/orgs
https://api.github.com/users/alexjc/received_events
https://api.github.com/users/alexjc/repos
https://api.github.com/users/alexjc/starred{/owner}{/repo}
https://api.github.com/users/alexjc/subscriptions
User
https://api.github.com/users/alexjc
public
COLLABORATOR
In the loading script, data files are downloaded with `DownloadManager` (`dl_manager` in `_split_generators`), which doesn't have any requirements regarding the actual type of the downloaded files.

PS: Let's use the forum or Hub discussions for further questions to avoid pinging other participants
2022-11-29T18:49:46Z
https://github.com/huggingface/datasets/pull/5289#issuecomment-1331134382
https://api.github.com/repos/huggingface/datasets/issues/5289
IC_kwDODunzps5PV3-u
https://api.github.com/repos/huggingface/datasets/issues/comments/1331134382/reactions
2022-11-29T18:49:46Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1331134382
https://avatars.githubusercontent.com/u/47462742?v=4
https://api.github.com/users/mariosasko/events{/privacy}
https://api.github.com/users/mariosasko/followers
https://api.github.com/users/mariosasko/following{/other_user}
https://api.github.com/users/mariosasko/gists{/gist_id}
https://github.com/mariosasko
mariosasko
MDQ6VXNlcjQ3NDYyNzQy
https://api.github.com/users/mariosasko/orgs
https://api.github.com/users/mariosasko/received_events
https://api.github.com/users/mariosasko/repos
https://api.github.com/users/mariosasko/starred{/owner}{/repo}
https://api.github.com/users/mariosasko/subscriptions
User
https://api.github.com/users/mariosasko
public
JPEG-XL is the most advanced of the next-generation of image codecs, supporting both lossless and lossy files — with better compression and quality than PNG and JPG respectively.  It has reduced the disk sizes and bandwidth required for many of the datasets I use.

Pillow does not yet support JXL, but there's a plugin as a separate Python library that does (`pip install jxlpy`), and I've tested that this change works as expected when the plugin is imported.

Dataset used for testing, you must `git pull` as loading it from Python won't work until `datasets-server` is also changed to support JXL files:
https://huggingface.co/datasets/texturedesign/td01_natural-ground-textures

The case where the plugin is not imported first raises an error:
```
PIL.UnidentifiedImageError: cannot identify image file 'td01/train/set01/01_145523.jxl'
```

In order to enable support for JXL even before pillow supports this, should this exception be handled with a better error message?  I'd expect/hope JXL support to follow in one of the pillow quarterly releases in the next 6-9 months.