Skip to content
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

Recursion in the upsampler does not always terminate #66

Open
gfhcs opened this issue Nov 9, 2022 · 1 comment
Open

Recursion in the upsampler does not always terminate #66

gfhcs opened this issue Nov 9, 2022 · 1 comment

Comments

@gfhcs
Copy link

gfhcs commented Nov 9, 2022

Hello,

we are processing the validation set of the REDS 120fps dataset (https://seungjunnah.github.io/Datasets/reds.html). For about half of the sequences there, we encounter a case in which the recursion in upsampling.utils.upsampler.Upsampler._upsample_adaptive does not terminate:

 def _upsample_adaptive(self, I0, I1, t0, t1, num_bisections=-1):
        if num_bisections == 0:
            return [], []

        dt = self.batch_dt = np.full(shape=(1,), fill_value=0.5, dtype=np.float32)
        image, F_0_1, F_1_0 = self.interpolator.interpolate(I0, I1, dt)
        raise Exception()

        if num_bisections < 0:
            flow_mag_0_1_max = ((F_0_1 ** 2).sum(-1) ** .5).max()
            flow_mag_1_0_max = ((F_1_0 ** 2).sum(-1) ** .5).max()
            num_bisections = int(np.ceil(np.log(max([flow_mag_0_1_max, flow_mag_1_0_max]))/np.log(2)))

        left_images, left_timestamps = self._upsample_adaptive(I0, image, t0, (t0+t1)/2, num_bisections=num_bisections-1)
        right_images, right_timestamps = self._upsample_adaptive(image, I1, (t0+t1)/2, t1, num_bisections=num_bisections-1)
        timestamps = left_timestamps + [(t0+t1)/2] + right_timestamps
        images = left_images + [image[0]] + right_images

        return images, timestamps

In the branch if num_bisections < 0: the computation of num_bisections might yield 0, such that recursion becomes infinite (because the recursive calls will hit exactly the same case again) and we either run into Python's recursion limit or run out of memory.

I have a very superficial understanding of this code, but my guess is that adding the following lines as the last instructions inside that if branch fixes the issue:

            if num_bisections == 0:
                return [image[0]], [(t0+t1)/2]

What do you think?

@mandulaj
Copy link

We hit the same problem and came to the exact same solution. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants