mirror of
https://github.com/vladmandic/automatic
synced 2026-09-20 01:31:13 +02:00
unified logger
This commit is contained in:
+22
-21
@@ -1,6 +1,7 @@
|
||||
import math
|
||||
from PIL import Image, ImageChops, ImageDraw
|
||||
from modules import shared, errors, images
|
||||
from modules import logger
|
||||
|
||||
|
||||
FONT_SIZE=48
|
||||
@@ -9,17 +10,17 @@ FONT_SIZE=48
|
||||
def test_processors(image):
|
||||
from modules.control import processors
|
||||
if image is None:
|
||||
shared.log.error('Image not loaded')
|
||||
logger.log.error('Image not loaded')
|
||||
return None, None, None
|
||||
res = []
|
||||
for processor_id in processors.list_models():
|
||||
if shared.state.interrupted:
|
||||
continue
|
||||
shared.log.info(f'Testing processor: {processor_id}')
|
||||
logger.log.info(f'Testing processor: {processor_id}')
|
||||
processor = processors.Processor(processor_id)
|
||||
output = image
|
||||
if processor is None:
|
||||
shared.log.error(f'Processor load failed: id="{processor_id}"')
|
||||
logger.log.error(f'Processor load failed: id="{processor_id}"')
|
||||
processor_id = f'{processor_id} error'
|
||||
else:
|
||||
output = processor(image)
|
||||
@@ -29,7 +30,7 @@ def test_processors(image):
|
||||
output = output.resize(image.size, Image.Resampling.LANCZOS)
|
||||
if output.mode != image.mode:
|
||||
output = output.convert(image.mode)
|
||||
shared.log.debug(f'Testing processor: input={image} mode={image.mode} output={output} mode={output.mode}')
|
||||
logger.log.debug(f'Testing processor: input={image} mode={image.mode} output={output} mode={output.mode}')
|
||||
diff = ImageChops.difference(image, output)
|
||||
if not diff.getbbox():
|
||||
processor_id = f'{processor_id} null'
|
||||
@@ -44,7 +45,7 @@ def test_processors(image):
|
||||
w, h = 256, 256
|
||||
size = (cols * w + cols, rows * h + rows)
|
||||
grid = Image.new('RGB', size=size, color='black')
|
||||
shared.log.info(f'Test processors: images={len(res)} grid={grid}')
|
||||
logger.log.info(f'Test processors: images={len(res)} grid={grid}')
|
||||
for i, image in enumerate(res):
|
||||
x = (i % cols * w) + (i % cols)
|
||||
y = (i // cols * h) + (i // cols)
|
||||
@@ -59,7 +60,7 @@ def test_controlnets(prompt, negative, image):
|
||||
from modules import devices, sd_models
|
||||
from modules.control.units import controlnet
|
||||
if image is None:
|
||||
shared.log.error('Image not loaded')
|
||||
logger.log.error('Image not loaded')
|
||||
return None, None, None
|
||||
res = []
|
||||
for model_id in controlnet.list_models():
|
||||
@@ -71,9 +72,9 @@ def test_controlnets(prompt, negative, image):
|
||||
if model_id != 'None':
|
||||
controlnet = controlnet.ControlNet(model_id=model_id, device=devices.device, dtype=devices.dtype)
|
||||
if controlnet is None:
|
||||
shared.log.error(f'ControlNet load failed: id="{model_id}"')
|
||||
logger.log.error(f'ControlNet load failed: id="{model_id}"')
|
||||
continue
|
||||
shared.log.info(f'Testing ControlNet: {model_id}')
|
||||
logger.log.info(f'Testing ControlNet: {model_id}')
|
||||
pipe = controlnet.ControlNetPipeline(controlnet=controlnet.model, pipeline=shared.sd_model)
|
||||
pipe.pipeline.to(device=devices.device, dtype=devices.dtype)
|
||||
sd_models.set_diffuser_options(pipe)
|
||||
@@ -95,7 +96,7 @@ def test_controlnets(prompt, negative, image):
|
||||
w, h = 256, 256
|
||||
size = (cols * w + cols, rows * h + rows)
|
||||
grid = Image.new('RGB', size=size, color='black')
|
||||
shared.log.info(f'Test ControlNets: images={len(res)} grid={grid}')
|
||||
logger.log.info(f'Test ControlNets: images={len(res)} grid={grid}')
|
||||
for i, image in enumerate(res):
|
||||
x = (i % cols * w) + (i % cols)
|
||||
y = (i // cols * h) + (i // cols)
|
||||
@@ -110,7 +111,7 @@ def test_adapters(prompt, negative, image):
|
||||
from modules import devices, sd_models
|
||||
from modules.control.units import t2iadapter
|
||||
if image is None:
|
||||
shared.log.error('Image not loaded')
|
||||
logger.log.error('Image not loaded')
|
||||
return None, None, None
|
||||
res = []
|
||||
for model_id in t2iadapter.list_models():
|
||||
@@ -122,9 +123,9 @@ def test_adapters(prompt, negative, image):
|
||||
if model_id != 'None':
|
||||
adapter = t2iadapter.Adapter(model_id=model_id, device=devices.device, dtype=devices.dtype)
|
||||
if adapter is None:
|
||||
shared.log.error(f'Adapter load failed: id="{model_id}"')
|
||||
logger.log.error(f'Adapter load failed: id="{model_id}"')
|
||||
continue
|
||||
shared.log.info(f'Testing Adapter: {model_id}')
|
||||
logger.log.info(f'Testing Adapter: {model_id}')
|
||||
pipe = t2iadapter.AdapterPipeline(adapter=adapter.model, pipeline=shared.sd_model)
|
||||
pipe.pipeline.to(device=devices.device, dtype=devices.dtype)
|
||||
sd_models.set_diffuser_options(pipe)
|
||||
@@ -147,7 +148,7 @@ def test_adapters(prompt, negative, image):
|
||||
w, h = 256, 256
|
||||
size = (cols * w + cols, rows * h + rows)
|
||||
grid = Image.new('RGB', size=size, color='black')
|
||||
shared.log.info(f'Test Adapters: images={len(res)} grid={grid}')
|
||||
logger.log.info(f'Test Adapters: images={len(res)} grid={grid}')
|
||||
for i, image in enumerate(res):
|
||||
x = (i % cols * w) + (i % cols)
|
||||
y = (i // cols * h) + (i // cols)
|
||||
@@ -162,7 +163,7 @@ def test_xs(prompt, negative, image):
|
||||
from modules import devices, sd_models
|
||||
from modules.control.units import xs
|
||||
if image is None:
|
||||
shared.log.error('Image not loaded')
|
||||
logger.log.error('Image not loaded')
|
||||
return None, None, None
|
||||
res = []
|
||||
for model_id in xs.list_models():
|
||||
@@ -174,9 +175,9 @@ def test_xs(prompt, negative, image):
|
||||
if model_id != 'None':
|
||||
xs = xs.ControlNetXS(model_id=model_id, device=devices.device, dtype=devices.dtype)
|
||||
if xs is None:
|
||||
shared.log.error(f'ControlNet-XS load failed: id="{model_id}"')
|
||||
logger.log.error(f'ControlNet-XS load failed: id="{model_id}"')
|
||||
continue
|
||||
shared.log.info(f'Testing ControlNet-XS: {model_id}')
|
||||
logger.log.info(f'Testing ControlNet-XS: {model_id}')
|
||||
pipe = xs.ControlNetXSPipeline(controlnet=xs.model, pipeline=shared.sd_model)
|
||||
pipe.pipeline.to(device=devices.device, dtype=devices.dtype)
|
||||
sd_models.set_diffuser_options(pipe)
|
||||
@@ -198,7 +199,7 @@ def test_xs(prompt, negative, image):
|
||||
w, h = 256, 256
|
||||
size = (cols * w + cols, rows * h + rows)
|
||||
grid = Image.new('RGB', size=size, color='black')
|
||||
shared.log.info(f'Test ControlNet-XS: images={len(res)} grid={grid}')
|
||||
logger.log.info(f'Test ControlNet-XS: images={len(res)} grid={grid}')
|
||||
for i, image in enumerate(res):
|
||||
x = (i % cols * w) + (i % cols)
|
||||
y = (i // cols * h) + (i // cols)
|
||||
@@ -213,7 +214,7 @@ def test_lite(prompt, negative, image):
|
||||
from modules import devices, sd_models
|
||||
from modules.control.units import lite
|
||||
if image is None:
|
||||
shared.log.error('Image not loaded')
|
||||
logger.log.error('Image not loaded')
|
||||
return None, None, None
|
||||
res = []
|
||||
for model_id in lite.list_models():
|
||||
@@ -225,9 +226,9 @@ def test_lite(prompt, negative, image):
|
||||
if model_id != 'None':
|
||||
lite = lite.ControlLLLite(model_id=model_id, device=devices.device, dtype=devices.dtype)
|
||||
if lite is None:
|
||||
shared.log.error(f'Control-LLite load failed: id="{model_id}"')
|
||||
logger.log.error(f'Control-LLite load failed: id="{model_id}"')
|
||||
continue
|
||||
shared.log.info(f'Testing ControlNet-XS: {model_id}')
|
||||
logger.log.info(f'Testing ControlNet-XS: {model_id}')
|
||||
pipe = lite.ControlLLitePipeline(pipeline=shared.sd_model)
|
||||
pipe.apply(controlnet=lite.model, image=image, conditioning=1.0)
|
||||
pipe.pipeline.to(device=devices.device, dtype=devices.dtype)
|
||||
@@ -250,7 +251,7 @@ def test_lite(prompt, negative, image):
|
||||
w, h = 256, 256
|
||||
size = (cols * w + cols, rows * h + rows)
|
||||
grid = Image.new('RGB', size=size, color='black')
|
||||
shared.log.info(f'Test ControlNet-XS: images={len(res)} grid={grid}')
|
||||
logger.log.info(f'Test ControlNet-XS: images={len(res)} grid={grid}')
|
||||
for i, image in enumerate(res):
|
||||
x = (i % cols * w) + (i % cols)
|
||||
y = (i // cols * h) + (i // cols)
|
||||
|
||||
Reference in New Issue
Block a user