File size: 724 Bytes
9f848c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from datasets import load_dataset
from pathlib import Path
from PIL import Image

REPO = "jamiewjm/sam-tp"  # change to your dataset repo id

ds_imgs = load_dataset(
    "imagefolder",
    data_dir=".",
    data_files={"image": f"hf://datasets/{REPO}/images/**"},
    split="train",
)
ds_msks = load_dataset(
    "imagefolder",
    data_dir=".",
    data_files={"mask": f"hf://datasets/{REPO}/annotations/**"},
    split="train",
)

mask_index = {Path(r["image"]["path"]).name: r["image"]["path"] for r in ds_msks}

row = ds_imgs[0]
img_path = Path(row["image"]["path"])
msk_path = Path(mask_index[img_path.name])

print("Image:", img_path)
print("Mask: ", msk_path)

Image.open(img_path).show()
Image.open(msk_path).show()