Recursion in the upsampler does not always terminate
Opened this issue · 1 comments
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?
We hit the same problem and came to the exact same solution. 👍