diff --git a/CHANGELOG.md b/CHANGELOG.md index a35bbe217..e76fd0df6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,6 +106,7 @@ Less than 2 weeks since last release, here's a service-pack style update with a - fix `nudenet` process tab operations - `controlnet` input validation - log metadata keys that cannot be applied + - fix `framepack` with image input ## Update for 2025-10-18 diff --git a/modules/framepack/framepack_wrappers.py b/modules/framepack/framepack_wrappers.py index 672db7806..ad4745846 100644 --- a/modules/framepack/framepack_wrappers.py +++ b/modules/framepack/framepack_wrappers.py @@ -5,6 +5,7 @@ import threading import numpy as np import torch import gradio as gr +from PIL import Image from modules import shared, processing, timer, paths, extra_networks, progress, ui_video_vlm from modules.video_models.video_utils import check_av from modules.framepack import framepack_install # pylint: disable=wrong-import-order @@ -27,6 +28,8 @@ def prepare_image(image, resolution): (416, 960), (448, 864), (480, 832), (512, 768), (544, 704), (576, 672), (608, 640), (640, 608), (672, 576), (704, 544), (768, 512), (832, 480), (864, 448), (960, 416), ] + if isinstance(image, Image.Image): + image = np.array(image) h, w, _c = image.shape min_metric = float('inf') scale_factor = resolution / 640.0 diff --git a/modules/framepack/pipeline/utils.py b/modules/framepack/pipeline/utils.py index 20108106b..9cd99571d 100644 --- a/modules/framepack/pipeline/utils.py +++ b/modules/framepack/pipeline/utils.py @@ -1,15 +1,14 @@ import os -import cv2 import json import random import glob +import datetime import torch import einops +import cv2 import numpy as np -import datetime import torchvision -import safetensors.torch as sf -from PIL import Image +from PIL import Image, ImageDraw, ImageFont def min_resize(x, m): @@ -30,7 +29,7 @@ def min_resize(x, m): def d_resize(x, y): - H, W, C = y.shape + H, W, _C = y.shape new_min = min(H, W) raw_min = min(x.shape[0], x.shape[1]) if new_min < raw_min: @@ -50,7 +49,7 @@ def resize_and_center_crop(image, target_width, target_height): scale_factor = max(target_width / original_width, target_height / original_height) resized_width = int(round(original_width * scale_factor)) resized_height = int(round(original_height * scale_factor)) - resized_image = pil_image.resize((resized_width, resized_height), Image.LANCZOS) + resized_image = pil_image.resize((resized_width, resized_height), Image.Resampling.LANCZOS) left = (resized_width - target_width) / 2 top = (resized_height - target_height) / 2 right = (resized_width + target_width) / 2 @@ -60,7 +59,7 @@ def resize_and_center_crop(image, target_width, target_height): def resize_and_center_crop_pytorch(image, target_width, target_height): - B, C, H, W = image.shape + _B, _C, H, W = image.shape if H == target_height and W == target_width: return image @@ -83,7 +82,7 @@ def resize_without_crop(image, target_width, target_height): return image pil_image = Image.fromarray(image) - resized_image = pil_image.resize((target_width, target_height), Image.LANCZOS) + resized_image = pil_image.resize((target_width, target_height), Image.Resampling.LANCZOS) return np.array(resized_image) @@ -188,7 +187,7 @@ def supress_lower_channels(m, k, alpha=0.01): def freeze_module(m): if not hasattr(m, '_forward_inside_frozen_module'): - m._forward_inside_frozen_module = m.forward + m._forward_inside_frozen_module = m.forward # pylint: disable=protected-access m.requires_grad_(False) m.forward = torch.no_grad()(m.forward) return m @@ -243,7 +242,7 @@ def soft_append_bcthw(history, current, overlap=0): def save_bcthw_as_mp4(x, output_filename, fps=10, crf=0): - b, c, t, h, w = x.shape + b, _c, _t, _h, _w = x.shape per_row = b for p in [6, 5, 4, 3, 2]: @@ -297,8 +296,6 @@ def add_tensors_with_padding(tensor1, tensor2): def visualize_txt_as_img(width, height, text, font_path='font/DejaVuSans.ttf', size=18): - from PIL import Image, ImageDraw, ImageFont - txt = Image.new("RGB", (width, height), color="white") draw = ImageDraw.Draw(txt) font = ImageFont.truetype(font_path, size=size)