Compare commits

..
Author SHA1 Message Date
Manuel Schmid 4e1eaa907f Merge remote-tracking branch 'upstream/main' into feature/checkbox-config
# Conflicts:
#	modules/config.py
#	webui.py
2024-07-27 23:06:03 +02:00
Manuel Schmid 8cc246a51d feat: count image from 1, making config keys more user friendly 2024-07-27 23:04:54 +02:00
Manuel Schmid 4a5f691b9e feat: add config for selected tab, rename desc to describe 2024-07-27 21:34:07 +02:00
Manuel Schmid 0b1fe42971 feat: add configs for controlnet
default_controlnet_image_count, ip_images, ip_stop_ats, ip_weights and ip_types
2024-07-27 21:15:51 +02:00
Manuel Schmid f5906f27a0 feat: add config for default_uov_method 2024-07-27 20:42:54 +02:00
Manuel Schmid 30c0d8f282 refactor: regroup checkbox configs 2024-07-27 20:38:58 +02:00
Manuel Schmid c247f114d7 feat: add config for default_developer_debug_mode_checkbox 2024-07-27 20:36:11 +02:00
Manuel Schmid f826bc16f7 feat: add config for default_invert_mask_checkbox 2024-07-27 20:28:35 +02:00
Manuel Schmid 017587a2fb feat: add config for default_inpaint_advanced_masking_checkbox 2024-07-27 20:28:15 +02:00
Manuel Schmid fa548f049d feat: add config for default_image_prompt_advanced_checkbox 2024-07-27 20:25:44 +02:00
Manuel Schmid 8575c149da feat: add config default_image_prompt_checkbox 2024-07-27 20:24:07 +02:00
Manuel Schmid 3c0f7bd722 Merge remote-tracking branch 'upstream/main' into develop_upstream 2024-07-27 20:16:40 +02:00
Manuel Schmid 591f09d106 docs: update numbering of basic debug procedure in issue template 2024-07-27 13:14:01 +02:00
20 changed files with 38 additions and 88 deletions
+2 -2
View File
@@ -216,9 +216,9 @@ def is_url(url_or_filename):
def load_checkpoint(model,url_or_filename): def load_checkpoint(model,url_or_filename):
if is_url(url_or_filename): if is_url(url_or_filename):
cached_file = download_cached_file(url_or_filename, check_hash=False, progress=True) cached_file = download_cached_file(url_or_filename, check_hash=False, progress=True)
checkpoint = torch.load(cached_file, map_location='cpu', weights_only=True) checkpoint = torch.load(cached_file, map_location='cpu')
elif os.path.isfile(url_or_filename): elif os.path.isfile(url_or_filename):
checkpoint = torch.load(url_or_filename, map_location='cpu', weights_only=True) checkpoint = torch.load(url_or_filename, map_location='cpu')
else: else:
raise RuntimeError('checkpoint url or path is invalid') raise RuntimeError('checkpoint url or path is invalid')
+2 -2
View File
@@ -78,9 +78,9 @@ def blip_nlvr(pretrained='',**kwargs):
def load_checkpoint(model,url_or_filename): def load_checkpoint(model,url_or_filename):
if is_url(url_or_filename): if is_url(url_or_filename):
cached_file = download_cached_file(url_or_filename, check_hash=False, progress=True) cached_file = download_cached_file(url_or_filename, check_hash=False, progress=True)
checkpoint = torch.load(cached_file, map_location='cpu', weights_only=True) checkpoint = torch.load(cached_file, map_location='cpu')
elif os.path.isfile(url_or_filename): elif os.path.isfile(url_or_filename):
checkpoint = torch.load(url_or_filename, map_location='cpu', weights_only=True) checkpoint = torch.load(url_or_filename, map_location='cpu')
else: else:
raise RuntimeError('checkpoint url or path is invalid') raise RuntimeError('checkpoint url or path is invalid')
state_dict = checkpoint['model'] state_dict = checkpoint['model']
+1 -1
View File
@@ -19,7 +19,7 @@ def init_detection_model(model_name, half=False, device='cuda', model_rootpath=N
url=model_url, model_dir='facexlib/weights', progress=True, file_name=None, save_dir=model_rootpath) url=model_url, model_dir='facexlib/weights', progress=True, file_name=None, save_dir=model_rootpath)
# TODO: clean pretrained model # TODO: clean pretrained model
load_net = torch.load(model_path, map_location=lambda storage, loc: storage, weights_only=True) load_net = torch.load(model_path, map_location=lambda storage, loc: storage)
# remove unnecessary 'module.' # remove unnecessary 'module.'
for k, v in deepcopy(load_net).items(): for k, v in deepcopy(load_net).items():
if k.startswith('module.'): if k.startswith('module.'):
+1 -1
View File
@@ -17,7 +17,7 @@ def init_parsing_model(model_name='bisenet', half=False, device='cuda', model_ro
model_path = load_file_from_url( model_path = load_file_from_url(
url=model_url, model_dir='facexlib/weights', progress=True, file_name=None, save_dir=model_rootpath) url=model_url, model_dir='facexlib/weights', progress=True, file_name=None, save_dir=model_rootpath)
load_net = torch.load(model_path, map_location=lambda storage, loc: storage, weights_only=True) load_net = torch.load(model_path, map_location=lambda storage, loc: storage)
model.load_state_dict(load_net, strict=True) model.load_state_dict(load_net, strict=True)
model.eval() model.eval()
model = model.to(device) model = model.to(device)
+1 -1
View File
@@ -104,7 +104,7 @@ def load_ip_adapter(clip_vision_path, ip_negative_path, ip_adapter_path):
offload_device = torch.device('cpu') offload_device = torch.device('cpu')
use_fp16 = model_management.should_use_fp16(device=load_device) use_fp16 = model_management.should_use_fp16(device=load_device)
ip_state_dict = torch.load(ip_adapter_path, map_location="cpu", weights_only=True) ip_state_dict = torch.load(ip_adapter_path, map_location="cpu")
plus = "latents" in ip_state_dict["image_proj"] plus = "latents" in ip_state_dict["image_proj"]
cross_attention_dim = ip_state_dict["ip_adapter"]["1.to_k_ip.weight"].shape[1] cross_attention_dim = ip_state_dict["ip_adapter"]["1.to_k_ip.weight"].shape[1]
sdxl = cross_attention_dim == 2048 sdxl = cross_attention_dim == 2048
+1 -1
View File
@@ -1 +1 @@
version = '2.5.3' version = '2.5.1'
-1
View File
@@ -17,7 +17,6 @@
"Content Type": "Content Type", "Content Type": "Content Type",
"Photograph": "Photograph", "Photograph": "Photograph",
"Art/Anime": "Art/Anime", "Art/Anime": "Art/Anime",
"Apply Styles": "Apply Styles",
"Describe this Image into Prompt": "Describe this Image into Prompt", "Describe this Image into Prompt": "Describe this Image into Prompt",
"Image Size and Recommended Size": "Image Size and Recommended Size", "Image Size and Recommended Size": "Image Size and Recommended Size",
"Upscale or Variation:": "Upscale or Variation:", "Upscale or Variation:": "Upscale or Variation:",
@@ -8,7 +8,7 @@ class CLIPEmbeddingNoiseAugmentation(ImageConcatWithNoiseAugmentation):
if clip_stats_path is None: if clip_stats_path is None:
clip_mean, clip_std = torch.zeros(timestep_dim), torch.ones(timestep_dim) clip_mean, clip_std = torch.zeros(timestep_dim), torch.ones(timestep_dim)
else: else:
clip_mean, clip_std = torch.load(clip_stats_path, map_location="cpu", weights_only=True) clip_mean, clip_std = torch.load(clip_stats_path, map_location="cpu")
self.register_buffer("data_mean", clip_mean[None, :], persistent=False) self.register_buffer("data_mean", clip_mean[None, :], persistent=False)
self.register_buffer("data_std", clip_std[None, :], persistent=False) self.register_buffer("data_std", clip_std[None, :], persistent=False)
self.time_embed = Timestep(timestep_dim) self.time_embed = Timestep(timestep_dim)
+1 -1
View File
@@ -326,7 +326,7 @@ def load_embed(embedding_name, embedding_directory, embedding_size, embed_key=No
except: except:
embed_out = safe_load_embed_zip(embed_path) embed_out = safe_load_embed_zip(embed_path)
else: else:
embed = torch.load(embed_path, map_location="cpu", weights_only=True) embed = torch.load(embed_path, map_location="cpu")
except Exception as e: except Exception as e:
print(traceback.format_exc()) print(traceback.format_exc())
print() print()
@@ -377,15 +377,15 @@ class VQAutoEncoder(nn.Module):
) )
if model_path is not None: if model_path is not None:
chkpt = torch.load(model_path, map_location="cpu", weights_only=True) chkpt = torch.load(model_path, map_location="cpu")
if "params_ema" in chkpt: if "params_ema" in chkpt:
self.load_state_dict( self.load_state_dict(
torch.load(model_path, map_location="cpu", weights_only=True)["params_ema"] torch.load(model_path, map_location="cpu")["params_ema"]
) )
logger.info(f"vqgan is loaded from: {model_path} [params_ema]") logger.info(f"vqgan is loaded from: {model_path} [params_ema]")
elif "params" in chkpt: elif "params" in chkpt:
self.load_state_dict( self.load_state_dict(
torch.load(model_path, map_location="cpu", weights_only=True)["params"] torch.load(model_path, map_location="cpu")["params"]
) )
logger.info(f"vqgan is loaded from: {model_path} [params]") logger.info(f"vqgan is loaded from: {model_path} [params]")
else: else:
@@ -273,8 +273,8 @@ class GFPGANBilinear(nn.Module):
if decoder_load_path: if decoder_load_path:
self.stylegan_decoder.load_state_dict( self.stylegan_decoder.load_state_dict(
torch.load( torch.load(
decoder_load_path, map_location=lambda storage, loc: storage, decoder_load_path, map_location=lambda storage, loc: storage
weights_only=True)["params_ema"] )["params_ema"]
) )
# fix decoder without updating params # fix decoder without updating params
if fix_decoder: if fix_decoder:
@@ -373,8 +373,8 @@ class GFPGANv1(nn.Module):
if decoder_load_path: if decoder_load_path:
self.stylegan_decoder.load_state_dict( self.stylegan_decoder.load_state_dict(
torch.load( torch.load(
decoder_load_path, map_location=lambda storage, loc: storage, decoder_load_path, map_location=lambda storage, loc: storage
weights_only=True)["params_ema"] )["params_ema"]
) )
# fix decoder without updating params # fix decoder without updating params
if fix_decoder: if fix_decoder:
@@ -284,8 +284,8 @@ class GFPGANv1Clean(nn.Module):
if decoder_load_path: if decoder_load_path:
self.stylegan_decoder.load_state_dict( self.stylegan_decoder.load_state_dict(
torch.load( torch.load(
decoder_load_path, map_location=lambda storage, loc: storage, decoder_load_path, map_location=lambda storage, loc: storage
weights_only=True)["params_ema"] )["params_ema"]
) )
# fix decoder without updating params # fix decoder without updating params
if fix_decoder: if fix_decoder:
-13
View File
@@ -702,19 +702,6 @@ default_inpaint_mask_sam_model = get_config_item_or_set_default(
expected_type=str expected_type=str
) )
default_describe_apply_prompts_checkbox = get_config_item_or_set_default(
key='default_describe_apply_prompts_checkbox',
default_value=True,
validator=lambda x: isinstance(x, bool),
expected_type=bool
)
default_describe_content_type = get_config_item_or_set_default(
key='default_describe_content_type',
default_value=[modules.flags.describe_type_photo],
validator=lambda x: all(k in modules.flags.describe_types for k in x),
expected_type=list
)
config_dict["default_loras"] = default_loras = default_loras[:default_max_lora_number] + [[True, 'None', 1.0] for _ in range(default_max_lora_number - len(default_loras))] config_dict["default_loras"] = default_loras = default_loras[:default_max_lora_number] + [[True, 'None', 1.0] for _ in range(default_max_lora_number - len(default_loras))]
# mapping config to meta parameter # mapping config to meta parameter
+1 -1
View File
@@ -231,7 +231,7 @@ def get_previewer(model):
if vae_approx_filename in VAE_approx_models: if vae_approx_filename in VAE_approx_models:
VAE_approx_model = VAE_approx_models[vae_approx_filename] VAE_approx_model = VAE_approx_models[vae_approx_filename]
else: else:
sd = torch.load(vae_approx_filename, map_location='cpu', weights_only=True) sd = torch.load(vae_approx_filename, map_location='cpu')
VAE_approx_model = VAEApprox() VAE_approx_model = VAEApprox()
VAE_approx_model.load_state_dict(sd) VAE_approx_model.load_state_dict(sd)
del sd del sd
-1
View File
@@ -96,7 +96,6 @@ inpaint_options = [inpaint_option_default, inpaint_option_detail, inpaint_option
describe_type_photo = 'Photograph' describe_type_photo = 'Photograph'
describe_type_anime = 'Art/Anime' describe_type_anime = 'Art/Anime'
describe_types = [describe_type_photo, describe_type_anime]
sdxl_aspect_ratios = [ sdxl_aspect_ratios = [
'704*1408', '704*1344', '768*1344', '768*1280', '832*1216', '832*1152', '704*1408', '704*1344', '768*1344', '768*1280', '832*1216', '832*1152',
+1 -1
View File
@@ -196,7 +196,7 @@ class InpaintWorker:
if inpaint_head_model is None: if inpaint_head_model is None:
inpaint_head_model = InpaintHead() inpaint_head_model = InpaintHead()
sd = torch.load(inpaint_head_model_path, map_location='cpu', weights_only=True) sd = torch.load(inpaint_head_model_path, map_location='cpu')
inpaint_head_model.load_state_dict(sd) inpaint_head_model.load_state_dict(sd)
feed = torch.cat([ feed = torch.cat([
+1 -1
View File
@@ -17,7 +17,7 @@ def perform_upscale(img):
if model is None: if model is None:
model_filename = downloading_upscale_model() model_filename = downloading_upscale_model()
sd = torch.load(model_filename, weights_only=True) sd = torch.load(model_filename)
sdo = OrderedDict() sdo = OrderedDict()
for k, v in sd.items(): for k, v in sd.items():
sdo[k.replace('residual_block_', 'RDB')] = v sdo[k.replace('residual_block_', 'RDB')] = v
-10
View File
@@ -1,13 +1,3 @@
# [2.5.3](https://github.com/lllyasviel/Fooocus/releases/tag/v2.5.3)
* Only load weights from non-safetensors files, preventing harmful code injection
* Add checkbox for applying/resetting styles when describing images, also allowing multiple describe content types
# [2.5.2](https://github.com/lllyasviel/Fooocus/releases/tag/v2.5.2)
* Fix not adding positive prompt when styles didn't have a {prompt} placeholder in the positive prompt
* Extend config settings for input image, see list in [PR](https://github.com/lllyasviel/Fooocus/pull/3382)
# [2.5.1](https://github.com/lllyasviel/Fooocus/releases/tag/v2.5.1) # [2.5.1](https://github.com/lllyasviel/Fooocus/releases/tag/v2.5.1)
* Update download URL in readme * Update download URL in readme
+16 -41
View File
@@ -337,11 +337,10 @@ with shared.gradio_root:
with gr.Column(): with gr.Column():
describe_input_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False) describe_input_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False)
with gr.Column(): with gr.Column():
describe_methods = gr.CheckboxGroup( describe_method = gr.Radio(
label='Content Type', label='Content Type',
choices=flags.describe_types, choices=[flags.describe_type_photo, flags.describe_type_anime],
value=modules.config.default_describe_content_type) value=flags.describe_type_photo)
describe_apply_styles = gr.Checkbox(label='Apply Styles', value=modules.config.default_describe_apply_prompts_checkbox)
describe_btn = gr.Button(value='Describe this Image into Prompt') describe_btn = gr.Button(value='Describe this Image into Prompt')
describe_image_size = gr.Textbox(label='Image Size and Recommended Size', elem_id='describe_image_size', visible=False) describe_image_size = gr.Textbox(label='Image Size and Recommended Size', elem_id='describe_image_size', visible=False)
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/1363" target="_blank">\U0001F4D4 Documentation</a>') gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/1363" target="_blank">\U0001F4D4 Documentation</a>')
@@ -1061,54 +1060,30 @@ with shared.gradio_root:
gr.Audio(interactive=False, value=notification_file, elem_id='audio_notification', visible=False) gr.Audio(interactive=False, value=notification_file, elem_id='audio_notification', visible=False)
break break
def trigger_describe(modes, img, apply_styles): def trigger_describe(mode, img):
describe_prompts = [] if mode == flags.describe_type_photo:
styles = set()
if flags.describe_type_photo in modes:
from extras.interrogate import default_interrogator as default_interrogator_photo from extras.interrogate import default_interrogator as default_interrogator_photo
describe_prompts.append(default_interrogator_photo(img)) return default_interrogator_photo(img), ["Fooocus V2", "Fooocus Enhance", "Fooocus Sharp"]
styles.update(["Fooocus V2", "Fooocus Enhance", "Fooocus Sharp"]) if mode == flags.describe_type_anime:
if flags.describe_type_anime in modes:
from extras.wd14tagger import default_interrogator as default_interrogator_anime from extras.wd14tagger import default_interrogator as default_interrogator_anime
describe_prompts.append(default_interrogator_anime(img)) return default_interrogator_anime(img), ["Fooocus V2", "Fooocus Masterpiece"]
styles.update(["Fooocus V2", "Fooocus Masterpiece"]) return mode, ["Fooocus V2"]
if len(styles) == 0 or not apply_styles: describe_btn.click(trigger_describe, inputs=[describe_method, describe_input_image],
styles = gr.update() outputs=[prompt, style_selections], show_progress=True, queue=True)
else:
styles = list(styles)
if len(describe_prompts) == 0:
describe_prompt = gr.update()
else:
describe_prompt = ', '.join(describe_prompts)
return describe_prompt, styles
describe_btn.click(trigger_describe, inputs=[describe_methods, describe_input_image, describe_apply_styles],
outputs=[prompt, style_selections], show_progress=True, queue=True) \
.then(fn=style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) \
.then(lambda: None, _js='()=>{refresh_style_localization();}')
if args_manager.args.enable_auto_describe_image: if args_manager.args.enable_auto_describe_image:
def trigger_auto_describe(mode, img, prompt, apply_styles): def trigger_auto_describe(mode, img, prompt):
# keep prompt if not empty # keep prompt if not empty
if prompt == '': if prompt == '':
return trigger_describe(mode, img, apply_styles) return trigger_describe(mode, img)
return gr.update(), gr.update() return gr.update(), gr.update()
uov_input_image.upload(trigger_auto_describe, inputs=[describe_methods, uov_input_image, prompt, describe_apply_styles], uov_input_image.upload(trigger_auto_describe, inputs=[describe_method, uov_input_image, prompt],
outputs=[prompt, style_selections], show_progress=True, queue=True) \ outputs=[prompt, style_selections], show_progress=True, queue=True)
.then(fn=style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) \
.then(lambda: None, _js='()=>{refresh_style_localization();}')
enhance_input_image.upload(lambda: gr.update(value=True), outputs=enhance_checkbox, queue=False, show_progress=False) \ enhance_input_image.upload(lambda: gr.update(value=True), outputs=enhance_checkbox, queue=False, show_progress=False) \
.then(trigger_auto_describe, inputs=[describe_methods, enhance_input_image, prompt, describe_apply_styles], .then(trigger_auto_describe, inputs=[describe_method, enhance_input_image, prompt], outputs=[prompt, style_selections], show_progress=True, queue=True)
outputs=[prompt, style_selections], show_progress=True, queue=True) \
.then(fn=style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) \
.then(lambda: None, _js='()=>{refresh_style_localization();}')
def dump_default_english_config(): def dump_default_english_config():
from modules.localization import dump_english_config from modules.localization import dump_english_config