Build an artificial intelligence AI drawing environment on MacAir

Build an artificial intelligence AI drawing environment on MacAir

On MacAir, you can build an AI drawing environment by yourself through the open source Stable Diffusion project. Here we take Mac Air with Intel processor as an example.

The Stable Diffusion project has high hardware requirements and only provides terminal command line interaction, so the stable-diffusion-webui project (webui for short) is used here to implement local deployment. The webui project provides the interactive mode of web pages for the Stable Diffusion project, and the operation is easier.

Environment deployment

After the git environment is deployed on this machine, the webui script can be run directly under normal circumstances, and executed in the terminal:

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui
./webui.sh

Some files will be downloaded during the execution, if there is an error in the middle, just execute webui.sh again.

If you are prompted that the opencv version is too old, you can manually update it like this:

# ImportError: dlopen(/github/stable-diffusion-webui/venv/lib/python3.10/site-packages/cv2/cv2.abi3.so, 2): Symbol not found: _VTRegisterSupplementalVideoDecoderIfAvailable
cd venv/bin
source activate
./python3.10 -m pip install --upgrade pip
pip3 install opencv-python==4.6.0.66
deactivate

If it prompts a graphics card problem, you can deal with it like this:

# RuntimeError: "LayerNormKernelImpl" not implemented for 'Half'
cd venv/bin
source activate
pip install torch --extra-index-url https://download.pytorch.org/whl/cu113
deactivate

EDIT webui-user.sh, adding:

export COMMANDLINE_ARGS="--precision full --no-half --skip-torch-cuda-test

If it runs successfully, you will see a prompt similar to this:

LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Applying cross attention optimization (InvokeAI).
Textual inversion embeddings loaded(0):
Model loaded in 31.0s (load weights from disk: 0.7s, create model: 1.1s, apply weights to model: 28.5s, apply dtype to VAE: 0.2s, load textual inversion embeddings: 0.3s).
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`

At this point, just open the browser and visit the corresponding address http://127.0.0.1:7860to use it.

Model download

The webui does not have a model file by default. You need to download it yourself and put it in the corresponding directory. The model file can be downloaded from the following two websites:

  • https://huggingface.co/
  • https://civitai.com/

Depending on the type of model, it is placed in a different directory:

  • Main model file, placed in: stable-diffusion-webui/models/Stable-diffusion
  • Lora file, placed in: stable-diffusion-webui/models/Lora
  • VAE file, placed in: stable-diffusion-webui/models/VAE

There is also a type of Lora file with the same name as the main model, which needs to be placed in the Stable-diffusion directory.

After the model is downloaded, refresh the browser page, and you can see the model file. Switching model files requires reloading, please be patient.

If the prompt cannot be written, you can refer to the wording of the prompt on the model page.

tidbits

For Stable Diffusion, we interviewed chatGPT:

你知道开源项目Stable Diffusion吗?

很抱歉,作为一个语言模型AI,我无法知道所有的开源项目。Stable Diffusion似乎不是一个很有名的开源项目,我无法提供更多的信息。如果您愿意提供更多背景信息,我会尽力回答。

chatGPT this is on purpose...

Stable Diffusion is a latent text-to-image diffusion model capable of generating photorealistic images given any text input, cultivating autonomous degrees of freedom to produce incredible images, enabling billions of Humans create amazing art in seconds.

To put it simply, it is the AI ​​drawing tool that everyone often says, which can realize functions such as converting text descriptions to pictures, or converting pictures to pictures.

The first round of AI drawing is popular, and it is the DALL-E product released by openAI in 2021. It can understand natural language input and generate pictures based on text descriptions. The following year, in an art competition in the United States, an artist named Jason Allen (Jason Allen) won the first place with the work created by the AI ​​​​tool Midjourney:

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-xi2TaA3Q-1678075166617)(1.png)]
insert image description here

In the same year, the CompVis group at the University of Munich released Stable Diffusion, a deep learning, text-to-image model for generating detailed images conditioned on text descriptions.

At present, many domestic websites that provide text drawing should use the functions realized by the open source project Stable Diffusion.

Guess you like

Origin blog.csdn.net/ffb/article/details/129359025