Skip to content

Conversation

@jveitchmichaelis
Copy link
Collaborator

@jveitchmichaelis jveitchmichaelis commented Jan 20, 2026

Description

Fixes some unexpected behavior during augmentation.

  1. If a padding operation is performed before other geometric transforms, the final labels are not transformed correctly. It seems that the geometric transform is correct, though probably not what the user would want, but the labels are definitely wrong. Here for example, if we pad and then flip, the image is correctly vflipped. The labels however are only vflipped in original image coordinates. From what I can see it's not as simple as resizing the labels, this should be handled by kornia.

This may be a limitation of how kornia constructs/chains the transformation matrices for different operations.

image
  1. kornia transforms input boxes/points but it doesn't do any filtering afterwards. If the source image is rotated for example, it will may result in boxes going out of bounds. Currently, we clip to the bounds of the augmented image, but if padding is forced to be the last operation, we should clip to the source image and then pad to the desired size. In the other direction, if the image is cropped, then we want to bound the labels to the transformed image.
image

This PR makes two changes:

  1. If the pipeline contains a PadTo operation, move it to the final step. This ensures that the resulting labels are correct. This is opinionated, but until we figure out a way to solve the label transform problem, it's a safe compromise and should always yield correct labels even if the transform pipeline is specified out of order by mistake.
  2. Modify box filtering to clamp to the minimum of the source/augmented image width and height.

Typical corrected sample:

image image

Related Issue(s)

#1274 - related, but this does not change the behavior of PadTo (unexpected cropping).

AI-Assisted Development

Auto-complete only for updating filter_boxes

  • I understand all the code I'm submitting
  • I have reviewed and validated all AI-generated code

@jveitchmichaelis jveitchmichaelis marked this pull request as ready for review January 20, 2026 22:16
@jveitchmichaelis jveitchmichaelis changed the title fix padding issues in augmentation pipeline wip: fix padding issues in augmentation pipeline Jan 20, 2026
@jveitchmichaelis jveitchmichaelis marked this pull request as draft January 20, 2026 22:47
@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.99%. Comparing base (0ab23a3) to head (2994bed).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
src/deepforest/augmentations.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1275      +/-   ##
==========================================
- Coverage   87.73%   86.99%   -0.75%     
==========================================
  Files          20       20              
  Lines        2716     2775      +59     
==========================================
+ Hits         2383     2414      +31     
- Misses        333      361      +28     
Flag Coverage Δ
unittests 86.99% <80.00%> (-0.75%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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