【深度学习】Stable Diffusion AI 绘画项目搭建详解,并运行案例
文章目录
- 前言
- 1.安装环境
- 1.1 基础环境
- 1.2 权重文件
- 2.牛刀小试
- 2.1 用法在这里
- 3.封装api
- 总结
前言
先把人家的git放过来:https://github.com/CompVis/stable-diffusion
40.7k 的stars, flask 和 django 两个web框架也不过如此数量级吧。
就是给一段文字,它能按照文字描述给你画画。画出来的还挺好看,是一个text-to-image diffusion model
是基于transformer 和多模态的一个产品。
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的支持我们能基于数据集LAION-5B database训练出一个512x512图像的潜在扩散模型。和 Google的画像类似,我们这个模型用了fronzen的CLIP vv - l /14文本编码器来根据文本提示调整模型,由于60M UNet 和 123M text encoder,这个模型是轻量级别的,并且可以跑在最低10GB显存的GPU上,[妈的,这还是轻量级的],
1.安装环境
1.1 基础环境
- 没有环境新建环境
A suitable conda environment named ldm can be created and activated with:
conda env create -f environment.yaml
conda activate ldm
- 存在环境后的更新环境
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网络连不到git上。
我的解决方案:
pip install taming-transformerspip install clip# 最后pip install -e .
1.2 权重文件
权重文件在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]
深度学习一半时间在鼓捣环境啊
出来了
全套代码在这里
import torch
from diffusers import StableDiffusionPipelinemodel_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
待续
总结
好玩是挺好玩,但是就拉个git没学到东西啊,算法工程师真的就是git拉个项目么。。。。呜呜呜
唯一遇到的问题是可能服务器上安装不上因为
你连上git
【深度学习】Stable Diffusion AI 绘画项目搭建详解,并运行案例相关推荐
- stable diffusion AI绘画作品展
https://wanziqianhong.art stable diffusion AI绘画作品展 更多图片请访问,万紫千红,https://wanziqianhong.art
- Stable Diffusion AI 绘画入门指南
Stable Diffusion AI 绘画入门指南 市面上用的最多的AI绘画工具是 Stable-Diffusion(SD) 和 Midjourney(Mid),SD是在本地运行的服务,开源,门槛高 ...
- 【深度学习系列】卷积神经网络CNN原理详解(一)——基本原理(1)
上篇文章我们给出了用paddlepaddle来做手写数字识别的示例,并对网络结构进行到了调整,提高了识别的精度.有的同学表示不是很理解原理,为什么传统的机器学习算法,简单的神经网络(如多层感知机)都可 ...
- 【Stable Diffusion | AI 绘画】手把手教你体验--AI 生成唯美二次元
应用背景 AI 绘画是一种应用人工智能技术来生成数字艺术作品的创作方法.这个领域的发展让艺术家和设计师能够更加轻松地使用技术来实现创意和想象.AI绘画是数字艺术领域的一种热门话题,因为它可以让我们了解 ...
- 我愿称之为史上最全的深度学习面经总结(附答案详解)
作者丨马东什么@知乎(已授权) 来源丨https://zhuanlan.zhihu.com/p/391954665 编辑丨极市平台 最近参加社招,面试基本是问项目,然后问项目里的算法所以这里还是按照实 ...
- 【深度学习】卷积神经网络(CNN)详解
章节 Filter 池化 Demo 冷知识 参考 CNN 一共分为输入,卷积,池化,拉直,softmax,输出 卷积由互关运算(用Filter完成)和激活函数 Filter CNN常用于图像识别,在深 ...
- 史上最全的深度学习面经总结(附答案详解)
以下文章来源于:马东什么@知乎 作者:马东什么 原文链接:https://zhuanlan.zhihu.com/p/391954665 本文仅用于学术分享,如有侵权,请联系后台作删文处理 导读 本文很 ...
- 汇总 | 深度学习中图像语义分割基准数据集详解
点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 汇总图像语义分割那些质量最好的数据集与常用benchmark数据集 ...
- python卷积神经网络cnn的训练算法_【深度学习系列】卷积神经网络CNN原理详解(一)——基本原理...
上篇文章我们给出了用paddlepaddle来做手写数字识别的示例,并对网络结构进行到了调整,提高了识别的精度.有的同学表示不是很理解原理,为什么传统的机器学习算法,简单的神经网络(如多层感知机)都可 ...
- 基于OpenCL的深度学习工具:AMD MLP及其使用详解
from:http://www.csdn.net/article/2015-08-05/2825390 [编者按]深度学习是近年来迅速发展和突破的机器学习领域,具有非常广泛的应用前景.将服务器GPU应 ...
最新文章
- 怎样在SecureCRT的shell里用命令上传下载文件(转)
- win32应用程序_电脑打不开exe程序|Win10提示exe不是有效32应用程序
- OpenCV加载Caffe框架模型
- JavaScript和ABAP的MD5计算源代码
- 使用 C# 实现 URL 安全的 Base62 转码
- containerd与安全沙箱的Kubernetes初体验
- 如何解决SVN 清理失败
- Server's Revolution
- string 释放_由String,String Builder,String Buffer 引起的面试惨案
- thymeleaf 使用页面报错_SpringBoot 使用thymeleaf 跳转页面时,总是提示404找不到页面...
- dedemonkey下载_android压力测试命令monkey详解
- 激光slam_激光SLAM与视觉SLAM,移动机器人核心技术不断升级
- SpringBoot配置参数绑定@ConfigurationProperties@Value
- lopatkin俄大神最新精简中文系统Windows 7 Professional VL SP1 7601.24496 x86-x64 ZH-CN DREY
- [论文总结] 深度学习在农业领域应用论文笔记9
- kindeditor php 上传错误,kindeditor 上传图片失败,该怎么解决
- Ribbon界面开发(C++)
- Ardunio开发实例-TEMT6000环境光传感器
- 2021-2027全球与中国射频屏蔽窗市场现状及未来发展趋势
- Easy Excel 使用总结
热门文章
- 基于JWT实现用户身份认证
- Android™ 2.1 android.R.drawable Icon Resources
- REST软件架构风格
- 硅谷洞察发布《2019美国医疗信息化产业分析及趋势报告》
- Greenspan vs. the Greenspan Doctrine
- 实体识别,你100%要遇到的知识建模的问题
- 华为认证知识点之IPV6
- 2023最新ZHEYI自动采集壁纸系统网站源码 360壁纸官方数据接口采集
- Java多线程:多人过山洞
- Unix/Unix Shell -- sh, ksh, csh