jamiewjm commited on
Commit
e1f9f79
·
verified ·
1 Parent(s): bc11380

Upload quickstart.py

Browse files
Files changed (1) hide show
  1. quickstart.py +30 -0
quickstart.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ from pathlib import Path
3
+ from PIL import Image
4
+
5
+ REPO = "your_user/sam-tp" # change to your dataset repo id
6
+
7
+ ds_imgs = load_dataset(
8
+ "imagefolder",
9
+ data_dir=".",
10
+ data_files={"image": f"hf://datasets/{REPO}/images/**"},
11
+ split="train",
12
+ )
13
+ ds_msks = load_dataset(
14
+ "imagefolder",
15
+ data_dir=".",
16
+ data_files={"mask": f"hf://datasets/{REPO}/annotations/**"},
17
+ split="train",
18
+ )
19
+
20
+ mask_index = {Path(r["image"]["path"]).name: r["image"]["path"] for r in ds_msks}
21
+
22
+ row = ds_imgs[0]
23
+ img_path = Path(row["image"]["path"])
24
+ msk_path = Path(mask_index[img_path.name])
25
+
26
+ print("Image:", img_path)
27
+ print("Mask: ", msk_path)
28
+
29
+ Image.open(img_path).show()
30
+ Image.open(msk_path).show()