mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
@@ -1,7 +1,7 @@
|
||||
import numpy as np
|
||||
import torch
|
||||
from modules import images_sharpfin
|
||||
import PIL
|
||||
from modules.image import convert
|
||||
|
||||
|
||||
JPEG_QUALITY = 95
|
||||
@@ -13,7 +13,7 @@ def preprocess(image, processor, **kwargs):
|
||||
elif isinstance(image, np.ndarray):
|
||||
image = PIL.Image.fromarray(image)
|
||||
elif isinstance(image, torch.Tensor):
|
||||
image = images_sharpfin.to_pil(image)
|
||||
image = convert.to_pil(image)
|
||||
else:
|
||||
raise TypeError(f"Image must be of type PIL.Image, np.ndarray, or torch.Tensor, got {type(image)} instead.")
|
||||
|
||||
|
||||
@@ -858,8 +858,8 @@ class StableDiffusionXLDiffImg2ImgPipeline(DiffusionPipeline, FromSingleFileMixi
|
||||
|
||||
# 4. Preprocess image
|
||||
#image = self.image_processor.preprocess(image) #ideally we would have preprocess the image with diffusers, but for this POC we won't --- it throws a deprecated warning
|
||||
from modules import images_sharpfin
|
||||
map = images_sharpfin.resize_tensor(map, tuple(s // self.vae_scale_factor for s in original_image.shape[2:]), linearize=False)
|
||||
from modules.image import sharpfin
|
||||
map = sharpfin.resize_tensor(map, tuple(s // self.vae_scale_factor for s in original_image.shape[2:]), linearize=False)
|
||||
# 5. Prepare timesteps
|
||||
def denoising_value_valid(dnv):
|
||||
return type(denoising_end) == float and 0 < dnv < 1
|
||||
@@ -1758,8 +1758,8 @@ class StableDiffusionDiffImg2ImgPipeline(DiffusionPipeline):
|
||||
|
||||
# 7. Prepare extra step kwargs.
|
||||
extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
|
||||
from modules import images_sharpfin
|
||||
map = images_sharpfin.resize_tensor(map, tuple(s // self.vae_scale_factor for s in image.shape[2:]), linearize=False)
|
||||
from modules.image import sharpfin
|
||||
map = sharpfin.resize_tensor(map, tuple(s // self.vae_scale_factor for s in image.shape[2:]), linearize=False)
|
||||
|
||||
# 8. Denoising loop
|
||||
num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order
|
||||
@@ -1834,7 +1834,8 @@ class StableDiffusionDiffImg2ImgPipeline(DiffusionPipeline):
|
||||
import gradio as gr
|
||||
import diffusers
|
||||
from PIL import Image, ImageEnhance, ImageOps # pylint: disable=reimported
|
||||
from modules import errors, shared, devices, scripts_manager, processing, sd_models, images, images_sharpfin
|
||||
from modules import errors, shared, devices, scripts_manager, processing, sd_models, images
|
||||
from modules.image import convert
|
||||
|
||||
|
||||
detector = None
|
||||
@@ -1888,9 +1889,9 @@ class Script(scripts_manager.Script):
|
||||
else:
|
||||
return None, None, None
|
||||
image_mask = image_map.copy()
|
||||
image_map = images_sharpfin.to_tensor(image_map)
|
||||
image_map = convert.to_tensor(image_map)
|
||||
image_map = image_map.to(devices.device)
|
||||
image_init = 2 * images_sharpfin.to_tensor(image_init) - 1
|
||||
image_init = 2 * convert.to_tensor(image_init) - 1
|
||||
image_init = image_init.unsqueeze(0)
|
||||
image_init = image_init.to(devices.device)
|
||||
return image_init, image_map, image_mask
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
from copy import deepcopy
|
||||
from PIL import Image
|
||||
import gradio as gr
|
||||
from modules import scripts_manager, processing, shared, devices, sd_models
|
||||
from modules import scripts_manager, processing, shared, devices
|
||||
|
||||
|
||||
birefnet = None
|
||||
@@ -84,8 +84,8 @@ class Script(scripts_manager.Script):
|
||||
from installer import install
|
||||
install('lpips')
|
||||
|
||||
from modules import images_sharpfin
|
||||
from scripts.lbm import get_model, extract_object, resize_and_center_crop # pylint: disable=no-name-in-module
|
||||
from modules.image import convert
|
||||
from scripts.lbm import extract_object, resize_and_center_crop # pylint: disable=no-name-in-module
|
||||
|
||||
ori_h_bg, ori_w_bg = fg_image.size
|
||||
ar_bg = ori_h_bg / ori_w_bg
|
||||
@@ -110,7 +110,7 @@ class Script(scripts_manager.Script):
|
||||
if lbm_method == 'Simple':
|
||||
output_image = img_pasted
|
||||
else:
|
||||
img_pasted_tensor = images_sharpfin.to_tensor(img_pasted).to(device=devices.device, dtype=devices.dtype).unsqueeze(0) * 2 - 1
|
||||
img_pasted_tensor = convert.to_tensor(img_pasted).to(device=devices.device, dtype=devices.dtype).unsqueeze(0) * 2 - 1
|
||||
batch = { "source_image": img_pasted_tensor }
|
||||
z_source = model.vae.encode(batch[model.source_key])
|
||||
output_image = model.sample(
|
||||
@@ -120,7 +120,7 @@ class Script(scripts_manager.Script):
|
||||
max_samples=1,
|
||||
)
|
||||
output_image = (output_image[0].clamp(-1, 1).float().cpu() + 1) / 2
|
||||
output_image = images_sharpfin.to_pil(output_image)
|
||||
output_image = convert.to_pil(output_image)
|
||||
if lbm_composite:
|
||||
output_image = Image.composite(output_image, bg_image, fg_mask)
|
||||
|
||||
|
||||
@@ -26,13 +26,13 @@ class Script(scripts_manager.Script):
|
||||
def encode(self, p: processing.StableDiffusionProcessing, image: Image.Image):
|
||||
if image is None:
|
||||
return None
|
||||
from modules import images_sharpfin
|
||||
from modules.image import convert
|
||||
if p.width is None or p.width == 0:
|
||||
p.width = int(8 * (image.width * p.scale_by // 8))
|
||||
if p.height is None or p.height == 0:
|
||||
p.height = int(8 * (image.height * p.scale_by // 8))
|
||||
image = images.resize_image(p.resize_mode, image, p.width, p.height, upscaler_name=p.resize_name, context=p.resize_context)
|
||||
tensor = images_sharpfin.to_tensor(image).unsqueeze(0).to(device=devices.device, dtype=devices.dtype)
|
||||
tensor = convert.to_tensor(image).unsqueeze(0).to(device=devices.device, dtype=devices.dtype)
|
||||
tensor = 2.0 * tensor - 1.0
|
||||
with devices.inference_context():
|
||||
latent = shared.sd_model.vae.tiled_encode(tensor)
|
||||
|
||||
@@ -4,6 +4,7 @@ from PIL import Image
|
||||
from modules import processing, shared, images, devices, scripts_manager
|
||||
from modules.processing import get_processed
|
||||
from modules.shared import opts, state, log
|
||||
from modules.image.util import flatten
|
||||
|
||||
|
||||
class Script(scripts_manager.Script):
|
||||
@@ -32,7 +33,7 @@ class Script(scripts_manager.Script):
|
||||
|
||||
if init_img is None:
|
||||
return None
|
||||
init_img = images.flatten(init_img, opts.img2img_background_color)
|
||||
init_img = flatten(init_img, opts.img2img_background_color)
|
||||
|
||||
if isinstance(upscaler_index, str):
|
||||
upscaler_index = [x.name.lower() for x in shared.sd_upscalers].index(upscaler_index.lower())
|
||||
|
||||
+6
-6
@@ -1322,8 +1322,8 @@ class StableDiffusionXLSoftFillPipeline(
|
||||
image.save("noised_image.png")
|
||||
|
||||
image = transforms.CenterCrop((image.size[1] // 64 * 64, image.size[0] // 64 * 64))(image)
|
||||
from modules import images_sharpfin
|
||||
image = images_sharpfin.to_tensor(image)
|
||||
from modules.image import convert
|
||||
image = convert.to_tensor(image)
|
||||
image = image * 2 - 1 # Normalize to [-1, 1]
|
||||
return image.unsqueeze(0)
|
||||
|
||||
@@ -1334,8 +1334,8 @@ class StableDiffusionXLSoftFillPipeline(
|
||||
"""
|
||||
map = map.convert("L")
|
||||
map = transforms.CenterCrop((map.size[1] // 64 * 64, map.size[0] // 64 * 64))(map)
|
||||
from modules import images_sharpfin
|
||||
map = images_sharpfin.to_tensor(map)
|
||||
from modules.image import convert
|
||||
map = convert.to_tensor(map)
|
||||
map = (map - 0.05) / (0.95 - 0.05)
|
||||
map = torch.clamp(map, 0.0, 1.0)
|
||||
return 1.0 - map
|
||||
@@ -1350,8 +1350,8 @@ class StableDiffusionXLSoftFillPipeline(
|
||||
|
||||
# Prepare mask as rescaled tensor map
|
||||
map = preprocess_map(mask).to(device)
|
||||
from modules import images_sharpfin
|
||||
map = images_sharpfin.resize_tensor(map, tuple(s // self.vae_scale_factor for s in original_image_tensor.shape[2:]), linearize=False)
|
||||
from modules.image import sharpfin
|
||||
map = sharpfin.resize_tensor(map, tuple(s // self.vae_scale_factor for s in original_image_tensor.shape[2:]), linearize=False)
|
||||
|
||||
# Generate latent tensor with noise
|
||||
original_with_noise = self.prepare_latents(
|
||||
|
||||
@@ -2,6 +2,7 @@ import time
|
||||
from copy import copy
|
||||
from PIL import Image
|
||||
from modules import shared, images, processing
|
||||
from modules.image.util import draw_text
|
||||
|
||||
|
||||
def draw_xyz_grid(p, xs, ys, zs, x_labels, y_labels, z_labels, cell, draw_legend, include_lone_images, include_sub_grids, first_axes_processed, second_axes_processed, margin_size, no_grid: False, include_time: False, include_text: False): # pylint: disable=unused-argument
|
||||
@@ -50,7 +51,7 @@ def draw_xyz_grid(p, xs, ys, zs, x_labels, y_labels, z_labels, cell, draw_legend
|
||||
if include_time:
|
||||
overlay_text += f'Time: {elapsed:.2f}'
|
||||
if len(overlay_text) > 0:
|
||||
processed_result.images[idx] = images.draw_overlay(processed_result.images[idx], overlay_text)
|
||||
processed_result.images[idx] = draw_text(processed_result.images[idx], overlay_text)
|
||||
processed_result.all_prompts[idx] = processed.prompt
|
||||
processed_result.all_seeds[idx] = processed.seed
|
||||
processed_result.infotexts[idx] = processed.infotexts[0]
|
||||
|
||||
Reference in New Issue
Block a user