question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RBFInterpolator gives Segmentation fault for large images

See original GitHub issue

scipy.interpolate.RBFInterpolator gives Segmentation fault for large images/2D arrays. Moreover, for some dimensions (example - 250 x 250) the algorithm is a bit slow. I am not sure whether the issue is with Pythran or with the implementation RBFInterpolator or is it just something specific to my system.

Reproducing code example:

Reference - https://stackoverflow.com/questions/21690608/numpy-inpaint-nans-interpolate-and-extrapolate/21697401#21697401

import numpy as np
import pythran
import scipy
from scipy.interpolate import RBFInterpolator

print("Pythran Version: ", pythran.__version__)
print("Scipy Version: ", scipy.__version__)
print("NumPy Version: ", np.__version__)

num_points = [10, 100, 500]
for num in num_points:
    x = np.linspace(0, 1, num)
    y = x[:, None]
    image = x + y
    print(image.shape)

    # Destroy some values
    mask = np.random.random(image.shape) > 0.7
    image[mask] = np.nan

    valid_mask = ~np.isnan(image)
    coords = np.array(np.nonzero(valid_mask)).T
    values = image[valid_mask]

    it = RBFInterpolator(coords, values)

    filled = it(list(np.ndindex(image.shape))).reshape(image.shape)

    del x, y, image, it, filled

    print("Completed Successfully for %d x %d image."%(num, num))

Error message:

Pythran Version:  0.9.12.dev0
Scipy Version:  1.8.0.dev0+1285.ac3b219
NumPy Version:  1.20.3
(10, 10)
Completed Successfully for 10 x 10 image.
(100, 100)
Completed Successfully for 100 x 100 image.
(500, 500)
Segmentation fault

Scipy/Numpy/Python version information:

1.8.0.dev0+1285.ac3b219 1.20.3 sys.version_info(major=3, minor=9, micro=4, releaselevel='final', serial=0)

Comments

Related PR - https://github.com/scipy/scipy/pull/13595

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
rgommerscommented, Jun 25, 2021

I noticed that, openmp directives aren’t there in _rbfinterp_pythran.py, so OpenMP isn’t used I believe. Should we add them?

No we shouldn’t add any directives here. OpenMP isn’t portable, and hence not allowed in SciPy binaries (see https://github.com/scipy/scipy/issues/10239#issuecomment-795030817). Let me comment on your other question in gh-13308 in more detail.

1reaction
treverhinescommented, Jun 15, 2021

How does the value of neighbor argument affects the quality of results? Is there any way with which we can select best of these values (according to the maximum available memory on a system) for a given input automatically?

If you are trying to interpolate a smooth function, then the error in the interpolant will generally decrease with a larger value for neighbors. In your example, you are interpolating a plane, which can be reproduced exactly regardless of the value for neighbors (although neighbors does need to be large enough so that the neighborhood of data points is not collinear).

It is hard to come up with a good way to automatically pick a value for neighbors. It depends on how many data points you have, and there is also a trade-off between speed/memory and accuracy. If you have fewer than about 5000 data points, then the fastest and most accurate RBF interpolation would probably be with neighbors=None. Setting neighbors to None uses all the data points but it avoids to cost of finding the nearest neighbors. When interpolating images (> 5000 data points), there is not too much to gain from having a large value for neighbors unless the image values are smooth over a large neighborhood. So I like to use neighbors=20 for image inpainting, and I also set kernel="linear", which is faster and also prevents the interpolant from overshooting the data.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Segmentation fault when running scipy interpolate
This isn't necessarily an answer but just more info, when I execute that exact code I get this as output all as error...
Read more >
Determining Root Cause of Segmentation Faults SIGSEGV or ...
We outline these potential causes below and give suggestions for avoiding the segmentation fault. Possible Cause #1 Fortran Specific Stackspace Exhaustion.
Read more >
Segmentation fault using imshow on large image - Matplotlib
Hi, I've been getting a segmentation fault when trying to display large images. A transcript of a sample session is below. I'm using...
Read more >
segmentation fault when running scipy interpolate - splunktool
RBFInterpolator gives Segmentation fault for large images /2D arrays. Moreover, for some dimensions (example - 250 x 250) the algorithm is a ...
Read more >
Segmentation fault when applying PCA to a big dataset on an ...
Instead of a DataFrame, wrap your matrix as a table using MLJ.table(mat) (or Tables.table(mat) ); If that still gives seg fault, try using ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found