Wraps BiM-VFI (CVPR 2025) as a ComfyUI custom node for long video frame interpolation with memory-safe sequential processing. - LoadBIMVFIModel: checkpoint loader with auto-download from Google Drive - BIMVFIInterpolate: 2x/4x/8x recursive interpolation with per-pair GPU processing, configurable VRAM management (all_on_gpu for high-VRAM setups), progress bar, and backwarp cache clearing - Vendored inference-only architecture from KAIST-VICLab/BiM-VFI - Auto-detection of CUDA version for cupy installation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
29 lines
955 B
Python
29 lines
955 B
Python
import torch.nn.functional as F
|
|
|
|
|
|
class InputPadder:
|
|
""" Pads images such that dimensions are divisible by divisor """
|
|
|
|
def __init__(self, dims, divisor=16):
|
|
self.ht, self.wd = dims[-2:]
|
|
pad_ht = (((self.ht // divisor) + 1) * divisor - self.ht) % divisor
|
|
pad_wd = (((self.wd // divisor) + 1) * divisor - self.wd) % divisor
|
|
self._pad = [0, pad_wd, 0, pad_ht]
|
|
|
|
def pad(self, *inputs):
|
|
if len(inputs) == 1:
|
|
return F.pad(inputs[0], self._pad, mode='constant')
|
|
else:
|
|
return [F.pad(x, self._pad, mode='constant') for x in inputs]
|
|
|
|
def unpad(self, *inputs):
|
|
if len(inputs) == 1:
|
|
return self._unpad(inputs[0])
|
|
else:
|
|
return [self._unpad(x) for x in inputs]
|
|
|
|
def _unpad(self, x):
|
|
ht, wd = x.shape[-2:]
|
|
c = [self._pad[2], ht - self._pad[3], self._pad[0], wd - self._pad[1]]
|
|
return x[..., c[0]:c[1], c[2]:c[3]]
|