1aurent commited on
Commit
ad2895a
1 Parent(s): 361a683

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +19 -9
README.md CHANGED
@@ -105,18 +105,28 @@ This subset of the dataset contains only urls to the images, their descriptions
105
 
106
  To download the images from the urls, you may do something like this:
107
  ```python
108
- import datasets
109
 
110
- ds = datasets.load_dataset("1aurent/unsplash-lite-palette")
 
111
 
112
- def download_image(example, dl_manager):
113
- url = example["url"]
114
- filename = dl_manager.download(url)
115
- return {"image": filename}
116
 
117
- dl_manager = datasets.DownloadManager()
118
- ds = ds.map(download_image, fn_kwargs={"dl_manager": dl_manager}, num_proc=32)
119
- ds = ds.cast_column("image", datasets.Image())
 
 
 
 
 
 
 
 
 
 
120
  ```
121
 
122
  ![](https://unsplash.com/blog/content/images/2020/08/footer-alt.jpg)
 
105
 
106
  To download the images from the urls, you may do something like this:
107
  ```python
108
+ from datasets import load_dataset, DownloadManager, Image
109
 
110
+ ds = load_dataset("1aurent/unsplash-lite-palette")
111
+ ds = ds["train"].select(list(range(100)))
112
 
113
+ def download_image(url: str | list[str], dl_manager: DownloadManager):
114
+ filename = dl_manager.download(url)
115
+ return {"image": filename}
 
116
 
117
+ ds = ds.map(
118
+ function=download_image,
119
+ input_columns=["url"],
120
+ fn_kwargs={
121
+ "dl_manager": DownloadManager(),
122
+ },
123
+ batched=True,
124
+ num_proc=6,
125
+ )
126
+ ds = ds.cast_column(
127
+ column="image",
128
+ feature=Image(),
129
+ )
130
  ```
131
 
132
  ![](https://unsplash.com/blog/content/images/2020/08/footer-alt.jpg)