前言
先把人家的git放過來:https://github.com/CompVis/stable-diffusion
40.7k 的stars, flask 和 django 兩個web框架也不過如此數(shù)量級吧。
就是給一段文字,它能按照文字描述給你畫畫。畫出來的還挺好看,是一個text-to-image diffusion model
是基于transformer 和多模態(tài)的一個產(chǎn)品。
Stable Diffusion is a latent text-to-image diffusion model. Thanks to a generous compute donation from Stability AI and support from LAION, we were able to train a Latent Diffusion Model on 512x512 images from a subset of the LAION-5B database. Similar to Google’s Imagen, this model uses a frozen CLIP ViT-L/14 text encoder to condition the model on text prompts. With its 860M UNet and 123M text encoder, the model is relatively lightweight and runs on a GPU with at least 10GB VRAM.
這一段是我從git上copy下來的,翻譯:
Stable Diffusion 是文本到圖像的擴散模型,多虧了來自Stability AI和 LAION的支持我們能基于數(shù)據(jù)集LAION-5B database訓(xùn)練出一個512x512圖像的潛在擴散模型。和 Google的畫像類似,我們這個模型用了fronzen的CLIP vv - l /14文本編碼器來根據(jù)文本提示調(diào)整模型,由于60M UNet 和 123M text encoder,這個模型是輕量級別的,并且可以跑在最低10GB顯存的GPU上,[媽的,這還是輕量級的],
1.安裝環(huán)境
1.1 基礎(chǔ)環(huán)境
- 沒有環(huán)境新建環(huán)境
A suitable conda environment named ldm can be created and activated with:
conda env create -f environment.yaml
conda activate ldm
- 存在環(huán)境后的更新環(huán)境
You can also update an existing latent diffusion environment by running
conda install pytorch torchvision -c pytorch
pip install transformers==4.19.2 diffusers invisible-watermark
pip install -e .
可能遇到的問題:
ERROR: Command errored out with exit status 128: git clone -q https://github.com/openai/CLIP.git /home/jianming_ge/workplace/stable-diffusion-main/src/clip Check the logs for full command output.
原因在這里,是因為server網(wǎng)絡(luò)連不到git上。
我的解決方案:
pip install taming-transformers
pip install clip
# 最后
pip install -e .
1.2 權(quán)重文件
權(quán)重文件在git的這里。
我選的是stable-diffusion-v1-4,
https://huggingface.co/CompVis/stable-diffusion-v1-4
2.牛刀小試
2.1 用法在這里
漫長的下載過程
(py39_torch1.10.1) [jianming_ge@localhost workplace]$ /home/jianming_ge/miniconda3/envs/py39_torch1.10.1/bin/python /home/jianming_ge/workplace/ldm.py
Downloading (…)ain/model_index.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 543/543 [00:00<00:00, 86.8kB/s]
Downloading (…)rocessor_config.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 342/342 [00:00<00:00, 85.7kB/s]
Downloading (…)_checker/config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 4.56k/4.56k [00:00<00:00, 916kB/s]
Downloading (…)_encoder/config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 592/592 [00:00<00:00, 160kB/s]
Downloading (…)cheduler_config.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 313/313 [00:00<00:00, 62.5kB/s]
Downloading (…)nfig-checkpoint.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 209/209 [00:00<00:00, 43.9kB/s]
Downloading (…)okenizer_config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 806/806 [00:00<00:00, 186kB/s]
Downloading (…)3d4/unet/config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 743/743 [00:00<00:00, 318kB/s]
Downloading (…)cial_tokens_map.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 472/472 [00:00<00:00, 101kB/s]
Downloading (…)nfig-checkpoint.json: 0%| | 0.00/209 [00:00<?, ?B/s/home/jianming_ge/miniconda3/envs/ldm/bin/python /home/jianming_ge/workplace/ldm.py | 0.00/806 [00:00<?, ?B/s]
Downloading (…)23d4/vae/config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 522/522 [00:00<00:00, 176kB/s]
Downloading (…)tokenizer/merges.txt: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████| 525k/525k [00:16<00:00, 31.7kB/s]
Downloading (…)tokenizer/vocab.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 1.06M/1.06M [00:30<00:00, 34.8kB/s]
Downloading (…)"pytorch_model.bin";: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████| 492M/492M [06:19<00:00, 1.30MB/s]
Downloading (…)_pytorch_model.bin";: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████| 335M/335M [11:17<00:00, 494kB/s]
Downloading (…)"pytorch_model.bin";: 3%|███▌ | 41.9M/1.22G [00:26<13:22, 1.46MB/s]
Downloading (…)"pytorch_model.bin";: 26%|██████████████████████████▉ | 315M/1.22G [06:06<23:42, 634kB/s]
Downloading (…)"pytorch_model.bin";: 47%|█████████████████████████████████████████████████▎ | 577M/1.22G [11:12<14:50, 718kB/s]
Downloading (…)"pytorch_model.bin";: 89%|██████████████████████████████████████████████████████████████████████████████████████████▌ | 1.08G/1.22G [16:20<01:12, 1.88MB/s]
Downloading (…)_pytorch_model.bin";: 38%|██████████████████████████████████████▌ | 1.30G/3.44G [16:14<21:55, 1.63MB/s]
Downloading (…)_pytorch_model.bin";: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████| 335M/335M [11:17<00:00, 458kB/s]
深度學(xué)習(xí)一半時間在鼓搗環(huán)境啊
出來了
全套代碼在這里
import torch
from diffusers import StableDiffusionPipeline
model_id = "CompVis/stable-diffusion-v1-4"
device = "cuda"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe = pipe.to(device)
prompt = "a photo of an astronaut riding a horse on mars"
image = pipe(prompt).images[0]
image.save("astronaut_rides_horse.png")
命令行下10幾秒鐘一張
模型提示輸入這個會快一些:
pip install accelerate
3.封裝api
待續(xù)文章來源:http://www.zghlxwxcb.cn/news/detail-790920.html
總結(jié)
好玩是挺好玩,但是就拉個git沒學(xué)到東西啊,算法工程師真的就是git拉個項目么。。。。嗚嗚嗚
唯一遇到的問題是可能服務(wù)器上安裝不上因為
你連上git文章來源地址http://www.zghlxwxcb.cn/news/detail-790920.html
到了這里,關(guān)于【深度學(xué)習(xí)】Stable Diffusion AI 繪畫項目搭建詳解,并運行案例的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!