fix bug of Lama node
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import base64
|
||||
import imghdr
|
||||
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
@@ -16,6 +16,10 @@ from torch.hub import download_url_to_file, get_dir
|
||||
import hashlib
|
||||
from .const import DEFAULT_MODEL_DIR
|
||||
|
||||
try :
|
||||
import imghdr
|
||||
except ImportError:
|
||||
from .imghdr import *
|
||||
|
||||
def md5sum(filename):
|
||||
md5 = hashlib.md5()
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
# imghdr.py - Determine the type of an image
|
||||
# Copied from Python standard library
|
||||
|
||||
import io
|
||||
import os
|
||||
|
||||
def what(file, h=None):
|
||||
if h is None:
|
||||
if isinstance(file, str):
|
||||
f = None
|
||||
try:
|
||||
f = open(file, 'rb')
|
||||
h = f.read(32)
|
||||
finally:
|
||||
if f:
|
||||
f.close()
|
||||
elif hasattr(file, 'read'):
|
||||
pos = file.tell()
|
||||
h = file.read(32)
|
||||
file.seek(pos)
|
||||
else:
|
||||
return None
|
||||
for name, test in tests:
|
||||
res = test(h)
|
||||
if res:
|
||||
return name
|
||||
return None
|
||||
|
||||
def test_jpeg(h):
|
||||
if h[0:3] == b'\xff\xd8\xff':
|
||||
return 'jpeg'
|
||||
def test_png(h):
|
||||
if h[:8] == b'\211PNG\r\n\032\n':
|
||||
return 'png'
|
||||
def test_gif(h):
|
||||
if h[:6] in (b'GIF87a', b'GIF89a'):
|
||||
return 'gif'
|
||||
def test_tiff(h):
|
||||
if h[:2] in (b'MM', b'II'):
|
||||
return 'tiff'
|
||||
def test_bmp(h):
|
||||
if h[:2] == b'BM':
|
||||
return 'bmp'
|
||||
def test_webp(h):
|
||||
if h[0:4] == b'RIFF' and h[8:12] == b'WEBP':
|
||||
return 'webp'
|
||||
|
||||
tests = [
|
||||
('jpeg', test_jpeg),
|
||||
('png', test_png),
|
||||
('gif', test_gif),
|
||||
('tiff', test_tiff),
|
||||
('bmp', test_bmp),
|
||||
('webp', test_webp),
|
||||
]
|
||||
@@ -76,6 +76,13 @@ class InpaintModel:
|
||||
|
||||
if config.sd_keep_unmasked_area:
|
||||
mask = mask[:, :, np.newaxis]
|
||||
# Ensure mask shape is (H, W, 1)
|
||||
if mask.ndim == 4 and mask.shape[-1] == 1:
|
||||
mask = mask.squeeze(-1) # remove last dim
|
||||
if mask.ndim == 4:
|
||||
mask = mask.squeeze()
|
||||
if mask.ndim == 3 and mask.shape[-1] != 1:
|
||||
mask = mask[:, :, :1]
|
||||
result = result * (mask / 255) + image[:, :, ::-1] * (1 - (mask / 255))
|
||||
return result
|
||||
|
||||
|
||||
@@ -1692,6 +1692,16 @@ class FcF(InpaintModel):
|
||||
)
|
||||
|
||||
original_pixel_indices = crop_mask < 127
|
||||
|
||||
# --- FIX: Ensure boolean mask matches image shape ---
|
||||
if original_pixel_indices.ndim == 3 and original_pixel_indices.shape[-1] == 1:
|
||||
# Convert (H, W, 1) -> (H, W)
|
||||
original_pixel_indices = original_pixel_indices.squeeze(-1)
|
||||
|
||||
if original_pixel_indices.ndim == 2:
|
||||
# Convert (H, W) -> (H, W, 1) for channel broadcast
|
||||
original_pixel_indices = np.repeat(original_pixel_indices[:, :, None], 3, axis=2)
|
||||
|
||||
inpaint_result[original_pixel_indices] = crop_image[:, :, ::-1][
|
||||
original_pixel_indices
|
||||
]
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
[project]
|
||||
name = "comfyui_layerstyle_advance"
|
||||
description = "The nodes detached from ComfyUI Layer Style are mainly those with complex requirements for dependency packages."
|
||||
version = "2.0.27"
|
||||
version = "2.0.28"
|
||||
license = { text = "MIT License" }
|
||||
dependencies = ["numpy", "matplotlib", "scikit_image", "scikit_learn", "opencv-contrib-python", "pymatting", "timm", "blend_modes", "transformers", "diffusers", "loguru", "colour-science", "huggingface_hub", "segment_anything", "addict", "omegaconf", "yapf", "wget", "iopath", "mediapipe", "typer_config", "fastapi", "rich", "google-generativeai", "ultralytics", "transparent-background", "accelerate", "onnxruntime", "bitsandbytes", "peft", "protobuf", "hydra-core", "blind-watermark", "qrcode", "pyzbar", "psd-tools", "wandb", "zhipuai", "openai","google-genai"]
|
||||
dependencies = ["numpy", "matplotlib", "scikit_image", "scikit_learn", "opencv-contrib-python", "pymatting", "timm", "blend_modes", "transformers", "diffusers", "loguru", "colour-science", "huggingface_hub", "segment_anything", "addict", "omegaconf", "yapf", "wget", "iopath", "mediapipe", "typer_config", "fastapi", "rich", "google-generativeai", "ultralytics", "transparent-background", "accelerate", "onnxruntime", "bitsandbytes", "peft", "protobuf", "hydra-core", "blind-watermark", "qrcode", "pyzbar", "psd-tools", "wandb", "zhipuai", "openai","google-genai", "fastapi","typer-config"]
|
||||
|
||||
[project.urls]
|
||||
Repository = "https://github.com/chflame163/ComfyUI_LayerStyle_Advance"
|
||||
|
||||
@@ -38,3 +38,5 @@ pyzbar
|
||||
psd-tools
|
||||
zhipuai
|
||||
openai
|
||||
typer-config
|
||||
fastapi
|
||||
Reference in New Issue
Block a user