Integrates GIMM-VFI alongside existing BIM/EMA/SGM models. Key feature: generates all intermediate frames in one forward pass (no recursive 2x passes needed for 4x/8x). - Vendor gimm_vfi_arch/ from kijai/ComfyUI-GIMM-VFI with device fixes - Two variants: RAFT-based (~80MB) and FlowFormer-based (~123MB) - Auto-download checkpoints from HuggingFace (Kijai/GIMM-VFI_safetensors) - Three new nodes: Load GIMM-VFI Model, GIMM-VFI Interpolate, GIMM-VFI Segment Interpolate - single_pass toggle: True=arbitrary timestep (default), False=recursive like other models - ds_factor parameter for high-res input downscaling Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
from easydict import EasyDict as edict
|
|
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 = [
|
|
pad_wd // 2,
|
|
pad_wd - pad_wd // 2,
|
|
pad_ht // 2,
|
|
pad_ht - pad_ht // 2,
|
|
]
|
|
|
|
def pad(self, *inputs):
|
|
if len(inputs) == 1:
|
|
return F.pad(inputs[0], self._pad, mode="replicate")
|
|
else:
|
|
return [F.pad(x, self._pad, mode="replicate") 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]]
|
|
def easydict_to_dict(obj):
|
|
if not isinstance(obj, edict):
|
|
return obj
|
|
else:
|
|
return {k: easydict_to_dict(v) for k, v in obj.items()}
|
|
|
|
|
|
class RaftArgs:
|
|
def __init__(self, small, mixed_precision, alternate_corr):
|
|
self.small = small
|
|
self.mixed_precision = mixed_precision
|
|
self.alternate_corr = alternate_corr
|
|
|
|
def _get_kwargs(self):
|
|
return {
|
|
"small": self.small,
|
|
"mixed_precision": self.mixed_precision,
|
|
"alternate_corr": self.alternate_corr
|
|
} |