From e604d1841fe60c0ffb6978ae4116535ca8d8f34f Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Wed, 4 Dec 2024 11:09:22 +0800 Subject: [PATCH] Fix TypeError in meshgrid (#8252) Fixes #8251 Remove `indexing="ij"` will not affect anything since it's default behavior in torch. ### Types of changes - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/networks/blocks/pos_embed_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/networks/blocks/pos_embed_utils.py b/monai/networks/blocks/pos_embed_utils.py index 21586e56da..a9c5176bc2 100644 --- a/monai/networks/blocks/pos_embed_utils.py +++ b/monai/networks/blocks/pos_embed_utils.py @@ -56,7 +56,7 @@ def build_sincos_position_embedding( grid_h = torch.arange(h, dtype=torch.float32) grid_w = torch.arange(w, dtype=torch.float32) - grid_h, grid_w = torch.meshgrid(grid_h, grid_w, indexing="ij") + grid_h, grid_w = torch.meshgrid(grid_h, grid_w) if embed_dim % 4 != 0: raise AssertionError("Embed dimension must be divisible by 4 for 2D sin-cos position embedding") @@ -75,7 +75,7 @@ def build_sincos_position_embedding( grid_w = torch.arange(w, dtype=torch.float32) grid_d = torch.arange(d, dtype=torch.float32) - grid_h, grid_w, grid_d = torch.meshgrid(grid_h, grid_w, grid_d, indexing="ij") + grid_h, grid_w, grid_d = torch.meshgrid(grid_h, grid_w, grid_d) if embed_dim % 6 != 0: raise AssertionError("Embed dimension must be divisible by 6 for 3D sin-cos position embedding")