Torchvision API - center crop operator#6266
Conversation
Signed-off-by: Marek Dabek <[email protected]>
|
@greptileai - please review |
Greptile SummaryThis PR adds a Key changes:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant adjust_input as adjust_input (decorator)
participant center_crop as center_crop / CenterCrop
participant DALI as DALI fn.crop / ndd.crop
Caller->>adjust_input: inpt (PIL/Tensor), output_size, device
adjust_input->>adjust_input: transform_input → ndd.Tensor / ndd.Batch
adjust_input->>center_crop: _input (ndd), output_size, device
center_crop->>center_crop: CenterCrop.verify_args(size)
center_crop->>center_crop: adjust_size(output_size) → (crop_h, crop_w)
center_crop->>center_crop: derive in_h, in_w from layout
center_crop->>center_crop: compute banker's-rounded crop_pos_y / crop_pos_x
center_crop->>DALI: crop(tensor, crop=(crop_h,crop_w), crop_pos_x, crop_pos_y,\nout_of_bounds_policy="pad", fill_values=0)
DALI-->>center_crop: cropped ndd output
center_crop-->>adjust_input: output.evaluate()
adjust_input->>adjust_input: adjust_output → PIL Image / torch.Tensor
adjust_input-->>Caller: result
|
dali/python/nvidia/dali/experimental/torchvision/v2/functional/centercrop.py
Show resolved
Hide resolved
Signed-off-by: Marek Dabek <[email protected]>
cd93185 to
1b043c0
Compare
|
!build |
|
CI MESSAGE: [46532136]: BUILD STARTED |
|
@greptileai - please re-review |
|
CI MESSAGE: [46532136]: BUILD FAILED |
|
CI MESSAGE: [46532136]: BUILD PASSED |
dali/python/nvidia/dali/experimental/torchvision/v2/functional/centercrop.py
Outdated
Show resolved
Hide resolved
dali/python/nvidia/dali/experimental/torchvision/v2/functional/centercrop.py
Show resolved
Hide resolved
dali/python/nvidia/dali/experimental/torchvision/v2/centercrop.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Not sure how important that is, but following up on https://github.com/NVIDIA/DALI/pull/6266/changes#r2976016315 I wonder if we should test cases with at least one of the extents, such that extent/2 is not representable exactly with float32 and whether we are consitent with torchvision there (one thing is how we compute the absolute offset, the other is how dali accepts the ratio as float32).
There was a problem hiding this comment.
I removed the casting. Although I think that idea of testing extent/2 is plausible is there a scenario where it would be used?
There was a problem hiding this comment.
I've just seen int32 with fp32 intermediate steps and wanted to raise the point that this may (or may not :D) result in more than off-by-one rounding errors. Are >> 2**24 extents plausible, I guess for some satelate images etc it could be the case. Having a test with extents not representable in fp32 (that could be very thin or narrow to keep it leightweight) would be a way to know if we're not diverging from torchvision too much. Anyway, I am just raising a concern, it could be overcautious, I am relying on your call here!
There was a problem hiding this comment.
Removed the fp32 casting. Tests are passing
Signed-off-by: Marek Dabek <[email protected]>
b1a9d82 to
3337aa9
Compare
|
!build |
|
CI MESSAGE: [46867909]: BUILD STARTED |
Signed-off-by: Marek Dabek <[email protected]> Co-authored-by: Kamil Tokarski <[email protected]>
3337aa9 to
58cdffb
Compare
|
@greptileai - please re-review |
|
CI MESSAGE: [46867909]: BUILD PASSED |
Center crop operators implementation Signed-off-by: Marek Dabek <[email protected]> Co-authored-by: Kamil Tokarski <[email protected]>
Category:
New feature
Description:
Implementation of Torchvision's center crop operators: object oriented and functional
Additional information:
Affected modules and functionalities:
Key points relevant for the review:
Tests:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: N/A