[Torchvision API] resized_crop and RandomResizedCrop#6369
[Torchvision API] resized_crop and RandomResizedCrop#6369mdabek-nvidia wants to merge 11 commits into
Conversation
|
@greptileai review please |
|
| Filename | Overview |
|---|---|
| dali/python/nvidia/dali/experimental/torchvision/v2/functional/crop.py | Adds resized_crop functional: extracts _crop helper, validates via RandomCrop.verify_args + Resize.verify_args, then calls ndd.resize on the cropped result. One unused helper function _verify_crop_coordinate was added but is never called. |
| dali/python/nvidia/dali/experimental/torchvision/v2/randomcrop.py | Adds RandomResizedCrop operator delegating to fn.random_resized_crop. Validation classes for scale/ratio and interpolation are well-structured and consistent with existing patterns. |
| dali/python/nvidia/dali/experimental/torchvision/v2/resize.py | Adds normalize_interpolation classmethod for PIL int-code to InterpolationMode conversion, int_to_interpolation_mode map, and additional size positivity/length checks in _ValidateSize. Clean changes used by both new operators. |
| dali/test/python/torchvision/test_tv_randomresizedcrop.py | New test file covering shape, correctness vs torchvision (identity crop), interpolation modes, antialias, and all validation error paths with assert_raises(glob=...) patterns. |
| dali/test/python/torchvision/test_tv_resized_crop.py | New test file with comprehensive pixel-level comparison against torchvision for tensor inputs and shape-level comparison for PIL inputs; covers crop positions, padding, interpolation modes, antialias, and all validation paths. |
| dali/test/python/torchvision/test_tv_crop.py | Updated existing crop tests to use assert_raises(glob=...) patterns for all error-path assertions, satisfying the test-edge-cases rule. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["resized_crop(inpt, top, left, height, width, size, ...)"] --> B["@adjust_input\n(PIL ↔ DALI tensor)"]
B --> C["_validate_crop_params\n(tensor: _validate_integer_param\nPIL: _round_pil_box)"]
C --> D["RandomCrop.verify_args\n(size=(height,width))"]
D --> E["Resize.normalize_interpolation\n(int → InterpolationMode)"]
E --> F["Resize.verify_args\n(size, interpolation)"]
F --> G["_crop(inpt, top, left, h, w)\nndd.slice with out_of_bounds pad"]
G --> H["Resize.calculate_target_size_dynamic_mode\n(height,width) + size_normalized"]
H --> I["ndd.resize(cropped, size=(target_h,target_w))"]
J["RandomResizedCrop.__init__(size, scale, ratio, ...)"] --> K["Resize.normalize_interpolation"]
K --> L["Operator.__init__ → arg_rules:\n_ValidateSizeDescriptor\n_ValidateCropSize\n_ValidateRandomResizedCropScaleRatio\n_ValidateRandomResizedCropInterpolation"]
L --> M["_kernel → fn.random_resized_crop\n(size, random_area=scale,\nrandom_aspect_ratio=ratio)"]
Reviews (4): Last reviewed commit: "Flake8 fixes - rebase artifacts" | Re-trigger Greptile
7075ce9 to
dc208ff
Compare
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
a7434df to
0d9eef9
Compare
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
* Different index support for tensor and PILImages Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
* RandomResizedCrop * resized_crop functional API * InterpoltionMode validation and unification Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
This reverts commit 9911739.
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
0d9eef9 to
a1722b9
Compare
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
9023b3a to
c9a2d3d
Compare
|
@greptileai re-review |
Category:
New feature
Description:
Torchvision API operators:
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