Skip to content

Commit

Permalink
fix import timm.models._registry
Browse files Browse the repository at this point in the history
  • Loading branch information
chflame163 committed Oct 16, 2024
1 parent 59bf270 commit a1a37ed
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion py/BiRefNet_legacy/backbones/pvt_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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

Expand Down
2 changes: 1 addition & 1 deletion py/BiRefNet_legacy/modules/mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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

Expand Down
2 changes: 1 addition & 1 deletion py/BiRefNet_v2/models/backbones/pvt_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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

Expand Down
2 changes: 1 addition & 1 deletion py/BiRefNet_v2/models/modules/mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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

Expand Down
2 changes: 1 addition & 1 deletion py/evf_sam/model/unilm/beit3/modeling_finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 21 additions & 16 deletions py/imagefunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion py/sam_hq/modeling/tiny_vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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


Expand Down
1 change: 0 additions & 1 deletion py/shadow_highlight_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def shadow_and_highlight_mask(self, image,
_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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down

0 comments on commit a1a37ed

Please sign in to comment.