bdanko commited on
Commit
9b3e829
·
verified ·
1 Parent(s): ecf87f2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +88 -0
README.md CHANGED
@@ -67,3 +67,91 @@ configs:
67
  - split: test
68
  path: data/test-*
69
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  - split: test
68
  path: data/test-*
69
  ---
70
+
71
+ ```python
72
+ from datasets import load_dataset
73
+ import matplotlib.pyplot as plt
74
+ import matplotlib.patches as patches
75
+ import numpy as np
76
+
77
+ # 1. Load the dataset
78
+ # Note: Since this is a private repo, ensure you have run `huggingface-cli login`
79
+ repo_id = "bdanko/loaf_resolution_512"
80
+ print(f"Downloading {repo_id}...")
81
+ dataset = load_dataset(repo_id, split="train")
82
+
83
+ # 2. Grab the first example
84
+ example = dataset[0]
85
+
86
+ # Hugging Face automatically decodes the Parquet bytes into a PIL Image
87
+ img = example["image"]
88
+ objects = example["objects"]
89
+
90
+ # Print image-level metadata
91
+ print("\n--- Image Metadata ---")
92
+ print(f"File Name: {example['file_name']}")
93
+ print(f"Image ID: {example['image_id']}")
94
+ print(f"Dimensions: {example['width']}x{example['height']}")
95
+ print(f"Camera Height (Image): {example['camera_height_img']}")
96
+
97
+ # 3. Set up the matplotlib plot
98
+ fig, ax = plt.subplots(1, figsize=(10, 8))
99
+ ax.imshow(img)
100
+ ax.axis("off")
101
+ ax.set_title(f"Sample: {example['file_name']}", fontsize=14)
102
+
103
+ print("\n--- Object Metadata ---")
104
+
105
+ # 4. Iterate through all objects in this image
106
+ # We use zip to unpack all the parallel lists stored inside the 'objects' dictionary
107
+ num_objects = len(objects["annotation_id"])
108
+
109
+ for i in range(num_objects):
110
+ ann_id = objects["annotation_id"][i]
111
+ cat_id = objects["category_id"][i]
112
+ bbox = objects["bbox"][i]
113
+ seg = objects["segmentation"][i]
114
+
115
+ # Custom / 3D annotations
116
+ ritbox = objects["ritbox"][i]
117
+ rot_box = objects["rotated_box"][i]
118
+ world_loc = objects["world_location"][i]
119
+ person_loc = objects["person_location"][i]
120
+ cam_height_ann = objects["camera_height_ann"][i]
121
+
122
+ print(f"\nObject {i+1} (Ann ID: {ann_id} | Category: {cat_id})")
123
+ print(f" - 2D BBox: {bbox}")
124
+ print(f" - Ritbox: {ritbox}")
125
+ print(f" - Rotated Box: {rot_box}")
126
+ print(f" - World Location: {world_loc}")
127
+ print(f" - Person Location: {person_loc}")
128
+ print(f" - Camera Height: {cam_height_ann}")
129
+
130
+ # --- Plotting the 2D Bounding Box ---
131
+ # COCO bbox format is [top_left_x, top_left_y, width, height]
132
+ if len(bbox) == 4:
133
+ x, y, w, h = bbox
134
+ rect = patches.Rectangle(
135
+ (x, y), w, h,
136
+ linewidth=2, edgecolor='red', facecolor='none', label=f"Cat {cat_id}"
137
+ )
138
+ ax.add_patch(rect)
139
+ ax.text(x, y - 5, f"Cat {cat_id}", color='red', fontsize=10, weight='bold')
140
+
141
+ # --- Plotting the Segmentation Polygon ---
142
+ # COCO segmentation is a flat list: [x1, y1, x2, y2, ...]
143
+ if len(seg) > 0:
144
+ # Reshape flat list into a list of (x, y) coordinate pairs
145
+ poly_coords = np.array(seg).reshape(-1, 2)
146
+ polygon = patches.Polygon(
147
+ poly_coords,
148
+ linewidth=2, edgecolor='cyan', facecolor='cyan', alpha=0.3
149
+ )
150
+ ax.add_patch(polygon)
151
+
152
+ plt.tight_layout()
153
+ plt.show()
154
+ ```
155
+
156
+
157
+ ![image](https://cdn-uploads.huggingface.co/production/uploads/6739246f8f51fde3c5ca7663/7b-CyZqtH1Qcz1IyOpwko.png)