Datasets:
File size: 1,536 Bytes
c83afe9 | 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | from datasets import load_dataset
import os
from PIL import Image
import matplotlib.pyplot as plt
# Clearly tell it: This file belongs to the test basket.
dataset = load_dataset(
'json',
data_files={'test': 'data/test.jsonl'},
split='test'
)
v1_dataset = dataset.filter(lambda x: x['task'] == 4)
print(f"Total entries in V1: {len(v1_dataset)}")
if len(v1_dataset) > 0:
print(v1_dataset[0])
item = v1_dataset[0]
# Concatenate the complete path: data + ground_truth (e.g. Task_Image_Mask/.../id_*.png)
img_path = os.path.join('data', item['ground_truth'])
print(f"Trying to open the image:{img_path}")
if os.path.exists(img_path):
img = Image.open(img_path)
plt.figure(figsize=(6, 6))
plt.imshow(img, cmap='gray' if img.mode == 'L' else None)
plt.title(f"ID: {item['id']} | Task: {item['task']}")
plt.axis('off')
plt.show()
else:
print(f"file not found {img_path}")
if "image1_path" in item.keys():
img1_path = os.path.join('data', item['image1_path'])
print(f"Trying to open the image:{img1_path}")
if os.path.exists(img1_path):
img1 = Image.open(img1_path)
plt.figure(figsize=(6, 6))
plt.imshow(img1, cmap='gray' if img1.mode == 'L' else None)
plt.title(f"ID: {item['id']} | Task: {item['task']} - Image 1")
plt.axis('off')
plt.show()
else:
print(f"file not found {img1_path}") |