fix import timm.models._registry
This commit is contained in:
@@ -3,7 +3,7 @@ import torch.nn as nn
|
||||
from functools import partial
|
||||
|
||||
from timm.models.layers import DropPath, to_2tuple, trunc_normal_
|
||||
from timm.models.registry import register_model
|
||||
from timm.models import register_model
|
||||
|
||||
import math
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import torch.nn as nn
|
||||
from functools import partial
|
||||
|
||||
from timm.models.layers import DropPath, to_2tuple, trunc_normal_
|
||||
from timm.models.registry import register_model
|
||||
from timm.models import register_model
|
||||
|
||||
import math
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import torch.nn as nn
|
||||
from functools import partial
|
||||
|
||||
from timm.models.layers import DropPath, to_2tuple, trunc_normal_
|
||||
from timm.models.registry import register_model
|
||||
from timm.models import register_model
|
||||
|
||||
import math
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import torch.nn as nn
|
||||
from functools import partial
|
||||
|
||||
from timm.models.layers import DropPath, to_2tuple, trunc_normal_
|
||||
from timm.models.registry import register_model
|
||||
from timm.models import register_model
|
||||
|
||||
import math
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
import torch.nn.functional as F
|
||||
from timm.models.registry import register_model
|
||||
from timm.models import register_model
|
||||
import numpy as np
|
||||
|
||||
import utils
|
||||
|
||||
+21
-16
@@ -950,25 +950,30 @@ def get_image_color_average(image:Image, mask:Image=None) -> str:
|
||||
def get_gray_average(image:Image, mask:Image=None) -> int:
|
||||
# image.mode = 'HSV', mask.mode = 'L'
|
||||
image = image.convert('HSV')
|
||||
_, _, _v = image.convert('HSV').split()
|
||||
|
||||
if mask is not None:
|
||||
if mask.mode != 'L':
|
||||
mask = mask.convert('L')
|
||||
width, height = image.size
|
||||
total_gray = 0
|
||||
valid_pixels = 0
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
if mask is not None:
|
||||
if mask.getpixel((x, y)) > 16: #mask亮度低于16的忽略不计
|
||||
gray = _v.getpixel((x, y))
|
||||
total_gray += gray
|
||||
valid_pixels += 1
|
||||
else:
|
||||
gray = _v.getpixel((x, y))
|
||||
total_gray += gray
|
||||
valid_pixels += 1
|
||||
average_gray = total_gray // valid_pixels
|
||||
else:
|
||||
mask = Image.new('L', size=image.size, color='white')
|
||||
_, _, _v = image.convert('HSV').split()
|
||||
_v = np.array(_v)
|
||||
average_gray = _v[np.array(mask) > 16].mean()
|
||||
# width, height = image.size
|
||||
# total_gray = 0
|
||||
# valid_pixels = 0
|
||||
# for y in range(height):
|
||||
# for x in range(width):
|
||||
# if mask is not None:
|
||||
# if mask.getpixel((x, y)) > 16: #mask亮度低于16的忽略不计
|
||||
# gray = _v.getpixel((x, y))
|
||||
# total_gray += gray
|
||||
# valid_pixels += 1
|
||||
# else:
|
||||
# gray = _v.getpixel((x, y))
|
||||
# total_gray += gray
|
||||
# valid_pixels += 1
|
||||
# average_gray = total_gray // valid_pixels
|
||||
return average_gray
|
||||
|
||||
def calculate_shadow_highlight_level(gray:int) -> float:
|
||||
|
||||
@@ -14,7 +14,7 @@ import torch.nn.functional as F
|
||||
import torch.utils.checkpoint as checkpoint
|
||||
from timm.models.layers import DropPath as TimmDropPath,\
|
||||
to_2tuple, trunc_normal_
|
||||
from timm.models.registry import register_model
|
||||
from timm.models import register_model
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
|
||||
@@ -66,7 +66,6 @@ class ShadowAndHighlightMask:
|
||||
_image = tensor2pil(_image).convert('RGB')
|
||||
_mask = input_masks[i] if i < len(input_masks) else input_masks[-1]
|
||||
|
||||
|
||||
avg_gray = get_gray_average(_image, _mask)
|
||||
shadow_level, highlight_level = calculate_shadow_highlight_level(avg_gray)
|
||||
shadow_low_threshold = (shadow_level + shadow_level_offset) / 100 + shadow_range / 2
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[project]
|
||||
name = "comfyui_layerstyle"
|
||||
description = "A set of nodes for ComfyUI it generate image like Adobe Photoshop's Layer Style. the Drop Shadow is first completed node, and follow-up work is in progress."
|
||||
version = "1.0.77"
|
||||
version = "1.0.78"
|
||||
license = "MIT"
|
||||
dependencies = ["numpy", "pillow", "torch", "matplotlib", "Scipy", "scikit_image", "scikit_learn", "opencv-contrib-python", "pymatting", "segment_anything", "timm", "addict", "yapf", "colour-science", "wget", "mediapipe", "loguru", "typer_config", "fastapi", "rich", "google-generativeai", "diffusers", "omegaconf", "tqdm", "transformers", "kornia", "image-reward", "ultralytics", "blend_modes", "blind-watermark", "qrcode", "pyzbar", "transparent-background", "huggingface_hub", "accelerate", "bitsandbytes", "torchscale", "wandb", "hydra-core", "psd-tools", "inference-cli[yolo-world]", "inference-gpu[yolo-world]", "onnxruntime", "peft"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user