ydshieh commited on
Commit
8ffa189
1 Parent(s): 9628bd8

Add dataset usage example script

Browse files
Files changed (1) hide show
  1. dataset_example.py +26 -0
dataset_example.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ from PIL import Image
3
+
4
+
5
+ dataset_name = "image_caption_dataset.py"
6
+ dataset_config_name = "coco_2017"
7
+ cache_dir = None
8
+ keep_in_memory = False
9
+ data_dir = "./"
10
+
11
+ dataset = load_dataset(
12
+ dataset_name, dataset_config_name, cache_dir=cache_dir, keep_in_memory=keep_in_memory, data_dir=data_dir
13
+ )
14
+
15
+ for example in dataset["train"]:
16
+ print(example)
17
+ # with Image.open(example['image_file']) as image:
18
+ # image.show()
19
+ break
20
+
21
+ for _idx, example in enumerate(dataset["validation"]):
22
+ if _idx >= 5:
23
+ break
24
+ print(example)
25
+ with Image.open(example['image_file']) as image:
26
+ image.show()