Krows7 commited on
Commit
57730e3
·
verified ·
1 Parent(s): 20ca54b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +105 -5
README.md CHANGED
@@ -12,15 +12,15 @@ annotations_creators:
12
  size_categories:
13
  - 10K<n<100K
14
  tags:
 
15
  - computer-vision
16
  - multi-label-classification
17
  - image-feature-extraction
 
18
  - representation-learning
19
- - embodied-ai
20
  - agent-perception
21
- - minecraft
22
  - reinforcement-learning
23
- - gameplay
24
  configs:
25
  - config_name: core
26
  default: true
@@ -172,14 +172,114 @@ dataset-root/
172
  └── splits/
173
  ```
174
 
175
- Load a local image:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
  ```python
178
  from pathlib import Path
179
  from PIL import Image
180
 
181
  root = Path("/path/to/dataset-root")
182
- example = dataset["train"][0]
183
 
184
  image = Image.open(
185
  root / "images" / example["image_path"]
 
12
  size_categories:
13
  - 10K<n<100K
14
  tags:
15
+ - minecraft
16
  - computer-vision
17
  - multi-label-classification
18
  - image-feature-extraction
19
+ - gameplay
20
  - representation-learning
 
21
  - agent-perception
 
22
  - reinforcement-learning
23
+ - embodied-ai
24
  configs:
25
  - config_name: core
26
  default: true
 
172
  └── splits/
173
  ```
174
 
175
+ ### Load images from the Hub
176
+
177
+ The CSV configurations expose `image_path` as a relative string. Image files live under:
178
+
179
+ ```text
180
+ images/<image_path>
181
+ ```
182
+
183
+ #### Download one image
184
+
185
+ Use `hf_hub_download()` for inspection, notebooks, or other cases where only a few images are needed:
186
+
187
+ ```python
188
+ from datasets import load_dataset
189
+ from huggingface_hub import hf_hub_download
190
+ from PIL import Image
191
+
192
+ REPO_ID = "OWNER/REPOSITORY"
193
+
194
+ dataset = load_dataset(
195
+ REPO_ID,
196
+ "core",
197
+ split="train",
198
+ )
199
+
200
+ example = dataset[0]
201
+
202
+ local_path = hf_hub_download(
203
+ repo_id=REPO_ID,
204
+ repo_type="dataset",
205
+ filename=f"images/{example['image_path']}",
206
+ )
207
+
208
+ image = Image.open(local_path).convert("RGB")
209
+
210
+ print(example["image_path"])
211
+ print(image.size)
212
+ ```
213
+
214
+ Downloaded files are stored in the Hugging Face cache and are normally reused on later calls.
215
+
216
+ #### Download the image store for training
217
+
218
+ For training or large-scale feature extraction, download the image tree once with `snapshot_download()`:
219
+
220
+ ```python
221
+ from pathlib import Path
222
+ from datasets import load_dataset
223
+ from huggingface_hub import snapshot_download
224
+ from PIL import Image
225
+
226
+ REPO_ID = "OWNER/REPOSITORY"
227
+
228
+ repo_root = Path(
229
+ snapshot_download(
230
+ repo_id=REPO_ID,
231
+ repo_type="dataset",
232
+ allow_patterns=["images/**"],
233
+ )
234
+ )
235
+
236
+ dataset = load_dataset(
237
+ REPO_ID,
238
+ "core",
239
+ split="train",
240
+ )
241
+
242
+ example = dataset[0]
243
+
244
+ image = Image.open(
245
+ repo_root / "images" / example["image_path"]
246
+ ).convert("RGB")
247
+ ```
248
+
249
+ The original directory structure is preserved inside the local snapshot.
250
+
251
+ #### Add a decoded `image` column
252
+
253
+ After downloading the image store, the string paths can be exposed as a lazy `datasets.Image` column:
254
+
255
+ ```python
256
+ from datasets import Image
257
+
258
+ def attach_image_path(example):
259
+ return {
260
+ "image": str(
261
+ repo_root
262
+ / "images"
263
+ / example["image_path"]
264
+ )
265
+ }
266
+
267
+ dataset = dataset.map(attach_image_path)
268
+ dataset = dataset.cast_column("image", Image())
269
+
270
+ image = dataset[0]["image"]
271
+ ```
272
+
273
+ `dataset[0]["image"]` then returns a decoded Pillow image, while `image_path` remains available as the stable dataset identifier.
274
+
275
+ ### Load images from a local checkout
276
 
277
  ```python
278
  from pathlib import Path
279
  from PIL import Image
280
 
281
  root = Path("/path/to/dataset-root")
282
+ example = dataset[0]
283
 
284
  image = Image.open(
285
  root / "images" / example["image_path"]