AIGC automatic image painting generation software based on Gradio/Stable Diffusion/Midjourney - Fooocus

0.Reference

This project: GitHub - lllyasviel/Fooocus: Focus on prompting and generating

Author: Lvmin Zhang

Edit

lllyasviel

Another masterpiece ContorlNet  https://github.com/lllyasviel/ControlNet

Model: https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0

https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0_0.9vae.safetensors

https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0_0.9vae.safetensors

Dependent projects:

GitHub - AUTOMATIC1111/stable-diffusion-webui: Stable Diffusion web UI

GitHub - comfyanonymous/ComfyUI: A powerful and modular stable diffusion GUI with a graph/nodes interface.

1.Abstract

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

Fooocus is a rethinking of Stable Diffusion and Midjourney designs:

  • Learn from Stable Diffusion, which is offline, open source, and free.

  • Learned from Midjourney that no manual adjustments are required, users just need to pay attention to the prompts and images.

Fooocus includes and automates many internal optimizations and quality improvements . Users can forget all those difficult technical parameters and just enjoy the interaction between humans and computers, "exploring new thinking media and expanding human imagination  [1]. "

Fooocus simplifies installation. The number of mouse clicks required between pressing "Download" and generating the first image is strictly limited to 3 times. Minimum GPU memory requirement is 4GB (Nvidia) .

The most important thing is that after deployment, it can be used even if the network is disconnected!

2. Effect preview

Temporary experience link (valid for 3 days): Fooocus 2.0.0 http://t.csdn.cn/mx6V2

here is the image.


Prompt word: Let the rain and mist spread all your life

Prompt words: Chinese style women and architecture

461602a6514d4ec99f06090649d5a39c.png

Prompt word: underwater world

0271a7951f4d47218f210e74c240cd20.png

Prompt word: Future Earth Fantasy

3987c875eb8c4761aa8536ebd6c34367.png

Prompt word: Jiang Yu Fei Fei Jiang Caoqi

264e07bd9c0144fe9c4b0bafbb2cb57b.png

Prompt word: boy who chases stars

9c2b514e03524b098789a8ab369710fb.png

The latest version adds a photo editing function  https://github.com/lllyasviel/Fooocus/discussions/390

Add mask automatic cutout function  https://github.com/lllyasviel/Fooocus/discussions/414

Add mask area 

Keep the same prompt word, select 1 photo, and generate it again

3.Environment preparation

After looking at the AIGC pictures above, are you eager to try it out?

3.1.Hardware configuration

The minimum requirements are 4GB Nvidia GPU memory (4GB VRAM) and 8GB system memory (8GB RAM).

3.2. Install Nvidia Drivers and Conda Toolkit

If Nvidia is not installed, please refer to

NVIDIA GPU driver and CUDA toolkit Linux CentOS 7 online installation guide_Entropy-Go's blog-CSDN blog

Install NVIDIA GPU driver and NVIDIA CUDA toolkit on Linux CentOS_Install nvidia driver on centos_Entropy-Go's blog-CSDN blog

3.3. Install Conda

Quick installation package management tool Conda on CentOS_Entropy-Go's blog-CSDN blog

4. Deploy project Fooocus on Linux

4.1. git clone download or download project

git clone https://github.com/lllyasviel/Fooocus.git

4.2. conda activation

cd Fooocus
conda env create -f environment.yaml
conda activate fooocus

If the conda environment variable is not set normally, it can be initialized.

conda init bash

4.3. Install dependent libraries

pip install -r requirements_versions.txt

4.4.Run

Then download the models: download sd_xl_base_1.0_0.9vae.safetensors from here as file "Fooocus\models\checkpoints\sd_xl_base_1.0_0.9vae.safetensors" and download sd_xl_refiner_1.0_0.9vae.safetensors from here as file "Fooocus" \models \checkpoints\sd_xl_refiner_1.0_0.9vae.safetensors". Or let Fooocus use the launcher to automatically download the model launch.py.

4.4.1. Local access

python launch.py

When running for the first time, the model and dependent libraries will be downloaded to ensure that the network connection is normal.

Run successfully

Fooocus Expansion engine loaded.
App started successful. Use the app with http://localhost:7860/ or 127.0.0.1:7860

Direct browser access 

http://localhost:7860/

127.0.0.1:7860

The default port is 7860, you can also specify the port number through the --port parameter

python launch.py --port 8888

4.4.2. LAN access

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

python launch.py --listen

Fooocus Expansion engine loaded.
App started successful. Use the app with http://localhost:7860/ or 0.0.0.0:7860

4.4.3. Temporary public network access

python launch.py --listen --share

The only temporary address https://b54bc590bc4bfdf404.gradio.live can be accessed from the public network within 72 hours.

Running on public URL: https://b54bc590bc4bfdf404.gradio.live

This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)

Fooocus Expansion engine loaded.
App started successful. Use the app with http://localhost:7860/ or 0.0.0.0:7860 or https://b54bc590bc4bfdf404.gradio.live
 

5. Deploy project Fooocus on Windows

You can download Fooocus directly:

>>>Click here to download<<<

After downloading the file, unzip it and run "run.bat".

Edit

When you start the software for the first time, it will automatically download the model:

  1. It will download sd_xl_base_1.0_0.9vae.safetensors from here as file "Fooocus\models\checkpoints\sd_xl_base_1.0_0.9vae.safetensors".
  2. It will download sd_xl_refiner_1.0_0.9vae.safetensors from here as file "Fooocus\models\checkpoints\sd_xl_refiner_1.0_0.9vae.safetensors".

Edit

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

Please note that if you see "MetadataIncompleteBuffer" , your model file is corrupted. Please download the model again.

Below are tests conducted on a relatively low-end laptop (Nvidia 3060 laptop) with 16GB of system RAM and 6GB of VRAM . The speed on this machine is about 1.35 seconds per iteration. Pretty impressive - 3060-equipped laptops these days are generally very affordable.

Edit

Additionally, many other software have recently reported that drivers above Nvidia 532 are sometimes up to 10 times slower than Nvidia driver 531. If your build times are long, consider downloading Nvidia Driver 531 Laptop or Nvidia Driver 531 Desktop .

Please note that the minimum requirements are 4GB Nvidia GPU memory (4GB VRAM) and 8GB system memory (8GB RAM) . This requires the use of Microsoft's Virtual Switching technology, which in most cases is automatically enabled by Windows installations, so you usually don't need to do anything about it. However, if you're not sure, or you manually turn it off (does anyone really do that?), or if you see any "RuntimeError: CPUAllocator" , you can enable it here:

Click here to view image description.

Edit

If you still see "RuntimeError: CPUAllocator", make sure you have at least 40GB of free space on each drive!

6. Start experiencing the AIGC drawing journey

6.1. Browser access the corresponding link

ad26bdfac2d44b8bac7f5c86adfa4570.png

6.2. Enter the prompt word and directly generate the picture

You can enter prompt words in Chinese, and 2 pictures will be generated by default. For the default configuration, click Advance to check the settings.

6.3. Settings

53422f5266b740a983fcfb76c06ef9fa.png

6.4. Style

bf5a5705a14d446281f75c05dac7677a.png

6.5. Advanced functions

15b3becdb4954fe7aa3aea7db3886684.png

6.6.Drawing

7ac6d9bbcdbb415cb186b9888a54b89f.png

The corresponding model inference process:

############################generate_clicked
############################args: ('logo with "CSDN" charaters', '', ['Fooocus V2', 'Default (Slightly Cinematic)'], 'Speed', '1344?04', 2, 652019699, 2, 'sd_xl_base_1.0_0.9vae.safetensors', 'sd_xl_refiner_1.0_0.9vae.safetensors', 'sd_xl_offset_example-lora_1.0.safetensors', 0.5, 'None', 0.5, 'None', 0.5, 'None', 0.5, 'None', 0.5)
Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.
[Prompt Expansion] New suffix: intricate, elegant. highly detailed, digital painting, artstation, concept art, smooth, sharp, focus, illustration.. art by artgerm and greg rutkowski and alphonse mucha
Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.
[Prompt Expansion] New suffix: extremely clean, brush strokes, and octane render, trending on artstation
 67%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258b                     | 20/30 [00:37<00:18,  1.88s/it]Refiner swapped.
100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 30/30 [00:57<00:00,  1.93s/it]
Image generated with private log at: /home/xxx/Fooocus/outputs/2023-09-14/log.html
 67%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258b                     | 20/30 [00:37<00:18,  1.89s/it]Refiner swapped.
100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 30/30 [00:57<00:00,  1.93s/it]
Image generated with private log at: /home/xxx/Fooocus/outputs/2023-09-14/log.html
 

6.7.Drawing successful

Images are stored in Fooocus/output/ files.

You can also view all prompt words and generated records through log.html

http://localhost:8888/file=./outputs/2023-09-16/log.html

b43ae238abf147188e556a042cc23f73.png

6.8. GPU computing resources when calling model inference

The remaining GPU resources are basically full. When playing AI deep learning, you can consider strategically stocking up graphics cards to maximize the computing power.

nvidia-smi 
Thu Sep 14 05:53:55 2023       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.86.10              Driver Version: 535.86.10    CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  Tesla P100-PCIE-16GB           Off | 00000000:31:00.0 Off |                    0 |
| N/A   59C    P0             217W / 250W |  16022MiB / 16384MiB |     99%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A     37726      C   python                                    10930MiB |
|    0   N/A  N/A     39923      C   /opt/tabby/bin/tabby                       5090MiB |
+---------------------------------------------------------------------------------------+

7.FAQ

7.1. Question 1

Git clone failed for Inference Engine: failed to resolve address for github.com: Name or service not known
ImportError: cannot import name 'load_additional_models' from 'comfy.sample' (/home/atanu/Workspace/project-diffusers/Fooocus/repositories/ComfyUI-from-StabilityAI-Official/comfy/sample.py)

Solution: The network is blocked, access to github fails, and clone fails. You can solve the problem by configuring the network connection proxy, or download it manually.

GitHub - comfyanonymous/ComfyUI: A powerful and modular stable diffusion GUI with a graph/nodes interface.

And rename ComfyUI to ComfyUI-from-StabilityAI-Official, and store it in /home/xxx/Fooocus/repositories/

Comment git_clone in launch.py

    comfyui_name = 'ComfyUI-from-StabilityAI-Official'
    
    # git_clone(comfy_repo, repo_dir(comfyui_name), "Inference Engine", comfy_commit_hash)

    sys.path.append(os.path.join(script_path, dir_repos, comfyui_name))

7.2. Question 2

ValueError: When localhost is not accessible, a shareable link must be created. Please set share=True.

Accessing Fooocus on the browser is successful, but when clicking generate/advance an error is reported Expecting value: line 1 column 1 (char 0) 

Solution: Add environment variable no_proxy

export no_proxy=localhost,127.0.0.1

7.3. Question 3

When the browser opens Fooocus, it keeps showing that it is loading, and the interface for normal input generation buttons does not appear for a long time or does not appear.

It is recommended to check the proxy, add the local IP to the whitelist set by the browser or computer, and enable other proxies for accessing external network addresses normally.

7.4. Question 4

If new dependency library problems arise after git pulling the project, such as torch, xformers, etc. mismatch and cuda cannot be called.

Open ~/Fooocus/launch.py ​​and modify the reinstall switch

REINSTALL_ALL = True

7.5. More questions

https://github.com/lllyasviel/Fooocus/issues

Guess you like

Origin blog.csdn.net/holyvslin/article/details/132870771