Skip to content

feat(ult): add custom augmentations#2

Merged
mandaiy merged 3 commits intomainfrom
feat/ult/custom-augmentation
Oct 12, 2025
Merged

feat(ult): add custom augmentations#2
mandaiy merged 3 commits intomainfrom
feat/ult/custom-augmentation

Conversation

@mandaiy
Copy link
Owner

@mandaiy mandaiy commented Oct 11, 2025

No description provided.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Comment on lines +57 to +74
if len(new["class_labels"]) > 0: # skip update if no bbox in new im
labels["img"] = new["image"]
labels["cls"] = np.array(new["class_labels"])
bboxes = np.array(new["bboxes"], dtype=np.float32)

# Update keypoints if they were transformed
if "keypoints" in new:
assert k is not None and dim is not None
kpts = new["keypoints"] / np.array([W, H]) # Normalize to [0, 1]
kpts = kpts.reshape(-1, k, dim - 1)
original_visibility = instances.keypoints[..., 2].reshape(-1, k, 1)

keypoints = np.concatenate([kpts, original_visibility], axis=-1).astype(np.float32)
else:
keypoints = None

instances.update(bboxes=bboxes, keypoints=keypoints)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update Instances class labels alongside bboxes

After applying the Albumentations transform the code replaces labels["cls"] but calls instances.update with only bboxes and keypoints. When the transform drops or reorders detections, Instances.cls still contains the old labels and length, so the Instances object no longer has matching numbers of boxes and classes. Downstream consumers of Instances (e.g. target builders or visualization) expect bboxes and cls to stay aligned and can mislabel or raise shape errors. Pass the transformed class_labels to instances.update whenever you change the boxes.

Useful? React with 👍 / 👎.

@mandaiy mandaiy force-pushed the feat/ult/custom-augmentation branch from 0faf039 to ce0af25 Compare October 12, 2025 07:23
@mandaiy
Copy link
Owner Author

mandaiy commented Oct 12, 2025

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Comment on lines +94 to +100
if "keypoints" in new:
assert k is not None and dim is not None
kpts = new["keypoints"] / np.array([W, H]) # Normalize to [0, 1]
kpts = kpts.reshape(-1, k, dim - 1)
original_visibility = instances.keypoints[..., 2].reshape(-1, k, 1)

keypoints = np.concatenate([kpts, original_visibility], axis=-1).astype(np.float32)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Normalize transformed keypoints using resized dimensions

The Albumentations adapter divides new["keypoints"] by the original W/H captured before the transform. For any transform that changes the image size (resize, crop, pad) Albumentations returns keypoints in the resized coordinate space, so normalizing by the original dimensions scales them incorrectly while the image and bboxes are updated to the new size. This produces misaligned keypoints in training samples. Normalize using the width and height of new["image"] instead.

Useful? React with 👍 / 👎.

@mandaiy mandaiy merged commit 240becf into main Oct 12, 2025
1 check passed
@mandaiy mandaiy deleted the feat/ult/custom-augmentation branch February 22, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant