hbenbel / Eulerian-Video-Magnification

Eulerian Video Magnification for colors and motions magnification
https://hbenbel.github.io/blog/evm
MIT License
56 stars 13 forks source link

Compilation issue #4

Open jojokeeps opened 1 year ago

jojokeeps commented 1 year ago

Everything works up until the final part and I keep getting this issue:

numpy.core._exceptions._ArrayMemoryError: Unable to allocate 12.0 GiB for an array with shape (3, 720, 1280, 292) and data type complex 128

Any help? Thanks!

kodavatimahendra commented 8 months ago

Hi,

Do not use the default parameters, they are the reason for running out of memory. Use the ones suggested inside the 'results' folder.

kodavatimahendra commented 8 months ago

Sorry my bad, inside each iteration of gaussian and laplacian functions, the lists are continuously appended. These lists aren't cleared until the end. Therefore for higher resolution or longer videos, the memory will overflow.

These functions have to be optimized.

8188 commented 3 months ago

The following function require less memory if using Gaussian kernel.

from scipy.fft import fft, ifft, fftfreq

def idealTemporalBandpassFilter_chunck(images, fps, freq_range, axis=0, chunk_size=200):
    num_frames = images.shape[axis]
    result = np.empty_like(images)

    for start in tqdm.tqdm(
        range(0, num_frames, chunk_size), ascii=True, desc="Gaussian Pyramids Filtering"
    ):
        end = min(start + chunk_size, num_frames)
        chunk = images.take(np.arange(start, end), axis=axis, mode="clip")
        fft_result = fft(chunk, axis=axis)
        frequencies = fftfreq(chunk.shape[0], d=1.0 / fps)

        low = (np.abs(frequencies - freq_range[0])).argmin()
        high = (np.abs(frequencies - freq_range[1])).argmin()

        fft_result[:low] = 0
        fft_result[high:] = 0

        result[start:end, ...] = ifft(fft_result, axis=0).real
    return result