```cupyx.scipy.ndimage.zoom``` returns incorrect values
See original GitHub issueDescription
Hi, I am currently working on a project that I need to scale a 4-d uint8 array by a factor in each axis. I first tried the scipy.ndimage.zoom
, but it was slow. I later found out that cupyx supports this function so I changed to cupyx.
However, the array returned is not the same as the scipy one. Around 0.0044% of the values are not the same. My guess is that cupyx set some of the values to 0 directly (maybe due to error, I am not sure).
This is the same cross-section of the two arrays: Cupyx
Scipy
You can see there are differences on the top.
To Reproduce
import numpy as np
import cupy as cp
import cupyx.scipy.ndimage
import scipy.ndimage
# Inputs:
# orginal_array: 4d uint8 numpy shape: (208, 208, 224, 21)
# space_directions: [0.97212501, 1.37501857, 1.15326139, 1]
data_array_cupyx = cupyx.scipy.ndimage.zoom(cp.array(original_array, dtype=cp.uint8), space_directions, output=cp.uint8).get().astype(np.uint8)
data_array_scipy = scipy.ndimage.zoom(original_array, space_directions, output=np.uint8)
diff_array = data_array_cupyx != data_array_scipy
print(np.prod(data_array_cupyx.shape))
# >>> 313008696
print(np.sum(diff_array))
# >>> 13921
Installation
Source (pip install cupy
)
Environment
OS : Windows-10-10.0.19041-SP0
Python Version : 3.8.3
CuPy Version : 10.2.0
CuPy Platform : NVIDIA CUDA
NumPy Version : 1.22.3
SciPy Version : 1.8.0
Cython Build Version : 0.29.28
Cython Runtime Version : None
CUDA Root : C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2
nvcc PATH : C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\nvcc.EXE
CUDA Build Version : 11020
CUDA Driver Version : 11060
CUDA Runtime Version : 11020
cuBLAS Version : (available)
cuFFT Version : 10401
cuRAND Version : 10203
cuSOLVER Version : (11, 1, 0)
cuSPARSE Version : (available)
NVRTC Version : (11, 2)
Thrust Version : 101000
CUB Build Version : 101000
Jitify Build Version : <unknown>
cuDNN Build Version : 8101
cuDNN Version : 8101
NCCL Build Version : None
NCCL Runtime Version : None
cuTENSOR Version : None
cuSPARSELt Build Version : None
Device 0 Name : NVIDIA GeForce GTX 1060 3GB
Device 0 Compute Capability : 61
Device 0 PCI Bus ID : 0000:01:00.0
Additional Information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
cupyx.scipy.ndimage.zoom — CuPy 11.4.0 documentation
zoom (float or sequence) – The zoom factor along the axes. If a float, zoom is the same for each axis. If a...
Read more >scipy.ndimage.zoom — SciPy v1.9.3 Manual
The zoom factor along the axes. If a float, zoom is the same for each axis. If a sequence, zoom should contain one...
Read more >CuPy Documentation - Read the Docs
Multidimensional Image Processing (cupyx.scipy.ndimage.*) ... Note: The kernel does not have return values. You need to pass both input ...
Read more >problem with the 2d interpolation method using scipy.ndimage ...
jpg',1) # returns RGB image img_1 = scipy.ndimage.zoom(img,[3,3,1], order=1) # zoom should contain one value for each axis.
Read more >Source code for monai.transforms.spatial.array
Tensor: """ Small fn to simplify returning data. If `MetaTensor`, update affine. ... [docs]class Zoom(InvertibleTransform): """ Zooms an ND image using ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure, here is a subset of the data. part.zip
Script
Okay, that is good that the floating point case followed by casting is consistent. That shouldn’t be necessary as ideally
output=cp.uint8
should work the same way as in scipy. If you are able to make a small subset of the data where you see the issue available for us to test with, that could help look into it a bit more.