Datasets:
Update README.md
Browse files
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
|
109 |
|
110 |
-
ds =
|
|
|
111 |
|
112 |
-
def download_image(
|
113 |
-
|
114 |
-
|
115 |
-
return {"image": filename}
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|