Type something to search...
Fooocus

Fooocus

Fooocus

35.1k 4.4k
04 May, 2024
  Python

What is Fooocus ?

Fooocus is an image generating software (based on Gradio).

Fooocus is a rethinking of Stable Diffusion and Midjourney’s designs:

  • Learned from Stable Diffusion, the software is offline, open source, and free.

  • Learned from Midjourney, the manual tweaking is not needed, and users only need to focus on the prompts and images.

Fooocus has included and automated lots of inner optimizations and quality improvements. Users can forget all those difficult technical parameters, and just enjoy the interaction between human and computer to “explore new mediums of thought and expanding the imaginative powers of the human species” [1] .

Fooocus has simplified the installation. Between pressing “download” and generating the first image, the number of needed mouse clicks is strictly limited to less than 3. Minimal GPU memory requirement is 4GB (Nvidia).


Fooocus Demo

fooocus

Non-cherry-picked random batch by just typing two words “forest elf”,

without any parameter tweaking, without any strange prompt tags.

See also non-cherry-picked generalization and diversity tests here and here and here.

In the entire open source community, only Fooocus can achieve this level of non-cherry-picked quality.


Install Fooocus

Moving from Midjourney to Fooocus

Using Fooocus is as easy as (probably easier than) Midjourney – but this does not mean we lack functionality. Below are the details.

MidjourneyFooocus
High-quality text-to-image without needing much prompt engineering or parameter tuning.
(Unknown method)
High-quality text-to-image without needing much prompt engineering or parameter tuning.
(Fooocus has an offline GPT-2 based prompt processing engine and lots of sampling improvements so that results are always beautiful, no matter if your prompt is as short as “house in garden” or as long as 1000 words)
V1 V2 V3 V4Input Image -> Upscale or Variation -> Vary (Subtle) / Vary (Strong)
U1 U2 U3 U4Input Image -> Upscale or Variation -> Upscale (1.5x) / Upscale (2x)
Inpaint / Up / Down / Left / Right (Pan)Input Image -> Inpaint or Outpaint -> Inpaint / Up / Down / Left / Right
(Fooocus uses its own inpaint algorithm and inpaint models so that results are more satisfying than all other software that uses standard SDXL inpaint method/model)
Image PromptInput Image -> Image Prompt
(Fooocus uses its own image prompt algorithm so that result quality and prompt understanding are more satisfying than all other software that uses standard SDXL methods like standard IP-Adapters or Revisions)
—styleAdvanced -> Style
—stylizeAdvanced -> Advanced -> Guidance
—nijiMultiple launchers: “run.bat”, “run_anime.bat”, and “run_realistic.bat”.
Fooocus support SDXL models on Civitai
(You can google search “Civitai” if you do not know about it)
—qualityAdvanced -> Quality
—repeatAdvanced -> Image Number
Multi Prompts (::)Just use multiple lines of prompts
Prompt WeightsYou can use ” I am (happy:1.5)“.
Fooocus uses A1111’s reweighting algorithm so that results are better than ComfyUI if users directly copy prompts from Civitai. (Because if prompts are written in ComfyUI’s reweighting, users are less likely to copy prompt texts as they prefer dragging files)
To use embedding, you can use “(embedding:file_name:1.1)”
—noAdvanced -> Negative Prompt
—arAdvanced -> Aspect Ratios
InsightFaceInput Image -> Image Prompt -> Advanced -> FaceSwap
DescribeInput Image -> Describe

We also have a few things borrowed from the best parts of LeonardoAI:

LeonardoAIFooocus
Prompt MagicAdvanced -> Style -> Fooocus V2
Advanced Sampler Parameters (like Contrast/Sharpness/etc)Advanced -> Advanced -> Sampling Sharpness / etc
User-friendly ControlNetsInput Image -> Image Prompt -> Advanced

Fooocus also developed many “fooocus-only” features for advanced users to get perfect results. Click here to browse the advanced features.

Download

Windows

You can directly download Fooocus with:

>>> Click here to download <<<

After you download the file, please uncompress it and then run the “run.bat”.

image

The first time you launch the software, it will automatically download models:

  1. It will download default models to the folder “Fooocus\models\checkpoints” given different presets. You can download them in advance if you do not want automatic download.

  2. Note that if you use inpaint, at the first time you inpaint an image, it will download Fooocus’s own inpaint control model from here as the file “Fooocus\models\inpaint\inpaint_v26.fooocus.patch” (the size of this file is 1.28GB).

After Fooocus 2.1.60, you will also have run_anime.bat and run_realistic.bat . They are different model presets (and require different models, but they will be automatically downloaded). Check here for more details.

image

If you already have these files, you can copy them to the above locations to speed up installation.

Note that if you see “MetadataIncompleteBuffer” or “PytorchStreamReader”, then your model files are corrupted. Please download models again.

Below is a test on a relatively low-end laptop with 16GB System RAM and 6GB VRAM (Nvidia 3060 laptop). The speed on this machine is about 1.35 seconds per iteration. Pretty impressive – nowadays laptops with 3060 are usually at very acceptable price.

image

Besides, recently many other software report that Nvidia driver above 532 is sometimes 10x slower than Nvidia driver 531. If your generation time is very long, consider download Nvidia Driver 531 Laptop or Nvidia Driver 531 Desktop.

Note that the minimal requirement is 4GB Nvidia GPU memory (4GB VRAM) and 8GB system memory (8GB RAM). This requires using Microsoft’s Virtual Swap technique, which is automatically enabled by your Windows installation in most cases, so you often do not need to do anything about it. However, if you are not sure, or if you manually turned it off (would anyone really do that?), or if you see any “RuntimeError: CPUAllocator”, you can enable it here:

image

And make sure that you have at least 40GB free space on each drive if you still see “RuntimeError: CPUAllocator” !

Please open an issue if you use similar devices but still cannot achieve acceptable performances.

Note that the minimal requirement for different platforms is different.

See also the common problems and troubleshoots here.


Colab

(Last tested - 2023 Dec 12)

| Colab | Info

| --- | --- |

!Open In Colab | Fooocus Official

In Colab, you can modify the last line to !python entry_with_update.py --share or !python entry_with_update.py --preset anime --share or !python entry_with_update.py --preset realistic --share for Fooocus Default/Anime/Realistic Edition.

Note that this Colab will disable refiner by default because Colab free’s resources are relatively limited (and some “big” features like image prompt may cause free-tier Colab to disconnect). We make sure that basic text-to-image is always working on free-tier Colab.

Thanks to camenduru!


Linux (Using Anaconda)

If you want to use Anaconda/Miniconda, you can

Terminal window
git clone https://github.com/lllyasviel/Fooocus.git
cd Fooocus
conda env create -f environment.yaml
conda activate fooocus
pip install -r requirements\_versions.txt

Then download the models: download default models to the folder “Fooocus\models\checkpoints”. Or let Fooocus automatically download the models using the launcher:

Terminal window
conda activate fooocus
python entry_with_update.py

Or, if you want to open a remote port, use

Terminal window
conda activate fooocus
python entry_with_update.py --listen

Use python entry_with_update.py --preset anime or python entry_with_update.py --preset realistic for Fooocus Anime/Realistic Edition.


Linux (Using Python Venv)

Your Linux needs to have Python 3.10 installed, and let’s say your Python can be called with the command python3 with your venv system working; you can

Terminal window
git clone https://github.com/lllyasviel/Fooocus.git
cd Fooocus
python3 -m venv fooocus\_env
source fooocus\_env/bin/activate
pip install -r requirements\_versions.txt

See the above sections for model downloads. You can launch the software with:

Terminal window
source fooocus\_env/bin/activate
python entry_with_update.py

Or, if you want to open a remote port, use

Terminal window
source fooocus_env/bin/activate
python entry_with_update.py --listen

Use python entry_with_update.py --preset anime or python entry_with_update.py --preset realistic for Fooocus Anime/Realistic Edition.


Linux (Using native system Python)

If you know what you are doing, and your Linux already has Python 3.10 installed, and your Python can be called with the command python3 (and Pip with pip3), you can

Terminal window
git clone https://github.com/lllyasviel/Fooocus.git
cd Fooocus
pip3 install -r requirements_versions.txt

See the above sections for model downloads. You can launch the software with:

Terminal window
python3 entry_with_update.py

Or, if you want to open a remote port, use

Terminal window
python3 entry_with_update.py --listen

Use python entry_with_update.py --preset anime or python entry_with_update.py --preset realistic for Fooocus Anime/Realistic Edition.


Linux (AMD GPUs)

Note that the minimal requirement for different platforms is different.

Same with the above instructions. You need to change torch to the AMD version

Terminal window
pip uninstall torch torchvision torchaudio torchtext functorch xformers
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.6

AMD is not intensively tested, however. The AMD support is in beta.

Use python entry_with_update.py --preset anime or python entry_with_update.py --preset realistic for Fooocus Anime/Realistic Edition.


Windows(AMD GPUs)

Note that the minimal requirement for different platforms is different.

Same with Windows. Download the software and edit the content of run.bat as:

Terminal window
.\python\_embeded\python.exe -m pip uninstall torch torchvision torchaudio torchtext functorch xformers -y
.\python\_embeded\python.exe -m pip install torch-directml
.\python_embeded\python.exe -s Fooocus\entry_with\_update.py --directml
pause

Then run the run.bat .

AMD is not intensively tested, however. The AMD support is in beta.

For AMD, use .\python_embeded\python.exe entry_with_update.py --directml --preset anime or .\python_embeded\python.exe entry_with_update.py --directml --preset realistic for Fooocus Anime/Realistic Edition.


Mac

Note that the minimal requirement for different platforms is different.

Mac is not intensively tested. Below is an unofficial guideline for using Mac. You can discuss problems here.

You can install Fooocus on Apple Mac silicon (M1 or M2) with macOS ‘Catalina’ or a newer version. Fooocus runs on Apple silicon computers via PyTorch MPS device acceleration. Mac Silicon computers don’t come with a dedicated graphics card, resulting in significantly longer image processing times compared to computers with dedicated graphics cards.

  1. Install the conda package manager and pytorch nightly. Read the Accelerated PyTorch training on Mac Apple Developer guide for instructions. Make sure pytorch recognizes your MPS device.

  2. Open the macOS Terminal app and clone this repository with git clone https://github.com/lllyasviel/Fooocus.git.

  3. Change to the new Fooocus directory, cd Fooocus.

  4. Create a new conda environment, conda env create -f environment.yaml.

  5. Activate your new conda environment, conda activate fooocus.

  6. Install the packages required by Fooocus, pip install -r requirements_versions.txt.

  7. Launch Fooocus by running python entry_with_update.py. (Some Mac M2 users may need python entry_with_update.py --disable-offload-from-vram to speed up model loading/unloading.) The first time you run Fooocus, it will automatically download the Stable Diffusion SDXL models and will take a significant amount of time, depending on your internet connection.

Use python entry_with_update.py --preset anime or python entry_with_update.py --preset realistic for Fooocus Anime/Realistic Edition.

Download Previous Version

See the guidelines here.


Minimal Requirement

Below is the minimal requirement for running Fooocus locally. If your device capability is lower than this spec, you may not be able to use Fooocus locally. (Please let us know, in any case, if your device capability is lower but Fooocus still works.)

Operating SystemGPUMinimal GPU MemoryMinimal System MemorySystem SwapNote
Windows/LinuxNvidia RTX 4XXX4GB8GBRequiredfastest
Windows/LinuxNvidia RTX 3XXX4GB8GBRequiredusually faster than RTX 2XXX
Windows/LinuxNvidia RTX 2XXX4GB8GBRequiredusually faster than GTX 1XXX
Windows/LinuxNvidia GTX 1XXX8GB (* 6GB uncertain)8GBRequiredonly marginally faster than CPU
Windows/LinuxNvidia GTX 9XX8GB8GBRequiredfaster or slower than CPU
Windows/LinuxNvidia GTX < 9XXNot supported///
WindowsAMD GPU8GB (updated 2023 Dec 30)8GBRequiredvia DirectML (* ROCm is on hold), about 3x slower than Nvidia RTX 3XXX
LinuxAMD GPU8GB8GBRequiredvia ROCm, about 1.5x slower than Nvidia RTX 3XXX
MacM1/M2 MPSSharedSharedSharedabout 9x slower than Nvidia RTX 3XXX
Windows/Linux/Maconly use CPU0GB32GBRequiredabout 17x slower than Nvidia RTX 3XXX

* AMD GPU ROCm (on hold): The AMD is still working on supporting ROCm on Windows.

* Nvidia GTX 1XXX 6GB uncertain: Some people report 6GB success on GTX 10XX, but some other people report failure cases.

Note that Fooocus is only for extremely high quality image generating. We will not support smaller models to reduce the requirement and sacrifice result quality.


Troubleshoot

See the common problems here.

Default Models

Given different goals, the default models and configs of Fooocus are different:

TaskWindowsLinux argsMain ModelRefinerConfig
Generalrun.batjuggernautXL v6_RunDiffusionnot usedhere
Realisticrun_realistic.bat—preset realisticrealistic_stock_photonot usedhere
Animerun_anime.bat—preset animebluepencil_v50dreamsharper_v8 (SD1.5)here

Note that the download is automatic - you do not need to do anything if the internet connection is okay. However, you can download them manually if you (or move them from somewhere else) have your own preparation.

List of “Hidden” Tricks

The below things are already inside the software, and users do not need to do anything about these.

  1. GPT2-based prompt expansion as a dynamic style “Fooocus V2”. (similar to Midjourney’s hidden pre-processsing and “raw” mode, or the LeonardoAI’s Prompt Magic).

  2. Native refiner swap inside one single k-sampler. The advantage is that the refiner model can now reuse the base model’s momentum (or ODE’s history parameters) collected from k-sampling to achieve more coherent sampling. In Automatic1111’s high-res fix and ComfyUI’s node system, the base model and refiner use two independent k-samplers, which means the momentum is largely wasted, and the sampling continuity is broken. Fooocus uses its own advanced k-diffusion sampling that ensures seamless, native, and continuous swap in a refiner setup. (Update Aug 13: Actually, I discussed this with Automatic1111 several days ago, and it seems that the “native refiner swap inside one single k-sampler” is [merged]( https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/12371) into the dev branch of webui. Great!)

  3. Negative ADM guidance. Because the highest resolution level of XL Base does not have cross attentions, the positive and negative signals for XL’s highest resolution level cannot receive enough contrasts during the CFG sampling, causing the results to look a bit plastic or overly smooth in certain cases. Fortunately, since the XL’s highest resolution level is still conditioned on image aspect ratios (ADM), we can modify the adm on the positive/negative side to compensate for the lack of CFG contrast in the highest resolution level. (Update Aug 16, the IOS App Drawing Things will support Negative ADM Guidance. Great!)

  4. We implemented a carefully tuned variation of Section 5.1 of “Improving Sample Quality of Diffusion Models Using Self-Attention Guidance”. The weight is set to very low, but this is Fooocus’s final guarantee to make sure that the XL will never yield an overly smooth or plastic appearance (examples here). This can almost eliminate all cases for which XL still occasionally produces overly smooth results, even with negative ADM guidance. (Update 2023 Aug 18, the Gaussian kernel of SAG is changed to an anisotropic kernel for better structure preservation and fewer artifacts.)

  5. We modified the style templates a bit and added the “cinematic-default”.

  6. We tested the “sd_xl_offset_example-lora_1.0.safetensors” and it seems that when the lora weight is below 0.5, the results are always better than XL without lora.

  7. The parameters of samplers are carefully tuned.

  8. Because XL uses positional encoding for generation resolution, images generated by several fixed resolutions look a bit better than those from arbitrary resolutions (because the positional encoding is not very good at handling int numbers that are unseen during training). This suggests that the resolutions in UI may be hard coded for best results.

  9. Separated prompts for two different text encoders seem unnecessary. Separated prompts for the base model and refiner may work, but the effects are random, and we refrain from implementing this.

  10. The DPM family seems well-suited for XL since XL sometimes generates overly smooth texture, but the DPM family sometimes generates overly dense detail in texture. Their joint effect looks neutral and appealing to human perception.

  11. A carefully designed system for balancing multiple styles as well as prompt expansion.

  12. Using automatic1111’s method to normalize prompt emphasizing. This significantly improves results when users directly copy prompts from civitai.

  13. The joint swap system of the refiner now also supports img2img and upscale in a seamless way.

  14. CFG Scale and TSNR correction (tuned for SDXL) when CFG is bigger than 10.


Customization

After the first time you run Fooocus, a config file will be generated at Fooocus\config.txt . This file can be edited to change the model path or default parameters.

For example, an edited Fooocus\config.txt (this file will be generated after the first launch) may look like this:

Terminal window
{
"path_checkpoints": "D:\Fooocus\models\checkpoints",
"path_loras": "D:\Fooocus\models\loras",
"path_embeddings": "D:\Fooocus\models\embeddings",
"path_vae_approx": "D:\Fooocus\models\vae_approx",
"path_upscale_models": "D:\Fooocus\models\upscale_models",
"path_inpaint": "D:\Fooocus\models\inpaint",
"path_controlnet": "D:\Fooocus\models\controlnet",
"path_clip_vision": "D:\Fooocus\models\clip_vision",
"path_fooocus_expansion": "D:\Fooocus\models\prompt_expansion\fooocus_expansion",
"path_outputs": "D:\Fooocus\outputs",
"default_model": "realisticStockPhoto_v10.safetensors",
"default_refiner": "",
"default_loras": [["lora_filename_1.safetensors", 0.5], ["lora_filename_2.safetensors", 0.5]],
"default_cfg_scale": 3.0,
"default_sampler": "dpmpp_2m",
"default_scheduler": "karras",
"default_negative_prompt": "low quality",
"default_positive_prompt": "",
"default_styles": [
"Fooocus V2",
"Fooocus Photograph",
"Fooocus Negative"
]
}

Many other keys, formats, and examples are in Fooocus\config_modification_tutorial.txt (this file will be generated after the first launch).

Consider twice before you really change the config. If you find yourself breaking things, just delete Fooocus\config.txt . Fooocus will go back to default.

A safer way is just to try “run_anime.bat” or “run_realistic.bat” - they should already be good enough for different tasks.

Note that user_path_config.txt is deprecated and will be removed soon. (Edit: it is already removed.)


All CMD Flags

Terminal window
entry_with_update.py [-h] [--listen [IP]] [--port PORT]
[--disable-header-check [ORIGIN]]
[--web-upload-size WEB_UPLOAD_SIZE]
[--external-working-path PATH [PATH ...]]
[--output-path OUTPUT_PATH] [--temp-path TEMP_PATH]
[--cache-path CACHE_PATH] [--in-browser]
[--disable-in-browser] [--gpu-device-id DEVICE_ID]
[--async-cuda-allocation | --disable-async-cuda-allocation]
[--disable-attention-upcast] [--all-in-fp32 | --all-in-fp16]
[--unet-in-bf16 | --unet-in-fp16 | --unet-in-fp8-e4m3fn | --unet-in-fp8-e5m2]
[--vae-in-fp16 | --vae-in-fp32 | --vae-in-bf16]
[--clip-in-fp8-e4m3fn | --clip-in-fp8-e5m2 | --clip-in-fp16 | --clip-in-fp32]
[--directml [DIRECTML_DEVICE]] [--disable-ipex-hijack]
[--preview-option [none,auto,fast,taesd]]
[--attention-split | --attention-quad | --attention-pytorch]
[--disable-xformers]
[--always-gpu | --always-high-vram | --always-normal-vram |
--always-low-vram | --always-no-vram | --always-cpu]
[--always-offload-from-vram] [--disable-server-log]
[--debug-mode] [--is-windows-embedded-python]
[--disable-server-info] [--share] [--preset PRESET]
[--language LANGUAGE] [--disable-offload-from-vram]
[--theme THEME] [--disable-image-log]