add config (#619)

* add config

* add config

* add config

* add config

* add config

* add config

* add config

* add config
This commit is contained in:
lllyasviel
2023-10-10 00:23:39 -07:00
committed by GitHub
parent c275434c59
commit f92b8038b4
7 changed files with 155 additions and 34 deletions
+1 -1
View File
@@ -1 +1 @@
version = '2.1.34' version = '2.1.35'
+7 -1
View File
@@ -224,7 +224,13 @@ def refresh_everything(refiner_model_name, base_model_name, loras):
refresh_everything( refresh_everything(
refiner_model_name=modules.path.default_refiner_model_name, refiner_model_name=modules.path.default_refiner_model_name,
base_model_name=modules.path.default_base_model_name, base_model_name=modules.path.default_base_model_name,
loras=[(modules.path.default_lora_name, 0.5), ('None', 0.5), ('None', 0.5), ('None', 0.5), ('None', 0.5)] loras=[
(modules.path.default_lora_name, modules.path.default_lora_weight),
('None', modules.path.default_lora_weight),
('None', modules.path.default_lora_weight),
('None', modules.path.default_lora_weight),
('None', modules.path.default_lora_weight)
]
) )
-3
View File
@@ -18,10 +18,7 @@ SCHEDULER_NAMES = ["normal", "karras", "exponential", "sgm_uniform", "simple", "
SAMPLER_NAMES = KSAMPLER_NAMES + ["ddim", "uni_pc", "uni_pc_bh2"] SAMPLER_NAMES = KSAMPLER_NAMES + ["ddim", "uni_pc", "uni_pc_bh2"]
sampler_list = SAMPLER_NAMES sampler_list = SAMPLER_NAMES
default_sampler = 'dpmpp_2m_sde_gpu'
scheduler_list = SCHEDULER_NAMES scheduler_list = SCHEDULER_NAMES
default_scheduler = "karras"
cn_ip = "Image Prompt" cn_ip = "Image Prompt"
cn_canny = "PyraCanny" cn_canny = "PyraCanny"
+71 -17
View File
@@ -1,5 +1,8 @@
import os import os
import json import json
import modules.flags
import modules.sdxl_styles
from modules.model_loader import load_file_from_url from modules.model_loader import load_file_from_url
@@ -16,29 +19,85 @@ except Exception as e:
print(e) print(e)
def get_config_or_set_default(key, default): def get_dir_or_set_default(key, default_value):
global config_dict global config_dict
v = config_dict.get(key, None) v = config_dict.get(key, None)
if isinstance(v, str) and os.path.exists(v) and os.path.isdir(v): if isinstance(v, str) and os.path.exists(v) and os.path.isdir(v):
return v return v
else: else:
dp = os.path.abspath(os.path.join(os.path.dirname(__file__), default)) dp = os.path.abspath(os.path.join(os.path.dirname(__file__), default_value))
os.makedirs(dp, exist_ok=True) os.makedirs(dp, exist_ok=True)
config_dict[key] = dp config_dict[key] = dp
return dp return dp
modelfile_path = get_config_or_set_default('modelfile_path', '../models/checkpoints/') modelfile_path = get_dir_or_set_default('modelfile_path', '../models/checkpoints/')
lorafile_path = get_config_or_set_default('lorafile_path', '../models/loras/') lorafile_path = get_dir_or_set_default('lorafile_path', '../models/loras/')
vae_approx_path = get_config_or_set_default('vae_approx_path', '../models/vae_approx/') vae_approx_path = get_dir_or_set_default('vae_approx_path', '../models/vae_approx/')
upscale_models_path = get_config_or_set_default('upscale_models_path', '../models/upscale_models/') upscale_models_path = get_dir_or_set_default('upscale_models_path', '../models/upscale_models/')
inpaint_models_path = get_config_or_set_default('inpaint_models_path', '../models/inpaint/') inpaint_models_path = get_dir_or_set_default('inpaint_models_path', '../models/inpaint/')
controlnet_models_path = get_config_or_set_default('controlnet_models_path', '../models/controlnet/') controlnet_models_path = get_dir_or_set_default('controlnet_models_path', '../models/controlnet/')
clip_vision_models_path = get_config_or_set_default('clip_vision_models_path', '../models/clip_vision/') clip_vision_models_path = get_dir_or_set_default('clip_vision_models_path', '../models/clip_vision/')
fooocus_expansion_path = get_config_or_set_default('fooocus_expansion_path', fooocus_expansion_path = get_dir_or_set_default('fooocus_expansion_path', '../models/prompt_expansion/fooocus_expansion')
'../models/prompt_expansion/fooocus_expansion') temp_outputs_path = get_dir_or_set_default('temp_outputs_path', '../outputs/')
temp_outputs_path = get_config_or_set_default('temp_outputs_path', '../outputs/')
def get_config_item_or_set_default(key, default_value, validator):
global config_dict
if key not in config_dict:
config_dict[key] = default_value
return default_value
v = config_dict.get(key, None)
if v is None or v == '':
v = 'None'
if validator(v):
return v
else:
config_dict[key] = default_value
return default_value
default_base_model_name = get_config_item_or_set_default(
key='default_model',
default_value='sd_xl_base_1.0_0.9vae.safetensors',
validator=lambda x: isinstance(x, str) and os.path.exists(os.path.join(modelfile_path, x))
)
default_refiner_model_name = get_config_item_or_set_default(
key='default_refiner',
default_value='sd_xl_refiner_1.0_0.9vae.safetensors',
validator=lambda x: x == 'None' or (isinstance(x, str) and os.path.exists(os.path.join(modelfile_path, x)))
)
default_lora_name = get_config_item_or_set_default(
key='default_lora',
default_value='sd_xl_offset_example-lora_1.0.safetensors',
validator=lambda x: x == 'None' or (isinstance(x, str) and os.path.exists(os.path.join(lorafile_path, x)))
)
default_lora_weight = get_config_item_or_set_default(
key='default_lora_weight',
default_value=0.5,
validator=lambda x: isinstance(x, float)
)
default_cfg_scale = get_config_item_or_set_default(
key='default_cfg_scale',
default_value=7.0,
validator=lambda x: isinstance(x, float)
)
default_sampler = get_config_item_or_set_default(
key='default_sampler',
default_value='dpmpp_2m_sde_gpu',
validator=lambda x: x in modules.flags.sampler_list
)
default_scheduler = get_config_item_or_set_default(
key='default_scheduler',
default_value='karras',
validator=lambda x: x in modules.flags.scheduler_list
)
default_styles = get_config_item_or_set_default(
key='default_styles',
default_value=['Fooocus V2', 'Default (Slightly Cinematic)'],
validator=lambda x: isinstance(x, list) and all(y in modules.sdxl_styles.legal_style_names for y in x)
)
with open(config_path, "w", encoding="utf-8") as json_file: with open(config_path, "w", encoding="utf-8") as json_file:
json.dump(config_dict, json_file, indent=4) json.dump(config_dict, json_file, indent=4)
@@ -46,11 +105,6 @@ with open(config_path, "w", encoding="utf-8") as json_file:
os.makedirs(temp_outputs_path, exist_ok=True) os.makedirs(temp_outputs_path, exist_ok=True)
default_base_model_name = 'sd_xl_base_1.0_0.9vae.safetensors'
default_refiner_model_name = 'sd_xl_refiner_1.0_0.9vae.safetensors'
default_lora_name = 'sd_xl_offset_example-lora_1.0.safetensors'
default_lora_weight = 0.5
model_filenames = [] model_filenames = []
lora_filenames = [] lora_filenames = []
+4 -4
View File
@@ -1,6 +1,4 @@
fooocus_expansion = "Fooocus V2" import modules.path
default_styles = ["Default (Slightly Cinematic)"]
# https://github.com/twri/sdxl_prompt_styler/blob/main/sdxl_styles.json # https://github.com/twri/sdxl_prompt_styler/blob/main/sdxl_styles.json
styles = [ styles = [
@@ -933,9 +931,11 @@ def normalize_key(k):
return k return k
default_styles = [normalize_key(x) for x in default_styles]
styles = {normalize_key(k['name']): (k['prompt'], k['negative_prompt']) for k in styles} styles = {normalize_key(k['name']): (k['prompt'], k['negative_prompt']) for k in styles}
style_keys = list(styles.keys()) style_keys = list(styles.keys())
fooocus_expansion = "Fooocus V2"
legal_style_names = [fooocus_expansion] + style_keys
SD_XL_BASE_RATIOS = { SD_XL_BASE_RATIOS = {
"0.5": (704, 1408), "0.5": (704, 1408),
+62 -2
View File
@@ -217,9 +217,69 @@ Below things are already inside the software, and **users do not need to do anyt
13. The joint swap system of refiner now also support img2img and upscale in a seamless way. 13. The joint swap system of refiner now also support img2img and upscale in a seamless way.
14. CFG Scale and TSNR correction (tuned for SDXL) when CFG is bigger than 10. 14. CFG Scale and TSNR correction (tuned for SDXL) when CFG is bigger than 10.
## Changing Model Path ## Customization
After the first time you run Fooocus, a config file will be generated at `Fooocus\user_path_config.txt`. This file can be edited for changing the model path. After the first time you run Fooocus, a config file will be generated at `Fooocus\user_path_config.txt`. This file can be edited for changing the model path. You can also change some parameters to turn Fooocus into "your Fooocus".
For example ["realisticStockPhoto_v10" is a pretty good model from CivitAI](https://civitai.com/models/139565/realistic-stock-photo). This model needs a special `CFG=3.0` and probably works better with some specific styles. Below is an example config to turn Fooocus into a **"Fooocus Realistic Stock Photo Software"**:
`Fooocus\user_path_config.txt`:
```json
{
"modelfile_path": "D:\\Fooocus\\models\\checkpoints",
"lorafile_path": "D:\\Fooocus\\models\\loras",
"vae_approx_path": "D:\\Fooocus\\models\\vae_approx",
"upscale_models_path": "D:\\Fooocus\\models\\upscale_models",
"inpaint_models_path": "D:\\Fooocus\\models\\inpaint",
"controlnet_models_path": "D:\\Fooocus\\models\\controlnet",
"clip_vision_models_path": "D:\\Fooocus\\models\\clip_vision",
"fooocus_expansion_path": "D:\\Fooocus\\models\\prompt_expansion\\fooocus_expansion",
"temp_outputs_path": "D:\\Fooocus\\outputs",
"default_model": "realisticStockPhoto_v10.safetensors",
"default_refiner": "",
"default_lora": "",
"default_lora_weight": 0.25,
"default_cfg_scale": 3.0,
"default_sampler": "dpmpp_2m",
"default_scheduler": "karras",
"default_styles": [
"Fooocus V2",
"Default (Slightly Cinematic)",
"SAI Photographic"
]
}
```
Then you will get this special Fooocus software for you
<details>
<summary>Click here to the see the image. </summary>
![image](https://github.com/lllyasviel/misc/assets/19834515/002b0fd1-2cf3-4cd7-8a73-cde573729c07)
("girl in garden, holding flowers, freckles", seed 12345)
</details>
Below, for comparison, is the default Fooocus without config customization:
<details>
<summary>Click here to the see the image. </summary>
![image](https://github.com/lllyasviel/misc/assets/19834515/1a9fa48b-37af-48bc-bc7e-1cb03bb38b59)
("girl in garden, holding flowers, freckles", seed 12345)
</details>
You can see that default Fooocus is also strong though "realisticStockPhoto_v10" may understand "freckles" better.
Consider twice before you really change the config because in many cases results are worse than default official Fooocus. You are warned, and you need to know exactly what you are doing.
If you find yourself breaking things, just delete `Fooocus\user_path_config.txt`. Fooocus will go back to default.
## Advanced Features ## Advanced Features
+10 -6
View File
@@ -12,7 +12,7 @@ import modules.gradio_hijack as grh
import modules.advanced_parameters as advanced_parameters import modules.advanced_parameters as advanced_parameters
import args_manager import args_manager
from modules.sdxl_styles import style_keys, aspect_ratios, fooocus_expansion, default_styles, default_aspect_ratio from modules.sdxl_styles import legal_style_names, aspect_ratios, fooocus_expansion, default_aspect_ratio
def generate_clicked(*args): def generate_clicked(*args):
@@ -192,8 +192,8 @@ with shared.gradio_root:
with gr.Tab(label='Style'): with gr.Tab(label='Style'):
style_selections = gr.CheckboxGroup(show_label=False, container=False, style_selections = gr.CheckboxGroup(show_label=False, container=False,
choices=[fooocus_expansion] + style_keys, choices=legal_style_names,
value=[fooocus_expansion] + default_styles, value=modules.path.default_styles,
label='Image Style') label='Image Style')
with gr.Tab(label='Model'): with gr.Tab(label='Model'):
with gr.Row(): with gr.Row():
@@ -211,7 +211,7 @@ with shared.gradio_root:
with gr.Tab(label='Advanced'): with gr.Tab(label='Advanced'):
sharpness = gr.Slider(label='Sampling Sharpness', minimum=0.0, maximum=30.0, step=0.001, value=2.0, sharpness = gr.Slider(label='Sampling Sharpness', minimum=0.0, maximum=30.0, step=0.001, value=2.0,
info='Higher value means image and texture are sharper.') info='Higher value means image and texture are sharper.')
guidance_scale = gr.Slider(label='Guidance Scale', minimum=1.0, maximum=30.0, step=0.01, value=7.0, guidance_scale = gr.Slider(label='Guidance Scale', minimum=1.0, maximum=30.0, step=0.01, value=modules.path.default_cfg_scale,
info='Higher value means style is cleaner, vivider, and more artistic.') info='Higher value means style is cleaner, vivider, and more artistic.')
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/117">\U0001F4D4 Document</a>') gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/117">\U0001F4D4 Document</a>')
@@ -229,8 +229,12 @@ with shared.gradio_root:
adaptive_cfg = gr.Slider(label='CFG Mimicking from TSNR', minimum=1.0, maximum=30.0, step=0.01, value=7.0, adaptive_cfg = gr.Slider(label='CFG Mimicking from TSNR', minimum=1.0, maximum=30.0, step=0.01, value=7.0,
info='Enabling Fooocus\'s implementation of CFG mimicking for TSNR ' info='Enabling Fooocus\'s implementation of CFG mimicking for TSNR '
'(effective when real CFG > mimicked CFG).') '(effective when real CFG > mimicked CFG).')
sampler_name = gr.Dropdown(label='Sampler', choices=flags.sampler_list, value=flags.default_sampler, info='Only effective in non-inpaint mode.') sampler_name = gr.Dropdown(label='Sampler', choices=flags.sampler_list,
scheduler_name = gr.Dropdown(label='Scheduler', choices=flags.scheduler_list, value=flags.default_scheduler, info='Scheduler of Sampler.') value=modules.path.default_sampler,
info='Only effective in non-inpaint mode.')
scheduler_name = gr.Dropdown(label='Scheduler', choices=flags.scheduler_list,
value=modules.path.default_scheduler,
info='Scheduler of Sampler.')
overwrite_step = gr.Slider(label='Forced Overwrite of Sampling Step', overwrite_step = gr.Slider(label='Forced Overwrite of Sampling Step',
minimum=-1, maximum=200, step=1, value=-1, minimum=-1, maximum=200, step=1, value=-1,