Using tao data services to generate augmentations seem to not produce correctly interpolated/transformed bounding boxes.
Here is a section of the original image with its mask and bbox overlaid:
Here is the same section in the augmented image:
You can see that the bounding box does not quite extend to the edge of the mask. Is this a known issue, or am I missing a key parameter while producing the augmentations? I’ve attached the augmentation spec file for reference.
aug_spec.txt (935 Bytes)
Here is my code to visualize the rle maps in case you need to reproduce the issue:
import os
import json
import random
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from pycocotools import mask as maskUtils
def visualize_coco_rle(json_path, images_dir, num_samples=5, seed=42):
# Load COCO data
with open(json_path, "r") as f:
coco = json.load(f)
images = coco["images"]
annotations = coco["annotations"]
# Build mapping
img_id2info = {img["id"]: img for img in images}
img_id2anns = {}
for ann in annotations:
img_id2anns.setdefault(ann["image_id"], []).append(ann)
# Pick a sample of images to visualize
random.seed(seed)
samples = [img for img in images if os.path.exists(os.path.join(images_dir, img["file_name"]))]
if len(samples) == 0:
print("No images found in directory!")
return
samples = random.sample(samples, min(num_samples, len(samples)))
for img_info in samples:
img_path = os.path.join(images_dir, img_info["file_name"])
anns = img_id2anns.get(img_info["id"], [])
if not os.path.exists(img_path):
print(f"Image not found: {img_path}")
continue
image = np.array(Image.open(img_path).convert("RGB"))
mask_total = np.zeros((img_info["height"], img_info["width"]), dtype=np.uint8)
# Overlay each mask in a different color
plt.figure(figsize=(10, 8))
plt.imshow(image)
plt.axis("off")
for ann_idx, ann in enumerate(anns):
rle = ann["segmentation"]
m = maskUtils.decode(rle)
# Random color per instance
color = np.random.rand(3,)
mask_bool = m.astype(bool)
# Overlay mask
plt.imshow(np.dstack([mask_bool*color[0], mask_bool*color[1], mask_bool*color[2]]), alpha=0.4)
# Optionally, show the bbox
x, y, w, h = ann["bbox"]
plt.gca().add_patch(plt.Rectangle((x, y), w, h, fill=False, edgecolor=color, linewidth=2))
plt.title(img_info["file_name"])
plt.show()
if __name__ == "__main__":
augmented_json_path = "output.json"
augmented_image_dir="images"
visualize_coco_rle(
json_path=augmented_json_path,
images_dir=augmented_image_dir,
num_samples=5
)

