-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pad
uses numpy though pytorch backend is available
#6066
Comments
thanks for reporting, would you like to help enhance the logic? the main testing cases are listed here https://github.com/Project-MONAI/MONAI/blob/dev/tests/test_pad_mode.py |
I see, according to pytorch/pytorch#40763 (comment), MONAI/monai/transforms/croppad/functional.py Lines 70 to 74 in f519699
to: _pad = (
_np_pad
if mode in {"reflect", "replicate"} and img.dtype in {torch.int16, torch.int64, torch.bool, torch.uint8}
else _pt_pad
) Or, we can just use PyTorch pad here first and use NumPy pad if any exception occurs. I'm not sure which one is desired. |
ok, I remember the _pt_pad was not very robust, it's only compatible with a few combinations of dtypes + padding modes. I can have a look soon. |
Fixes #6066 ### Description prefer the pytorch backend as much as possible ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [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`. - [x] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [x] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Wenqi Li <wenqil@nvidia.com>
Fixes #6245 . ### Description support GPU tensor for * `GridPatch`, `GridPatchd`, `RandGridPatch` and `RandGridPatchd` * `GridPatchDataset`, `PatchIter`, `PatchIterd` and `iter_patch` #### Changes * Currently, `GridPatch`, `GridPatchDataset` and their siblings need to copy GPU tensor to numpy array (or not support GPU tensor) in their pipeline. This PR enables them to support end-to-end GPU operations. * Since the padding function `pad_nd` is used heavily, its robustness is improved. Some strange behavior introduced by #6066 is fixed. * In `GridPatch`, #6082 might be fixed by this PR? * `RandGridPatch`'s mode defaults to `None` (consistent with docs) #### Need to Notice * Default padding mode of `PatchIter`, `PatchIterd` and `iter_patch` are kept as `NumpyPadMode.WRAP`. However, `GridPatch` defaults to `None`. (might be inconsistent?) ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [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). - [x] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [x] 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: Qingpeng Li <qingpeng9802@gmail.com>
Describe the bug
According to the doc string of
Pad
:MONAI/monai/transforms/croppad/array.py
Lines 88 to 89 in f519699
However, sometimes
Pad
uses numpy though pytorch backend is available.To Reproduce
Run the following script, which wraps pad of numpy and torch by printing corresponding information first, and pads the input with Monai's transform to see the output:
Expected behavior
PyTorch is available in the script, so it should output
pt
(indicating that PyTorch pad is used)Actual behavior
The script outputs
np
(indicating that numpy pad is used).Environment
Additional context
I think the condition for PyTorch here is too strict.
MONAI/monai/transforms/croppad/functional.py
Lines 70 to 74 in f519699
The text was updated successfully, but these errors were encountered: