diff --git a/freevideo_engine/geometry.py b/freevideo_engine/geometry.py index d51a748f..e0cc0e37 100644 --- a/freevideo_engine/geometry.py +++ b/freevideo_engine/geometry.py @@ -5,8 +5,23 @@ def geometry(width=1344, height=768, frames=None, seconds=None): - if any(not isinstance(n, int) or n < 256 or n % 32 for n in (width, height)): - raise ValueError('Width and height must be multiples of 32, at least 256 pixels.') + # Accept numpy integer types and integer-valued floats from upstream nodes, + # not only Python int; reject values that do not convert to a whole integer. + dims = [] + for n in (width, height): + if isinstance(n, bool): + raise ValueError('Width and height must be multiples of 32, at least 256 pixels.') + # Normalize via float so strings ("640"), numpy integers and integer-valued + # floats all compare by numeric value rather than Python identity/type. + try: + f = float(n) + except (TypeError, ValueError): + raise ValueError('Width and height must be multiples of 32, at least 256 pixels.') + ni = int(f) + if f != ni or ni < 256 or ni % 32: + raise ValueError('Width and height must be multiples of 32, at least 256 pixels.') + dims.append(ni) + width, height = dims if frames is not None and seconds is not None: raise ValueError('Specify frames or seconds, not both.') if seconds is not None and (not math.isfinite(seconds) or seconds <= 0): diff --git a/freevideo_engine/latent_upscale.py b/freevideo_engine/latent_upscale.py index 7a71d346..1903d71d 100644 --- a/freevideo_engine/latent_upscale.py +++ b/freevideo_engine/latent_upscale.py @@ -33,8 +33,17 @@ def upscale(video, checkpoint, width, height, *, memory_saving=False): if (not isinstance(video, torch.Tensor) or video.ndim != 5 or tuple(video.shape[:2]) != (1,24) or not video.is_floating_point() or not bool(torch.isfinite(video).all())): raise ValueError('Latent upscaling requires finite batch-one, 24-channel video latents') - if any(type(value) is not int or value % 32 for value in (width,height)): - raise ValueError('Upscale target dimensions must be multiples of 32') + _dims = [] + for value in (width, height): + try: + _f = float(value) + except (TypeError, ValueError): + raise ValueError('Upscale target dimensions must be multiples of 32') + _iv = int(_f) + if _f != _iv or _iv % 32: + raise ValueError('Upscale target dimensions must be multiples of 32') + _dims.append(_iv) + width, height = _dims source_h, source_w = video.shape[-2:] target_h, target_w = height//16, width//16 if target_h < source_h or target_w < source_w or target_h*source_w != target_w*source_h: