Compare commits

...
10 Commits
Author SHA1 Message Date
Manuel Schmid c4ce2ce600 Merge pull request #3359 from lllyasviel/develop
Release v2.5.1
2024-07-25 16:00:08 +02:00
Manuel Schmid 03655fa5ea release: bump version to 2.5.1, update changelog 2024-07-25 15:22:02 +02:00
Manuel Schmid a9248c8e46 feat: sort enhance images (mashb1t#62)
* feat: add checkbox, config and handling for saving only the final enhanced image

* feat: sort output of enhance feature

(cherry picked from commit 9d45c0e6ca)
2024-07-25 15:21:56 +02:00
Manuel Schmid 37360e95fe feat: add checkbox, config and handling for saving only the final enhanced image (mashb1t#61)
(cherry picked from commit 829a6dc046)
2024-07-25 15:21:37 +02:00
Manuel Schmid 54985596e8 Merge remote-tracking branch 'upstream/main' into develop_upstream 2024-07-21 12:37:07 +02:00
Manuel Schmid 3a20e14ca0 docs: update attributes and add add inline prompt features section to readme (#3333)
* docs: update attributes and add add inline prompt features section to readme
* docs: update attributes to better show corresponding mutually exclusive groups
2024-07-21 12:36:54 +02:00
Manuel Schmid 2262061145 docs: update attributes to better show corresponding mutually exclusive groups 2024-07-21 12:36:04 +02:00
Manuel Schmid 56928b769b docs: update attributes and add add inline prompt features section to readme 2024-07-21 12:31:17 +02:00
Manuel Schmid 2e8cff296e fix: correctly debug preprocessor again (#3332)
fixes https://github.com/lllyasviel/Fooocus/issues/3327
as discussed in https://github.com/lllyasviel/Fooocus/discussions/3323

add missing inheritance for EarlyReturnException from BaseException to correctly throw and catch
2024-07-21 11:49:28 +02:00
Manuel Schmid f597bf1ab6 fix: allow reading of metadata from jpeg, jpg and webp again (#3301)
also massively improves metadata read speed by switching from filepath (tempfile) to pil, which allows direct processing
2024-07-17 23:30:51 +02:00
10 changed files with 160 additions and 54 deletions
+4 -1
View File
@@ -17,7 +17,7 @@ args_parser.parser.add_argument("--disable-offload-from-vram", action="store_tru
args_parser.parser.add_argument("--theme", type=str, help="launches the UI with light or dark theme", default=None) args_parser.parser.add_argument("--theme", type=str, help="launches the UI with light or dark theme", default=None)
args_parser.parser.add_argument("--disable-image-log", action='store_true', args_parser.parser.add_argument("--disable-image-log", action='store_true',
help="Prevent writing images and logs to hard drive.") help="Prevent writing images and logs to the outputs folder.")
args_parser.parser.add_argument("--disable-analytics", action='store_true', args_parser.parser.add_argument("--disable-analytics", action='store_true',
help="Disables analytics for Gradio.") help="Disables analytics for Gradio.")
@@ -28,6 +28,9 @@ args_parser.parser.add_argument("--disable-metadata", action='store_true',
args_parser.parser.add_argument("--disable-preset-download", action='store_true', args_parser.parser.add_argument("--disable-preset-download", action='store_true',
help="Disables downloading models for presets", default=False) help="Disables downloading models for presets", default=False)
args_parser.parser.add_argument("--disable-enhance-output-sorting", action='store_true',
help="Disables enhance output sorting for final image gallery.")
args_parser.parser.add_argument("--enable-auto-describe-image", action='store_true', args_parser.parser.add_argument("--enable-auto-describe-image", action='store_true',
help="Enables automatic description of uov and enhance image when prompt is empty", default=False) help="Enables automatic description of uov and enhance image when prompt is empty", default=False)
+1 -1
View File
@@ -1 +1 @@
version = '2.5.0' version = '2.5.1'
+3
View File
@@ -68,6 +68,9 @@
"Read wildcards in order": "Read wildcards in order", "Read wildcards in order": "Read wildcards in order",
"Black Out NSFW": "Black Out NSFW", "Black Out NSFW": "Black Out NSFW",
"Use black image if NSFW is detected.": "Use black image if NSFW is detected.", "Use black image if NSFW is detected.": "Use black image if NSFW is detected.",
"Save only final enhanced image": "Save only final enhanced image",
"Save Metadata to Images": "Save Metadata to Images",
"Adds parameters to generated images allowing manual regeneration.": "Adds parameters to generated images allowing manual regeneration.",
"\ud83d\udcda History Log": "\uD83D\uDCDA History Log", "\ud83d\udcda History Log": "\uD83D\uDCDA History Log",
"Image Style": "Image Style", "Image Style": "Image Style",
"Fooocus V2": "Fooocus V2", "Fooocus V2": "Fooocus V2",
+48 -26
View File
@@ -9,7 +9,7 @@ patch_all()
class AsyncTask: class AsyncTask:
def __init__(self, args): def __init__(self, args):
from modules.flags import Performance, MetadataScheme, ip_list, controlnet_image_count from modules.flags import Performance, MetadataScheme, ip_list, controlnet_image_count, disabled
from modules.util import get_enabled_loras from modules.util import get_enabled_loras
from modules.config import default_max_lora_number from modules.config import default_max_lora_number
import args_manager import args_manager
@@ -95,6 +95,7 @@ class AsyncTask:
self.inpaint_advanced_masking_checkbox = args.pop() self.inpaint_advanced_masking_checkbox = args.pop()
self.invert_mask_checkbox = args.pop() self.invert_mask_checkbox = args.pop()
self.inpaint_erode_or_dilate = args.pop() self.inpaint_erode_or_dilate = args.pop()
self.save_final_enhanced_image_only = args.pop() if not args_manager.args.disable_image_log else False
self.save_metadata_to_images = args.pop() if not args_manager.args.disable_metadata else False self.save_metadata_to_images = args.pop() if not args_manager.args.disable_metadata else False
self.metadata_scheme = MetadataScheme( self.metadata_scheme = MetadataScheme(
args.pop()) if not args_manager.args.disable_metadata else MetadataScheme.FOOOCUS args.pop()) if not args_manager.args.disable_metadata else MetadataScheme.FOOOCUS
@@ -153,12 +154,14 @@ class AsyncTask:
enhance_inpaint_erode_or_dilate, enhance_inpaint_erode_or_dilate,
enhance_mask_invert enhance_mask_invert
]) ])
self.should_enhance = self.enhance_checkbox and (self.enhance_uov_method != disabled.casefold() or len(self.enhance_ctrls) > 0)
self.images_to_enhance_count = 0
self.enhance_stats = {}
async_tasks = [] async_tasks = []
class EarlyReturnException: class EarlyReturnException(BaseException):
pass pass
@@ -277,7 +280,7 @@ def worker():
def process_task(all_steps, async_task, callback, controlnet_canny_path, controlnet_cpds_path, current_task_id, def process_task(all_steps, async_task, callback, controlnet_canny_path, controlnet_cpds_path, current_task_id,
denoising_strength, final_scheduler_name, goals, initial_latent, steps, switch, positive_cond, denoising_strength, final_scheduler_name, goals, initial_latent, steps, switch, positive_cond,
negative_cond, task, loras, tiled, use_expansion, width, height, base_progress, preparation_steps, negative_cond, task, loras, tiled, use_expansion, width, height, base_progress, preparation_steps,
total_count, show_intermediate_results): total_count, show_intermediate_results, persist_image=True):
if async_task.last_stop is not False: if async_task.last_stop is not False:
ldm_patched.modules.model_management.interrupt_current_processing() ldm_patched.modules.model_management.interrupt_current_processing()
if 'cn' in goals: if 'cn' in goals:
@@ -314,9 +317,8 @@ def worker():
if modules.config.default_black_out_nsfw or async_task.black_out_nsfw: if modules.config.default_black_out_nsfw or async_task.black_out_nsfw:
progressbar(async_task, current_progress, 'Checking for NSFW content ...') progressbar(async_task, current_progress, 'Checking for NSFW content ...')
imgs = default_censor(imgs) imgs = default_censor(imgs)
progressbar(async_task, current_progress, progressbar(async_task, current_progress, f'Saving image {current_task_id + 1}/{total_count} to system ...')
f'Saving image {current_task_id + 1}/{total_count} to system ...') img_paths = save_and_log(async_task, height, imgs, task, use_expansion, width, loras, persist_image)
img_paths = save_and_log(async_task, height, imgs, task, use_expansion, width, loras)
yield_result(async_task, img_paths, current_progress, async_task.black_out_nsfw, False, yield_result(async_task, img_paths, current_progress, async_task.black_out_nsfw, False,
do_not_show_finished_images=not show_intermediate_results or async_task.disable_intermediate_results) do_not_show_finished_images=not show_intermediate_results or async_task.disable_intermediate_results)
@@ -332,7 +334,7 @@ def worker():
async_task.adaptive_cfg async_task.adaptive_cfg
) )
def save_and_log(async_task, height, imgs, task, use_expansion, width, loras) -> list: def save_and_log(async_task, height, imgs, task, use_expansion, width, loras, persist_image=True) -> list:
img_paths = [] img_paths = []
for x in imgs: for x in imgs:
d = [('Prompt', 'prompt', task['log_positive_prompt']), d = [('Prompt', 'prompt', task['log_positive_prompt']),
@@ -387,7 +389,7 @@ def worker():
d.append(('Metadata Scheme', 'metadata_scheme', d.append(('Metadata Scheme', 'metadata_scheme',
async_task.metadata_scheme.value if async_task.save_metadata_to_images else async_task.save_metadata_to_images)) async_task.metadata_scheme.value if async_task.save_metadata_to_images else async_task.save_metadata_to_images))
d.append(('Version', 'version', 'Fooocus v' + fooocus_version.version)) d.append(('Version', 'version', 'Fooocus v' + fooocus_version.version))
img_paths.append(log(x, d, metadata_parser, async_task.output_format, task)) img_paths.append(log(x, d, metadata_parser, async_task.output_format, task, persist_image))
return img_paths return img_paths
@@ -958,7 +960,7 @@ def worker():
inpaint_engine, inpaint_respective_field, inpaint_strength, inpaint_engine, inpaint_respective_field, inpaint_strength,
prompt, negative_prompt, final_scheduler_name, goals, height, img, mask, prompt, negative_prompt, final_scheduler_name, goals, height, img, mask,
preparation_steps, steps, switch, tiled, total_count, use_expansion, use_style, preparation_steps, steps, switch, tiled, total_count, use_expansion, use_style,
use_synthetic_refiner, width, show_intermediate_results=True): use_synthetic_refiner, width, show_intermediate_results=True, persist_image=True):
base_model_additional_loras = [] base_model_additional_loras = []
inpaint_head_model_path = None inpaint_head_model_path = None
inpaint_parameterized = inpaint_engine != 'None' # inpaint_engine = None, improve detail inpaint_parameterized = inpaint_engine != 'None' # inpaint_engine = None, improve detail
@@ -979,7 +981,7 @@ def worker():
progressbar(async_task, current_progress, 'Checking for NSFW content ...') progressbar(async_task, current_progress, 'Checking for NSFW content ...')
img = default_censor(img) img = default_censor(img)
progressbar(async_task, current_progress, f'Saving image {current_task_id + 1}/{total_count} to system ...') progressbar(async_task, current_progress, f'Saving image {current_task_id + 1}/{total_count} to system ...')
uov_image_path = log(img, d, output_format=async_task.output_format) uov_image_path = log(img, d, output_format=async_task.output_format, persist_image=persist_image)
yield_result(async_task, uov_image_path, current_progress, async_task.black_out_nsfw, False, yield_result(async_task, uov_image_path, current_progress, async_task.black_out_nsfw, False,
do_not_show_finished_images=not show_intermediate_results or async_task.disable_intermediate_results) do_not_show_finished_images=not show_intermediate_results or async_task.disable_intermediate_results)
return current_progress, img, prompt, negative_prompt return current_progress, img, prompt, negative_prompt
@@ -1013,7 +1015,8 @@ def worker():
final_scheduler_name, goals, initial_latent, steps, switch, final_scheduler_name, goals, initial_latent, steps, switch,
task_enhance['c'], task_enhance['uc'], task_enhance, loras, task_enhance['c'], task_enhance['uc'], task_enhance, loras,
tiled, use_expansion, width, height, current_progress, tiled, use_expansion, width, height, current_progress,
preparation_steps, total_count, show_intermediate_results) preparation_steps, total_count, show_intermediate_results,
persist_image)
del task_enhance['c'], task_enhance['uc'] # Save memory del task_enhance['c'], task_enhance['uc'] # Save memory
return current_progress, imgs[0], prompt, negative_prompt return current_progress, imgs[0], prompt, negative_prompt
@@ -1021,7 +1024,7 @@ def worker():
def enhance_upscale(all_steps, async_task, base_progress, callback, controlnet_canny_path, controlnet_cpds_path, def enhance_upscale(all_steps, async_task, base_progress, callback, controlnet_canny_path, controlnet_cpds_path,
current_task_id, denoising_strength, done_steps_inpainting, done_steps_upscaling, enhance_steps, current_task_id, denoising_strength, done_steps_inpainting, done_steps_upscaling, enhance_steps,
prompt, negative_prompt, final_scheduler_name, height, img, preparation_steps, switch, tiled, prompt, negative_prompt, final_scheduler_name, height, img, preparation_steps, switch, tiled,
total_count, use_expansion, use_style, use_synthetic_refiner, width): total_count, use_expansion, use_style, use_synthetic_refiner, width, persist_image=True):
# reset inpaint worker to prevent tensor size issues and not mix upscale and inpainting # reset inpaint worker to prevent tensor size issues and not mix upscale and inpainting
inpaint_worker.current_task = None inpaint_worker.current_task = None
@@ -1039,7 +1042,7 @@ def worker():
controlnet_cpds_path, current_progress, current_task_id, denoising_strength, False, controlnet_cpds_path, current_progress, current_task_id, denoising_strength, False,
'None', 0.0, 0.0, prompt, negative_prompt, final_scheduler_name, 'None', 0.0, 0.0, prompt, negative_prompt, final_scheduler_name,
goals_enhance, height, img, None, preparation_steps, steps, switch, tiled, total_count, goals_enhance, height, img, None, preparation_steps, steps, switch, tiled, total_count,
use_expansion, use_style, use_synthetic_refiner, width) use_expansion, use_style, use_synthetic_refiner, width, persist_image=persist_image)
except ldm_patched.modules.model_management.InterruptProcessingException: except ldm_patched.modules.model_management.InterruptProcessingException:
if async_task.last_stop == 'skip': if async_task.last_stop == 'skip':
@@ -1156,6 +1159,8 @@ def worker():
current_progress += 1 current_progress += 1
progressbar(async_task, current_progress, 'Image processing ...') progressbar(async_task, current_progress, 'Image processing ...')
should_enhance = async_task.enhance_checkbox and (async_task.enhance_uov_method != flags.disabled.casefold() or len(async_task.enhance_ctrls) > 0)
if 'vary' in goals: if 'vary' in goals:
async_task.uov_input_image, denoising_strength, initial_latent, width, height, current_progress = apply_vary( async_task.uov_input_image, denoising_strength, initial_latent, width, height, current_progress = apply_vary(
async_task, async_task.uov_method, denoising_strength, async_task.uov_input_image, switch, async_task, async_task.uov_method, denoising_strength, async_task.uov_input_image, switch,
@@ -1261,8 +1266,8 @@ def worker():
int(current_progress + async_task.callback_steps), int(current_progress + async_task.callback_steps),
f'Sampling step {step + 1}/{total_steps}, image {current_task_id + 1}/{total_count} ...', y)]) f'Sampling step {step + 1}/{total_steps}, image {current_task_id + 1}/{total_count} ...', y)])
should_enhance = async_task.enhance_checkbox and (async_task.enhance_uov_method != flags.disabled.casefold() or len(async_task.enhance_ctrls) > 0) show_intermediate_results = len(tasks) > 1 or async_task.should_enhance
show_intermediate_results = len(tasks) > 1 or should_enhance persist_image = not async_task.should_enhance or not async_task.save_final_enhanced_image_only
for current_task_id, task in enumerate(tasks): for current_task_id, task in enumerate(tasks):
progressbar(async_task, current_progress, f'Preparing task {current_task_id + 1}/{async_task.image_number} ...') progressbar(async_task, current_progress, f'Preparing task {current_task_id + 1}/{async_task.image_number} ...')
@@ -1275,7 +1280,8 @@ def worker():
initial_latent, async_task.steps, switch, task['c'], initial_latent, async_task.steps, switch, task['c'],
task['uc'], task, loras, tiled, use_expansion, width, task['uc'], task, loras, tiled, use_expansion, width,
height, current_progress, preparation_steps, height, current_progress, preparation_steps,
async_task.image_number, show_intermediate_results) async_task.image_number, show_intermediate_results,
persist_image)
current_progress = int(preparation_steps + (100 - preparation_steps) / float(all_steps) * async_task.steps * (current_task_id + 1)) current_progress = int(preparation_steps + (100 - preparation_steps) / float(all_steps) * async_task.steps * (current_task_id + 1))
images_to_enhance += imgs images_to_enhance += imgs
@@ -1293,7 +1299,7 @@ def worker():
execution_time = time.perf_counter() - execution_start_time execution_time = time.perf_counter() - execution_start_time
print(f'Generating and saving time: {execution_time:.2f} seconds') print(f'Generating and saving time: {execution_time:.2f} seconds')
if not should_enhance: if not async_task.should_enhance:
print(f'[Enhance] Skipping, preconditions aren\'t met') print(f'[Enhance] Skipping, preconditions aren\'t met')
stop_processing(async_task, processing_start_time) stop_processing(async_task, processing_start_time)
return return
@@ -1302,9 +1308,14 @@ def worker():
active_enhance_tabs = len(async_task.enhance_ctrls) active_enhance_tabs = len(async_task.enhance_ctrls)
should_process_enhance_uov = async_task.enhance_uov_method != flags.disabled.casefold() should_process_enhance_uov = async_task.enhance_uov_method != flags.disabled.casefold()
enhance_uov_before = False
enhance_uov_after = False
if should_process_enhance_uov: if should_process_enhance_uov:
active_enhance_tabs += 1 active_enhance_tabs += 1
enhance_uov_before = async_task.enhance_uov_processing_order == flags.enhancement_uov_before
enhance_uov_after = async_task.enhance_uov_processing_order == flags.enhancement_uov_after
total_count = len(images_to_enhance) * active_enhance_tabs total_count = len(images_to_enhance) * active_enhance_tabs
async_task.images_to_enhance_count = len(images_to_enhance)
base_progress = current_progress base_progress = current_progress
current_task_id = -1 current_task_id = -1
@@ -1312,19 +1323,23 @@ def worker():
done_steps_inpainting = 0 done_steps_inpainting = 0
enhance_steps, _, _, _ = apply_overrides(async_task, async_task.original_steps, height, width) enhance_steps, _, _, _ = apply_overrides(async_task, async_task.original_steps, height, width)
exception_result = None exception_result = None
for img in images_to_enhance: for index, img in enumerate(images_to_enhance):
async_task.enhance_stats[index] = 0
enhancement_image_start_time = time.perf_counter() enhancement_image_start_time = time.perf_counter()
last_enhance_prompt = async_task.prompt last_enhance_prompt = async_task.prompt
last_enhance_negative_prompt = async_task.negative_prompt last_enhance_negative_prompt = async_task.negative_prompt
if should_process_enhance_uov and async_task.enhance_uov_processing_order == flags.enhancement_uov_before: if enhance_uov_before:
current_task_id += 1 current_task_id += 1
persist_image = not async_task.save_final_enhanced_image_only or active_enhance_tabs == 0
current_task_id, done_steps_inpainting, done_steps_upscaling, img, exception_result = enhance_upscale( current_task_id, done_steps_inpainting, done_steps_upscaling, img, exception_result = enhance_upscale(
all_steps, async_task, base_progress, callback, controlnet_canny_path, controlnet_cpds_path, all_steps, async_task, base_progress, callback, controlnet_canny_path, controlnet_cpds_path,
current_task_id, denoising_strength, done_steps_inpainting, done_steps_upscaling, enhance_steps, current_task_id, denoising_strength, done_steps_inpainting, done_steps_upscaling, enhance_steps,
async_task.prompt, async_task.negative_prompt, final_scheduler_name, height, img, preparation_steps, async_task.prompt, async_task.negative_prompt, final_scheduler_name, height, img, preparation_steps,
switch, tiled, total_count, use_expansion, use_style, use_synthetic_refiner, width) switch, tiled, total_count, use_expansion, use_style, use_synthetic_refiner, width, persist_image)
async_task.enhance_stats[index] += 1
if exception_result == 'continue': if exception_result == 'continue':
continue continue
elif exception_result == 'break': elif exception_result == 'break':
@@ -1336,6 +1351,8 @@ def worker():
current_progress = int(base_progress + (100 - preparation_steps) / float(all_steps) * (done_steps_upscaling + done_steps_inpainting)) current_progress = int(base_progress + (100 - preparation_steps) / float(all_steps) * (done_steps_upscaling + done_steps_inpainting))
progressbar(async_task, current_progress, f'Preparing enhancement {current_task_id + 1}/{total_count} ...') progressbar(async_task, current_progress, f'Preparing enhancement {current_task_id + 1}/{total_count} ...')
enhancement_task_start_time = time.perf_counter() enhancement_task_start_time = time.perf_counter()
is_last_enhance_for_image = (current_task_id + 1) % active_enhance_tabs == 0 and not enhance_uov_after
persist_image = not async_task.save_final_enhanced_image_only or is_last_enhance_for_image
extras = {} extras = {}
if enhance_mask_model == 'sam': if enhance_mask_model == 'sam':
@@ -1366,13 +1383,13 @@ def worker():
async_task.yields.append(['preview', (current_progress, 'Loading ...', mask)]) async_task.yields.append(['preview', (current_progress, 'Loading ...', mask)])
yield_result(async_task, mask, current_progress, async_task.black_out_nsfw, False, yield_result(async_task, mask, current_progress, async_task.black_out_nsfw, False,
async_task.disable_intermediate_results) async_task.disable_intermediate_results)
async_task.enhance_stats[index] += 1
print(f'[Enhance] {dino_detection_count} boxes detected') print(f'[Enhance] {dino_detection_count} boxes detected')
print(f'[Enhance] {sam_detection_count} segments detected in boxes') print(f'[Enhance] {sam_detection_count} segments detected in boxes')
print(f'[Enhance] {sam_detection_on_mask_count} segments applied to mask') print(f'[Enhance] {sam_detection_on_mask_count} segments applied to mask')
if enhance_mask_model == 'sam' and ( if enhance_mask_model == 'sam' and (dino_detection_count == 0 or not async_task.debugging_dino and sam_detection_on_mask_count == 0):
dino_detection_count == 0 or not async_task.debugging_dino and sam_detection_on_mask_count == 0):
print(f'[Enhance] No "{enhance_mask_dino_prompt_text}" detected, skipping') print(f'[Enhance] No "{enhance_mask_dino_prompt_text}" detected, skipping')
continue continue
@@ -1385,7 +1402,8 @@ def worker():
enhance_inpaint_engine, enhance_inpaint_respective_field, enhance_inpaint_strength, enhance_inpaint_engine, enhance_inpaint_respective_field, enhance_inpaint_strength,
enhance_prompt, enhance_negative_prompt, final_scheduler_name, goals_enhance, height, img, mask, enhance_prompt, enhance_negative_prompt, final_scheduler_name, goals_enhance, height, img, mask,
preparation_steps, enhance_steps, switch, tiled, total_count, use_expansion, use_style, preparation_steps, enhance_steps, switch, tiled, total_count, use_expansion, use_style,
use_synthetic_refiner, width) use_synthetic_refiner, width, persist_image=persist_image)
async_task.enhance_stats[index] += 1
if (should_process_enhance_uov and async_task.enhance_uov_processing_order == flags.enhancement_uov_after if (should_process_enhance_uov and async_task.enhance_uov_processing_order == flags.enhancement_uov_after
and async_task.enhance_uov_prompt_type == flags.enhancement_uov_prompt_type_last_filled): and async_task.enhance_uov_prompt_type == flags.enhancement_uov_prompt_type_last_filled):
@@ -1412,14 +1430,18 @@ def worker():
if exception_result == 'break': if exception_result == 'break':
break break
if should_process_enhance_uov and async_task.enhance_uov_processing_order == flags.enhancement_uov_after: if enhance_uov_after:
current_task_id += 1 current_task_id += 1
# last step in enhance, always save
persist_image = True
current_task_id, done_steps_inpainting, done_steps_upscaling, img, exception_result = enhance_upscale( current_task_id, done_steps_inpainting, done_steps_upscaling, img, exception_result = enhance_upscale(
all_steps, async_task, base_progress, callback, controlnet_canny_path, controlnet_cpds_path, all_steps, async_task, base_progress, callback, controlnet_canny_path, controlnet_cpds_path,
current_task_id, denoising_strength, done_steps_inpainting, done_steps_upscaling, enhance_steps, current_task_id, denoising_strength, done_steps_inpainting, done_steps_upscaling, enhance_steps,
last_enhance_prompt, last_enhance_negative_prompt, final_scheduler_name, height, img, last_enhance_prompt, last_enhance_negative_prompt, final_scheduler_name, height, img,
preparation_steps, switch, tiled, total_count, use_expansion, use_style, use_synthetic_refiner, preparation_steps, switch, tiled, total_count, use_expansion, use_style, use_synthetic_refiner,
width) width, persist_image)
async_task.enhance_stats[index] += 1
if exception_result == 'continue': if exception_result == 'continue':
continue continue
elif exception_result == 'break': elif exception_result == 'break':
+6
View File
@@ -562,6 +562,12 @@ default_black_out_nsfw = get_config_item_or_set_default(
validator=lambda x: isinstance(x, bool), validator=lambda x: isinstance(x, bool),
expected_type=bool expected_type=bool
) )
default_save_only_final_enhanced_image = get_config_item_or_set_default(
key='default_save_only_final_enhanced_image',
default_value=False,
validator=lambda x: isinstance(x, bool),
expected_type=bool
)
default_save_metadata_to_images = get_config_item_or_set_default( default_save_metadata_to_images = get_config_item_or_set_default(
key='default_save_metadata_to_images', key='default_save_metadata_to_images',
default_value=False, default_value=False,
+3 -4
View File
@@ -604,9 +604,8 @@ def get_metadata_parser(metadata_scheme: MetadataScheme) -> MetadataParser:
raise NotImplementedError raise NotImplementedError
def read_info_from_image(filepath) -> tuple[str | None, MetadataScheme | None]: def read_info_from_image(file) -> tuple[str | None, MetadataScheme | None]:
with Image.open(filepath) as image: items = (file.info or {}).copy()
items = (image.info or {}).copy()
parameters = items.pop('parameters', None) parameters = items.pop('parameters', None)
metadata_scheme = items.pop('fooocus_scheme', None) metadata_scheme = items.pop('fooocus_scheme', None)
@@ -615,7 +614,7 @@ def read_info_from_image(filepath) -> tuple[str | None, MetadataScheme | None]:
if parameters is not None and is_json(parameters): if parameters is not None and is_json(parameters):
parameters = json.loads(parameters) parameters = json.loads(parameters)
elif exif is not None: elif exif is not None:
exif = image.getexif() exif = file.getexif()
# 0x9286 = UserComment # 0x9286 = UserComment
parameters = exif.get(0x9286, None) parameters = exif.get(0x9286, None)
# 0x927C = MakerNote # 0x927C = MakerNote
+2 -2
View File
@@ -21,8 +21,8 @@ def get_current_html_path(output_format=None):
return html_name return html_name
def log(img, metadata, metadata_parser: MetadataParser | None = None, output_format=None, task=None) -> str: def log(img, metadata, metadata_parser: MetadataParser | None = None, output_format=None, task=None, persist_image=True) -> str:
path_outputs = modules.config.temp_path if args_manager.args.disable_image_log else modules.config.path_outputs path_outputs = modules.config.temp_path if args_manager.args.disable_image_log or not persist_image else modules.config.path_outputs
output_format = output_format if output_format else modules.config.default_output_format output_format = output_format if output_format else modules.config.default_output_format
date_string, local_temp_filename, only_name = generate_temp_filename(folder=path_outputs, extension=output_format) date_string, local_temp_filename, only_name = generate_temp_filename(folder=path_outputs, extension=output_format)
os.makedirs(os.path.dirname(local_temp_filename), exist_ok=True) os.makedirs(os.path.dirname(local_temp_filename), exist_ok=True)
+49 -15
View File
@@ -371,15 +371,14 @@ entry_with_update.py [-h] [--listen [IP]] [--port PORT]
[--hf-mirror HF_MIRROR] [--hf-mirror HF_MIRROR]
[--external-working-path PATH [PATH ...]] [--external-working-path PATH [PATH ...]]
[--output-path OUTPUT_PATH] [--output-path OUTPUT_PATH]
[--temp-path TEMP_PATH] [--temp-path TEMP_PATH] [--cache-path CACHE_PATH]
[--cache-path CACHE_PATH] [--in-browser] [--in-browser] [--disable-in-browser]
[--disable-in-browser]
[--gpu-device-id DEVICE_ID] [--gpu-device-id DEVICE_ID]
[--async-cuda-allocation | --disable-async-cuda-allocation] [--async-cuda-allocation | --disable-async-cuda-allocation]
[--disable-attention-upcast] [--disable-attention-upcast]
[--all-in-fp32 | --all-in-fp16] [--all-in-fp32 | --all-in-fp16]
[--unet-in-bf16 | --unet-in-fp16 | --unet-in-fp8-e4m3fn | --unet-in-fp8-e5m2] [--unet-in-bf16 | --unet-in-fp16 | --unet-in-fp8-e4m3fn | --unet-in-fp8-e5m2]
[--vae-in-fp16 | --vae-in-fp32 | --vae-in-bf16] [--vae-in-fp16 | --vae-in-fp32 | --vae-in-bf16]
[--vae-in-cpu] [--vae-in-cpu]
[--clip-in-fp8-e4m3fn | --clip-in-fp8-e5m2 | --clip-in-fp16 | --clip-in-fp32] [--clip-in-fp8-e4m3fn | --clip-in-fp8-e5m2 | --clip-in-fp16 | --clip-in-fp32]
[--directml [DIRECTML_DEVICE]] [--directml [DIRECTML_DEVICE]]
@@ -387,30 +386,65 @@ entry_with_update.py [-h] [--listen [IP]] [--port PORT]
[--preview-option [none,auto,fast,taesd]] [--preview-option [none,auto,fast,taesd]]
[--attention-split | --attention-quad | --attention-pytorch] [--attention-split | --attention-quad | --attention-pytorch]
[--disable-xformers] [--disable-xformers]
[--always-gpu | --always-high-vram | --always-normal-vram | [--always-gpu | --always-high-vram | --always-normal-vram | --always-low-vram | --always-no-vram | --always-cpu [CPU_NUM_THREADS]]
--always-low-vram | --always-no-vram | --always-cpu [CPU_NUM_THREADS]]
[--always-offload-from-vram] [--always-offload-from-vram]
[--pytorch-deterministic] [--disable-server-log] [--pytorch-deterministic] [--disable-server-log]
[--debug-mode] [--is-windows-embedded-python] [--debug-mode] [--is-windows-embedded-python]
[--disable-server-info] [--multi-user] [--share] [--disable-server-info] [--multi-user] [--share]
[--preset PRESET] [--disable-preset-selection] [--preset PRESET] [--disable-preset-selection]
[--language LANGUAGE] [--language LANGUAGE]
[--disable-offload-from-vram] [--theme THEME] [--disable-offload-from-vram] [--theme THEME]
[--disable-image-log] [--disable-analytics] [--disable-image-log] [--disable-analytics]
[--disable-metadata] [--disable-preset-download] [--disable-metadata] [--disable-preset-download]
[--enable-describe-uov-image] [--disable-enhance-output-sorting]
[--enable-auto-describe-image]
[--always-download-new-model] [--always-download-new-model]
[--rebuild-hash-cache [CPU_NUM_THREADS]]
``` ```
## Inline Prompt Features
### Wildcards
Example prompt: `__color__ flower`
Processed for positive and negative prompt.
Selects a random wildcard from a predefined list of options, in this case the `wildcards/color.txt` file.
The wildcard will be replaced with a random color (randomness based on seed).
You can also disable randomness and process a wildcard file from top to bottom by enabling the checkbox `Read wildcards in order` in Developer Debug Mode.
Wildcards can be nested and combined, and multiple wildcards can be used in the same prompt (example see `wildcards/color_flower.txt`).
### Array Processing
Example prompt: `[[red, green, blue]] flower`
Processed only for positive prompt.
Processes the array from left to right, generating a separate image for each element in the array. In this case 3 images would be generated, one for each color.
Increase the image number to 3 to generate all 3 variants.
Arrays can not be nested, but multiple arrays can be used in the same prompt.
Does support inline LoRAs as array elements!
### Inline LoRAs
Example prompt: `flower <lora:sunflowers:1.2>`
Processed only for positive prompt.
Applies a LoRA to the prompt. The LoRA file must be located in the `models/loras` directory.
## Advanced Features ## Advanced Features
[Click here to browse the advanced features.](https://github.com/lllyasviel/Fooocus/discussions/117) [Click here to browse the advanced features.](https://github.com/lllyasviel/Fooocus/discussions/117)
## Forks
Fooocus also has many community forks, just like SD-WebUI's [vladmandic/automatic](https://github.com/vladmandic/automatic) and [anapnoe/stable-diffusion-webui-ux](https://github.com/anapnoe/stable-diffusion-webui-ux), for enthusiastic users who want to try! Fooocus also has many community forks, just like SD-WebUI's [vladmandic/automatic](https://github.com/vladmandic/automatic) and [anapnoe/stable-diffusion-webui-ux](https://github.com/anapnoe/stable-diffusion-webui-ux), for enthusiastic users who want to try!
| Fooocus' forks | | Fooocus' forks |
| - | | - |
| [fenneishi/Fooocus-Control](https://github.com/fenneishi/Fooocus-Control) </br>[runew0lf/RuinedFooocus](https://github.com/runew0lf/RuinedFooocus) </br> [MoonRide303/Fooocus-MRE](https://github.com/MoonRide303/Fooocus-MRE) </br> [metercai/SimpleSDXL](https://github.com/metercai/SimpleSDXL) </br> and so on ... | | [fenneishi/Fooocus-Control](https://github.com/fenneishi/Fooocus-Control) </br>[runew0lf/RuinedFooocus](https://github.com/runew0lf/RuinedFooocus) </br> [MoonRide303/Fooocus-MRE](https://github.com/MoonRide303/Fooocus-MRE) </br> [metercai/SimpleSDXL](https://github.com/metercai/SimpleSDXL) </br> [mashb1t/Fooocus](https://github.com/mashb1t/Fooocus) </br> and so on ... |
See also [About Forking and Promotion of Forks](https://github.com/lllyasviel/Fooocus/discussions/699). See also [About Forking and Promotion of Forks](https://github.com/lllyasviel/Fooocus/discussions/699).
+10
View File
@@ -1,3 +1,13 @@
# [2.5.1](https://github.com/lllyasviel/Fooocus/releases/tag/v2.5.1)
* Update download URL in readme
* Increase speed of metadata loading
* Fix reading of metadata from jpeg, jpg and webp (exif)
* Fix debug preprocessor
* Update attributes and add inline prompt features section to readme
* Add checkbox, config and handling for saving only the final enhanced image. Use config `default_save_only_final_enhanced_image`, default False.
* Add sorting of final images when enhanced is enabled. Use argument `--disable-enhance-output-sorting` to disable.
# [2.5.0](https://github.com/lllyasviel/Fooocus/releases/tag/v2.5.0) # [2.5.0](https://github.com/lllyasviel/Fooocus/releases/tag/v2.5.0)
This version includes various package updates. If the auto-update doesn't work you can do one of the following: This version includes various package updates. If the auto-update doesn't work you can do one of the following:
+34 -5
View File
@@ -73,6 +73,9 @@ def generate_clicked(task: worker.AsyncTask):
gr.update(visible=True, value=product), \ gr.update(visible=True, value=product), \
gr.update(visible=False) gr.update(visible=False)
if flag == 'finish': if flag == 'finish':
if not args_manager.args.disable_enhance_output_sorting:
product = sort_enhance_images(product, task)
yield gr.update(visible=False), \ yield gr.update(visible=False), \
gr.update(visible=False), \ gr.update(visible=False), \
gr.update(visible=False), \ gr.update(visible=False), \
@@ -90,6 +93,25 @@ def generate_clicked(task: worker.AsyncTask):
return return
def sort_enhance_images(images, task):
if not task.should_enhance or len(images) <= task.images_to_enhance_count:
return images
sorted_images = []
walk_index = task.images_to_enhance_count
for index, enhanced_img in enumerate(images[:task.images_to_enhance_count]):
sorted_images.append(enhanced_img)
if index not in task.enhance_stats:
continue
target_index = walk_index + task.enhance_stats[index]
if walk_index < len(images) and target_index <= len(images):
sorted_images += images[walk_index:target_index]
walk_index += task.enhance_stats[index]
return sorted_images
def inpaint_mode_change(mode, inpaint_engine_version): def inpaint_mode_change(mode, inpaint_engine_version):
assert mode in modules.flags.inpaint_options assert mode in modules.flags.inpaint_options
@@ -339,12 +361,12 @@ with shared.gradio_root:
with gr.TabItem(label='Metadata') as metadata_tab: with gr.TabItem(label='Metadata') as metadata_tab:
with gr.Column(): with gr.Column():
metadata_input_image = grh.Image(label='For images created by Fooocus', source='upload', type='filepath') metadata_input_image = grh.Image(label='For images created by Fooocus', source='upload', type='pil')
metadata_json = gr.JSON(label='Metadata') metadata_json = gr.JSON(label='Metadata')
metadata_import_button = gr.Button(value='Apply Metadata') metadata_import_button = gr.Button(value='Apply Metadata')
def trigger_metadata_preview(filepath): def trigger_metadata_preview(file):
parameters, metadata_scheme = modules.meta_parser.read_info_from_image(filepath) parameters, metadata_scheme = modules.meta_parser.read_info_from_image(file)
results = {} results = {}
if parameters is not None: if parameters is not None:
@@ -748,6 +770,10 @@ with shared.gradio_root:
inputs=black_out_nsfw, outputs=disable_preview, queue=False, inputs=black_out_nsfw, outputs=disable_preview, queue=False,
show_progress=False) show_progress=False)
if not args_manager.args.disable_image_log:
save_final_enhanced_image_only = gr.Checkbox(label='Save only final enhanced image',
value=modules.config.default_save_only_final_enhanced_image)
if not args_manager.args.disable_metadata: if not args_manager.args.disable_metadata:
save_metadata_to_images = gr.Checkbox(label='Save Metadata to Images', value=modules.config.default_save_metadata_to_images, save_metadata_to_images = gr.Checkbox(label='Save Metadata to Images', value=modules.config.default_save_metadata_to_images,
info='Adds parameters to generated images allowing manual regeneration.') info='Adds parameters to generated images allowing manual regeneration.')
@@ -969,6 +995,9 @@ with shared.gradio_root:
ctrls += freeu_ctrls ctrls += freeu_ctrls
ctrls += inpaint_ctrls ctrls += inpaint_ctrls
if not args_manager.args.disable_image_log:
ctrls += [save_final_enhanced_image_only]
if not args_manager.args.disable_metadata: if not args_manager.args.disable_metadata:
ctrls += [save_metadata_to_images, metadata_scheme] ctrls += [save_metadata_to_images, metadata_scheme]
@@ -995,8 +1024,8 @@ with shared.gradio_root:
load_parameter_button.click(modules.meta_parser.load_parameter_button_click, inputs=[prompt, state_is_generating, inpaint_mode], outputs=load_data_outputs, queue=False, show_progress=False) load_parameter_button.click(modules.meta_parser.load_parameter_button_click, inputs=[prompt, state_is_generating, inpaint_mode], outputs=load_data_outputs, queue=False, show_progress=False)
def trigger_metadata_import(filepath, state_is_generating): def trigger_metadata_import(file, state_is_generating):
parameters, metadata_scheme = modules.meta_parser.read_info_from_image(filepath) parameters, metadata_scheme = modules.meta_parser.read_info_from_image(file)
if parameters is None: if parameters is None:
print('Could not find metadata in the image!') print('Could not find metadata in the image!')
parsed_parameters = {} parsed_parameters = {}