mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
@@ -6,15 +6,16 @@
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
import numpy as np
|
||||
from skimage import filters
|
||||
|
||||
|
||||
## Attention Utils
|
||||
def get_dynamic_threshold(tensor):
|
||||
from skimage import filters
|
||||
return filters.threshold_otsu(tensor.float().cpu().numpy())
|
||||
|
||||
|
||||
def attn_map_to_binary(attention_map, scaler=1.):
|
||||
from skimage import filters
|
||||
attention_map_np = attention_map.float().cpu().numpy()
|
||||
threshold_value = filters.threshold_otsu(attention_map_np) * scaler
|
||||
binary_mask = (attention_map_np > threshold_value).astype(np.uint8)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
from skimage import transform as trans
|
||||
|
||||
|
||||
### https://github.com/somanchiu/ReSwapper/blob/GAN/Image.py
|
||||
@@ -74,6 +73,7 @@ arcface_dst = np.array(
|
||||
|
||||
|
||||
def estimate_norm(lmk, image_size=112,mode='arcface'): # pylint: disable=unused-argument
|
||||
from skimage import transform as trans
|
||||
if image_size%112==0:
|
||||
ratio = float(image_size)/112.0
|
||||
diff_x = 0
|
||||
@@ -126,6 +126,7 @@ def square_crop(im, S):
|
||||
|
||||
|
||||
def transform(data, center, output_size, scale, rotation):
|
||||
from skimage import transform as trans
|
||||
scale_ratio = scale
|
||||
rot = float(rotation) * np.pi / 180.0
|
||||
t1 = trans.SimilarityTransform(scale=scale_ratio)
|
||||
|
||||
@@ -8,7 +8,6 @@ import torch
|
||||
import numpy as np
|
||||
import cv2
|
||||
from PIL import Image
|
||||
from skimage import exposure
|
||||
from blendmodes.blend import blendLayers, BlendType
|
||||
from modules import shared, devices, images, sd_models, sd_samplers, sd_hijack_hypertile, processing_vae, timer
|
||||
|
||||
@@ -33,6 +32,7 @@ def setup_color_correction(image):
|
||||
|
||||
|
||||
def apply_color_correction(correction, original_image):
|
||||
from skimage import exposure
|
||||
shared.log.debug(f"Applying color correction: correction={correction.shape} image={original_image}")
|
||||
np_image = np.asarray(original_image)
|
||||
np_recolor = cv2.cvtColor(np_image, cv2.COLOR_RGB2LAB)
|
||||
@@ -545,11 +545,15 @@ def apply_circular(enable: bool, model):
|
||||
if getattr(model, 'texture_tiling', False) == enable:
|
||||
return
|
||||
try:
|
||||
i = 0
|
||||
for layer in [layer for layer in model.unet.modules() if type(layer) is torch.nn.Conv2d]:
|
||||
i += 1
|
||||
layer.padding_mode = 'circular' if enable else 'zeros'
|
||||
for layer in [layer for layer in model.vae.modules() if type(layer) is torch.nn.Conv2d]:
|
||||
i += 1
|
||||
layer.padding_mode = 'circular' if enable else 'zeros'
|
||||
model.texture_tiling = enable
|
||||
shared.log.debug(f'Apply texture tiling: enabled={enable} layers={i} cls={model.__class__.__name__} ')
|
||||
except Exception as e:
|
||||
debug(f"Diffusers tiling failed: {e}")
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import math
|
||||
import numpy as np
|
||||
import skimage
|
||||
import gradio as gr
|
||||
from PIL import Image, ImageDraw
|
||||
import modules.scripts as scripts
|
||||
@@ -60,6 +59,8 @@ def get_matched_noise(_np_src_image, np_mask_rgb, noise_q=1, color_variation=0.0
|
||||
for c in range(3):
|
||||
np_mask_rgb[:, :, c] = hardened[:]
|
||||
return np_mask_rgb
|
||||
|
||||
import skimage
|
||||
width = _np_src_image.shape[0]
|
||||
height = _np_src_image.shape[1]
|
||||
num_channels = _np_src_image.shape[2]
|
||||
|
||||
Reference in New Issue
Block a user