[Test][TFLite] Add unit tests for RESIZE_BILINEAR and RESIZE_NEAREST_NEIGHBOR ops#19365
[Test][TFLite] Add unit tests for RESIZE_BILINEAR and RESIZE_NEAREST_NEIGHBOR ops#19365tlopex merged 3 commits intoapache:mainfrom
Conversation
…NEIGHBOR into parametrized tests
There was a problem hiding this comment.
Code Review
This pull request adds comprehensive unit tests for TFLite resize operations (bilinear and nearest neighbor) in the Relax frontend. It introduces a helper function, _make_resize_expected, to programmatically generate expected IRModules for verification. The review feedback highlights an unused import (tirx as T) and an unused variable (out_shape) in the helper function that should be removed to improve code quality.
| from tvm.relax.frontend.tflite import from_tflite | ||
| from tvm.script.parser import ir as I | ||
| from tvm.script.parser import relax as R | ||
| from tvm.script.parser import tirx as T |
|
|
||
| def _make_resize_expected(input_shape, output_size, method, coordinate_transformation_mode, rounding_method): | ||
| """Build an Expected IRModule programmatically to avoid TVMScript variable scope limitations.""" | ||
| out_shape = (input_shape[0], output_size[0], output_size[1], input_shape[3]) |
|
Hi @OmarAzizi , Just a small note: please avoid using phrases like |
|
@tlopex Noted, thank you for letting me know |
…NEIGHBOR ops (apache#19365) Partially closes apache#18971. Add parametrized unit tests for `RESIZE_BILINEAR` and `RESIZE_NEAREST_NEIGHBOR` following the existing `verify()` + `tf.Module` pattern in the file. ## Tests added (13 total) ### `RESIZE_BILINEAR` (7 cases via `test_resize_bilinear`) | Case | Input shape | Output size | `coordinate_transformation_mode` | |------|-------------|-------------|----------------------------------| | upsample, default | `(1, 4, 4, 1)` | `8×8` | `half_pixel` | | downsample, default | `(1, 8, 8, 3)` | `4×4` | `half_pixel` | | align_corners | `(1, 4, 4, 1)` | `7×7` | `align_corners` | | half_pixel_centers | `(1, 4, 4, 2)` | `8×8` | `half_pixel` | | multichannel / batch > 1 | `(2, 6, 6, 16)` | `12×12` | `half_pixel` | | identity | `(1, 5, 5, 3)` | `5×5` | `half_pixel` | | non-square | `(1, 4, 8, 1)` | `8×16` | `half_pixel` | ### `RESIZE_NEAREST_NEIGHBOR` (6 cases via `test_resize_nearest_neighbor`) | Case | Input shape | Output size | `coordinate_transformation_mode` | `rounding_method` | |------|-------------|-------------|----------------------------------|-------------------| | upsample, default | `(1, 2, 2, 1)` | `4×4` | `half_pixel` | `round_prefer_ceil` | | downsample, default | `(1, 8, 8, 3)` | `4×4` | `half_pixel` | `round_prefer_ceil` | | align_corners | `(1, 4, 4, 1)` | `7×7` | `align_corners` | `""` | | multichannel / batch > 1 | `(4, 3, 3, 8)` | `6×6` | `half_pixel` | `round_prefer_ceil` | | non-square | `(1, 4, 8, 1)` | `8×16` | `half_pixel` | `round_prefer_ceil` | | identity | `(1, 3, 3, 2)` | `3×3` | `half_pixel` | `round_prefer_ceil` | ## Implementation notes - `Expected` modules are built programmatically via `relax.BlockBuilder` rather than TVMScript — the TVMScript parser does not accept runtime variables in type annotations, which would be required inside a parametrized test. - All 13 new tests pass. - `test_fill`, `test_batch_matmul`, and `test_batch_matmul_adj` were already failing on unmodified `main` before this PR. No regressions introduced. - Tested with Python 3.10.20, TensorFlow 2.9.0, NumPy 1.26.4.
Partially closes #18971.
Add parametrized unit tests for
RESIZE_BILINEARandRESIZE_NEAREST_NEIGHBORfollowing the existingverify()+tf.Modulepattern in the file.Tests added (13 total)
RESIZE_BILINEAR(7 cases viatest_resize_bilinear)coordinate_transformation_mode(1, 4, 4, 1)8×8half_pixel(1, 8, 8, 3)4×4half_pixel(1, 4, 4, 1)7×7align_corners(1, 4, 4, 2)8×8half_pixel(2, 6, 6, 16)12×12half_pixel(1, 5, 5, 3)5×5half_pixel(1, 4, 8, 1)8×16half_pixelRESIZE_NEAREST_NEIGHBOR(6 cases viatest_resize_nearest_neighbor)coordinate_transformation_moderounding_method(1, 2, 2, 1)4×4half_pixelround_prefer_ceil(1, 8, 8, 3)4×4half_pixelround_prefer_ceil(1, 4, 4, 1)7×7align_corners""(4, 3, 3, 8)6×6half_pixelround_prefer_ceil(1, 4, 8, 1)8×16half_pixelround_prefer_ceil(1, 3, 3, 2)3×3half_pixelround_prefer_ceilImplementation notes
Expectedmodules are built programmatically viarelax.BlockBuilderrather than TVMScript — the TVMScript parser does not accept runtime variables in type annotations, which would be required inside a parametrized test.test_fill,test_batch_matmul, andtest_batch_matmul_adjwere already failing on unmodifiedmainbefore this PR. No regressions introduced.