最近大火的Stable Diffusion也开源了(20220823);

我也本地化测试了一下效果确实比Dall-E mini强太多了,对于我们这些玩不上Dall-E2的这个简直就是就是捡钱的感觉,当然后期跑起来,稍微不注意显存就炸了。

这里我写一下安装过程,具体分为两个安装流程;

流程1 -- Hubggingface的方式安装

使用Huggingface的模式进行直接安装。

CompVis/stable-diffusion-v1-1 · Hugging Face​huggingface.co/CompVis/stable-diffusion-v1-1正在上传…重新上传取消

注册

第一个工作需要注册账户,可以关联github;

注册后在个人目录下有一个token号;链接https://huggingface.co/settings/tokens,这个tokens号要在服务器登陆的过程中进行添加;

在服务器登陆要输入huggingface登陆:

huggingface-cli login

登陆界面,输入token就可以分析;

之后才可以再安装;

相关包安装

安装配置的包命令:

pip install --upgrade diffusers transformers scipy

安装过程时间会很长[最好修改镜像路径],一般不会出什么问题。

运行模式

然后直接运行下面的code就可以绘制图出来,第一次计算会下载模型权重,速度很长。国内网络很慢,建议选择其他网络方法,或者早起(早晨速度特别快)。

import torch
from torch import autocast
from diffusers import StableDiffusionPipelinemodel_id = "CompVis/stable-diffusion-v1-1"
device = "cuda"pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True)
pipe = pipe.to(device)prompt = "a photo of an astronaut riding a horse on mars"
with autocast("cuda"):image = pipe(prompt, guidance_scale=7.5)["sample"][0]  image.save("astronaut_rides_horse.png")

可以调节其他参数,但这个流程具体我没有更多测试。

prompt = "Little Red Riding Hood and big grey wolf, digital painting, artstation, concept art, smooth, sharp focus, illustration, renaissance, flowy, melting, round moons, rich clouds, very detailed, volumetric light, mist, fine art, textured oil over canvas, epic fantasy art, very colorful, ornate intricate scales, fractal gems, 8 k, hyper realistic, high contrast"
prompt = "fantasy magic fashion Asian girl portrait, glossy eyes, face, long hair, fantasy, intricate, elegant, highly detailed, digital painting, artstation, concept art, smooth, sharp focus, illustration, renaissance, flowy, melting, round moons, rich clouds, very detailed, volumetric light, mist, fine art, textured oil over canvas, epic fantasy art, very colorful, ornate intricate scales, fractal gems, 8 k, hyper realistic, high contrast"
prompt = "All roads lead to Rome,  8 k, hyper realistic, high contrast, elegant, highly detailed, digital painting, artstation, concept art, smooth, sharp focus, illustration"
prompt = "Tomorrow is another day,  8 k, hyper realistic, high contrast, elegant, highly detailed, digital painting, artstation, concept art, smooth, sharp focus, illustration"

我测试的三组,效果如下:

流程2 -- 使用github进行分布部署

这种模式使用自己下载模型,运行时候使用参数会更好的结果。

通过下载GitHub下载原始代码,路径:

GitHub - CompVis/stable-diffusion​github.com/CompVis/stable-diffusion正在上传…重新上传取消

只用git clone 或者直接download的保存都可以,访问这个目录进行安装。

相关包安装

安装使用conda方式做的:GitHub - CompVis/stable-diffusion安装使用conda方式做的:

conda env create -f environment.yaml
conda activate ldm

但我安装过程因为git clone之后报错,因为各种原因吧。

我是直接本地download下来,然后直接

python setup.py install

具体包括的安装包有CLIP[openai/CLIP]和taming-transformers[CompVis/taming-transformers];这里说一下taming-transformers安装后依然找不到相关代码, 我直接把[taming]目录代码copy根目录下,这样直接import没有问题了。

一些相关包的安装:

conda install pytorch torchvision -c pytorch
pip install transformers==4.19.2 diffusers invisible-watermark
pip install -e .

这部分安装包括stable-diffusion的目录;

模型文件下载

访问网站[Hugging Face – The AI community building the future.]:

在Files and versions下载就可以,选择对应的sd-v1-4.ckpt下载,如图:

直接点后面的下载符号就可以下载,之后运行的时候只要链接到模型路径就可以计算。

运行模式1 - 文本转图像:

第一次运行还会安装、和配置很多模型,需要时间很多。

还是建议早起。

全部模型参数如下:

usage: txt2img.py [-h] [--prompt [PROMPT]] [--outdir [OUTDIR]] [--skip_grid] [--skip_save] [--ddim_steps DDIM_STEPS] [--plms] [--laion400m] [--fixed_code] [--ddim_eta DDIM_ETA][--n_iter N_ITER] [--H H] [--W W] [--C C] [--f F] [--n_samples N_SAMPLES] [--n_rows N_ROWS] [--scale SCALE] [--from-file FROM_FILE] [--config CONFIG] [--ckpt CKPT][--seed SEED] [--precision {full,autocast}]optional arguments:-h, --help            show this help message and exit--prompt [PROMPT]     the prompt to render--outdir [OUTDIR]     dir to write results to--skip_grid           do not save a grid, only individual samples. Helpful when evaluating lots of samples--skip_save           do not save individual samples. For speed measurements.--ddim_steps DDIM_STEPSnumber of ddim sampling steps--plms                use plms sampling--laion400m           uses the LAION400M model--fixed_code          if enabled, uses the same starting code across samples--ddim_eta DDIM_ETA   ddim eta (eta=0.0 corresponds to deterministic sampling--n_iter N_ITER       sample this often--H H                 image height, in pixel space--W W                 image width, in pixel space--C C                 latent channels--f F                 downsampling factor--n_samples N_SAMPLEShow many samples to produce for each given prompt. A.k.a. batch size--n_rows N_ROWS       rows in the grid (default: n_samples)--scale SCALE         unconditional guidance scale: eps = eps(x, empty) + scale * (eps(x, cond) - eps(x, empty))--from-file FROM_FILEif specified, load prompts from this file--config CONFIG       path to config which constructs model--ckpt CKPT           path to checkpoint of model--seed SEED           the seed (for reproducible sampling)--precision {full,autocast}evaluate at this precision

其中主要的参数(我使用的),

--prompt 关键词准备;

--plms 预测使用需要使用这个信息;

--W/--H 这里需要注意如果生成图太大,显存可能不足,建议一点一点试试;

--seed 种子数、相同prompt和seed会保证生成图像一致;

--ckpt 写模型的全路径,访问模型;

--outdir 图像生成路径,图绘按照ID顺着添加,目录下有一个文件夹路径会保留所有样本;

我测试的一个样例:

python txt2img.py --prompt "Asia girl, glossy eyes, face, long hair, fantasy, elegant, highly detailed, digital painting, artstation, concept art, smooth, illustration, renaissance, flowy, melting, round moons, rich clouds, very detailed, volumetric light, mist, fine art, textured oil over canvas, epic fantasy art, very colorful, ornate intricate scales, fractal gems, 8 k, hyper realistic, high contrast" --plms --outdir ./stable-diffusion-main/Workspace --ckpt ./stable-diffusion-main/models/ldm/sd-v1-4.ckpt --ddim_steps 100 --H 512 --W 512 --seed 8

输出结果:

运行模式2--图像+文本--图像

该部分就是通过一个随机图,给一些描述可以产出新的效果。我测试这部分。。。比较诡异;

如果有好的案例欢迎推荐给我,大家注意一下。

python scripts/img2img.py --prompt "magic fashion girl portrait, glossy eyes, face, long hair, fantasy, intricate, elegant, highly detailed, digital painting, artstation, concept art, smooth, sharp focus, illustration, renaissance, flowy, melting, round moons, rich clouds, very detailed, volumetric light, mist, fine art, textured oil over canvas, epic fantasy art, very colorful, ornate intricate scales, fractal gems, 8 k, hyper realistic, high contrast" --init-img ./stable-diffusion-main/Workspace2/h3.jpg --strength 0.8 --outdir ./stable-diffusion-main/Workspace --ckpt ./stable-diffusion-main/models/ldm/sd-v1-4.ckpt --ddim_steps 100

经过我测试还有很多人讨论的结果,输入图尽量保持长宽像素保持64的倍数,一般不会报错。

输入图像:

输出结果如下:

结果有点。。。不理解

但看小蓝鸟上还是很多不错的结果。

---未完待续---

参考链接:

[1] CompVis/stable-diffusion-v1-1[CompVis/stable-diffusion-v1-1 · Hugging Face];

[2]CompVis/stable-diffusion[https://github.com/CompVis/stable-diffusion]

模型方法--Stable Diffusion - 知乎

当下最强的 AI art 生成模型 Stable Diffusion 最全面介绍_创业者西乔的博客-CSDN博客

AI-多模态-文本->图像-2021:Stable Diffusion【开源】【目前开源模型中最强】相关推荐

  1. 本地生成动漫风格 AI 绘画 图像|Stable Diffusion WebUI 的安装和局域网部署教程

    Stable Diffusion WebUI 的安装和部署教程 1. 简介 2. 安装环境 2.1 Windows 2.2 Linux 3. 运行 4. 模型下载链接 5. 局域网部署 5.1 Win ...

  2. 在 Amazon SageMaker 上玩转 Stable Diffusion: 基于 Dreambooth 的模型微调

    本文将以 Stable Diffusion Quick Kit 为例,详细讲解如何利用 Dreambooth 对 Stable Diffusion 模型进行微调,包括基础的 Stable Diffus ...

  3. Stable Diffusion XL:更快,更强

    Stable Diffusion XL:更快,更强 今天,Stability AI 的创始人兼首席执行官 Emad Mostaque 发推宣布,Stable Diffusion XL 进入公测阶段. ...

  4. 【AI绘图】一、stable diffusion的发展史

    一.stable diffusion的发展史 本文目标:学习交流 对于熟悉SD的同学,一起学习和交流使用过程中的技巧和心得. 帮助新手 帮助没有尝试过SD但又对它感兴趣的同学快速入门,并且能够独立生成 ...

  5. 智源社区AI周刊No.102:Stable Diffusion背后公司再融1亿美元;体外人脑细胞五分钟学会打乒乓,登Neuron...

    汇聚每周AI观点.研究和各类资源,不错过真知灼见和重要资讯!欢迎扫码,关注并订阅智源社区AI周刊. 编辑精选 1. Stable Diffusion背后公司再融1亿美金:独辟蹊径,开源和社区驱动的AI ...

  6. AI创作之如何使用Stable Diffusion AI 将自己变成皮克斯动画角色 (教程含完整操作步骤)

    无论您想成为下一个伍迪.下一个巴斯光年,还是将您的鱼变成下一个尼莫,Stable Diffusion都能实现.使用这种潜在的文本到图像扩散模型,您只需一个简单的文本提示,就可以将自己变成任何皮克斯角色 ...

  7. AI 绘画基础 - 细数 Stable Diffusion 中的各种常用模型 【 魔导士装备图鉴】

    AI 绘画新手魔导士在刚开始玩 Stable Diffusion 时总会遇到各种新的概念,让人困惑,其中就包括各种模型和他们之间的关系. 魔法师入门得先认识各种法师装备(各种模型),让我们遇到问题知道 ...

  8. AI绘画:快速上手stable diffusion

    点击↑上方↑蓝色"编了个程"关注我~ 这是Yasin的第 89 篇原创文章 mj vs sd 最近随着Chat GPT的大火,AI绘画也火了起来.尤其是midjourney(以下简 ...

  9. AI生成二维码Stable diffusion生成可识别二维码【附完整教程】【附完整案例】

    前言 最近的炫酷QR比较火,所以今天给大家分享一下如何实现.首先我们知道QR二维码已经改变了信息的共享和获取方式.但是,QR码的视觉外观可能并不总是符合设计或艺术品的美学要求.为了解决这个问题,Con ...

最新文章

  1. POJ 2135 最小费用最大流
  2. Error:Connection timed out: connect
  3. Spring boot项目集成Sharding Jdbc
  4. vue 组件属性监听_详解vuex 中的 state 在组件中如何监听
  5. 解决Maven:Cannot resolve com.oracle.ojdbc:ojdbc6:11.2.0.1.0报红找不到问题,解决方案亲测有效详细图文教程 问题描述(ojdbc6)
  6. BIM学习笔记(一)
  7. JAVA多线程是什么
  8. 尚学堂浪曦视频学习推荐顺序
  9. FFmpeg 软编码h.264与H.265(从简到深)
  10. 线上编程学院codecademy
  11. 解决:Error during artifact deployment. See server log for details.问题
  12. 关于计算机的小故事英语作文,简单的英语小故事精选【六篇】
  13. 单片机学习笔记————51单片机实现两片联级74HC595驱动16个LED灯(把74HC595驱动程序翻译成类似单片机IO口直接驱动的方式)
  14. OpenGL - PBR
  15. Java版战棋(SLG)游戏AI及寻径处理入门
  16. 在OpenGL中实现Geometry Instancing
  17. Python手撸机器学习系列(十五):简单神经网络
  18. apicloud 不干胶标签打印模块及开发
  19. 《卸甲笔记》-多表查询之二
  20. 怎样删除具有trustedinstall权限的文件

热门文章

  1. iapp上传图片到云函数
  2. 今宵除夕夜,天涯共此时
  3. 论文笔记之Soft Q-learning
  4. 波卡动态 | Moonbeam 上第一个3D NFT项目宣布合作
  5. 计算机及处理器温度要求国标,【国家标准】GB 4967-1995电子计算器通用技术条件.pdf...
  6. 手把手写算法(学个语言)
  7. 发邮件窗体【支持编辑邮件模板,使用wse多线程上传附件及发邮件(带附件)】以及在服务器端自动发邮件...
  8. 那些不再追逐互联网的年轻人们,正遇见下一个「互联网」
  9. 尽己力,听天命。无愧于心,不惑于情
  10. ReactNative报错null is not an object (evaluating '_rngesturehandlermodule.default.direction')