教你文本生成图片——stablediffusion

news/2024/7/10 20:13:04 标签: stable diffusion, 人工智能, ai
aidu_pl">

今天来点轻松的话题,带大家玩一个用文字生成图片的模型。

相信大家如果关注AIGC领域,对文本生成图片,对Stablefiffusion、DEALL.E应该不陌生。今天给大家介绍的就是基于SD2 finetune出来的一个模型()

这篇文章不会教大家STABLEDiffusion的原理,也不会去介绍文本生成图的历史,甚至不会让大家知道CLIP。只会带大家想工程师一样用很少的代码批量的产出你想要的图片。为你的软文配图。

ainer" style="display:flex;">

先来看几张效果

安装环境

pip install --upgrade diffusers accelerate transformers
ainer" style="display:flex;">

开始文本生成图

from diffusers import StableDiffusionPipeline
import torch

model_id = "dreamlike-art/dreamlike-photoreal-2.0"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe = pipe.to("cuda")

prompt = "3d render, an  soft and smooth appearance cute ant doll stands in the middle, full of sense with blue and white of technology with glow, bright cinematic lighting, gopro, fisheye lens"
image = pipe(prompt).images[0]

image.save("./result.jpg")
'''
#批量prompt生成图片
num = 0
prompt_list = ['a ctue **','...','....']
for prompt in prompt_list:
    image = pipe(prompt).images[0]
    save_file_name = "result{0}.jpg".format(str(num)
    image.save("./result.jpg")
    num+=1
'''
ainer" style="display:flex;">

优化promp让图更好看

Start by selecting the medium you want to use for your art, such as photo, digital art, 3d render, painting, etc.
1.开始部分选择你要生成的图片艺术风格,比如:照片、数字艺术、3d渲染、优化等等

Next, describe what you want to generate. For better results be specific and use descriptive language. For example, instead of saying "a castle" you could say "a medieval castle on a cliff, storm clouds, restless ocean".
2.接着你要描述你要生成的具体物品,为了得到更好效果最好用描述性形容性词汇,例如,与其说“一座城堡”,不如说“悬崖上的中世纪城堡、暴风云、动荡的海洋”

To make your prompt even more specific, you can add modifiers such as "dark cinematic lighting" or "highly detailed, intricate, bokeh". This will help the AI generate art that is more in line with your vision.
3.为了让你的提示更加具体,你可以添加修饰符,例如“暗色系光照”或“细节很详细、复杂、散景”。这将帮助 AI 生成更符合你意愿的作品。

If you have any particular artists in mind, you can add their names to your prompt. Some popular artists include Greg Rutkowski, Artgerm, Alphonse Mucha, and Zdzislaw Beksinski. Check out these links for a list of supported artists and some examples of their art:
4.如果你有特定的艺术家或艺术手法你可以加上去,这样生成图片会更符合你要求

3d render, an soft and smooth appearance cute ant doll stands in the middle, full of sense with blue and white of technology with glow, bright cinematic lighting, gopro, fisheye lens, 4k hd wallpaper, conceptart

ainer" style="display:flex;">

3d render, an cute ant doll with blue and white of technology glow ,soft and smooth appearance stands in the middle, bright cinematic lighting, gopro, romatic, 4k hd wallpaper, conceptart

ainer" style="display:flex;">

3d render, an cute ant doll with blue and white of technology glow ,soft and smooth appearance stands in the middle, bright cinematic lighting, gopro, romatic, 4k hd wallpaper, bright illustration,cuteart

ainer" style="display:flex;">

3d render, an soft and smooth appearance cute ant doll stands in the middle, full of sense with blue and white of technology with glow, bright cinematic lighting, gopro, fisheye lens, canon eos r 6, bifurcated lens, 4 k hd wallpaper, trending on artstation

ainer" style="display:flex;">

小结

今天就带大家用代码方式批量做图片生成。

大家一定发现这东西拿到只能生成某个物体吗,能不能生成一些背景。

有没办法让生成的物体不变,在增加一些元素会改变一些图片内容。

现在生成的方式太随机了,同一句prompt生成的图片都会出现差异,有没办法解决

还有就是有没可能批量生成风格稳定的图

有没办法自动的生成prompt生成高质量的图片

大家先别急下面几篇文章会一一给你解答。


http://www.niftyadmin.cn/n/63493.html

相关文章

软件测试 -- 高阶 2 软件测试与软件开发

辅车相依,唇亡齿寒。-- 《左传僖公五年》 释译:颊骨和齿床互相依靠,嘴唇没有了,牙齿就会感到寒冷。比喻利害密要相关,命运紧密相关联。-- 百度百科 测试与开发是什么关系? 1. 软件开发流程 2. 开发和测…

在 Centos 上在线安装 GitLab

作为程序员,其中一个愿望是拥有一个自己的代码存储库。在支持私有部署的代码存储库产品中,GitLab 是比较著名的了,所以今天我总结了一下在 Centos 上安装 GitLab 的过程。 依赖 基础依赖 首先,需要安装部分基础的依赖&#xff…

Spring Boot 日志

目录 1.概述 2.切换日志实现 3.使用 3.1.日志级别 3.3.日志离线 3.4.详细定制 1.概述 由一些历史原因,JAVA领域存在有很多日志框架,如Log4j、Logback、log4j2。 log4j是Java日志框架的元老,在log4j被Apache Foundation收入门下之后&a…

【蓝桥杯集训1】前缀和专题(2 / 5)

目录 前缀和模板 !3956. 截断数组 - 前缀和枚举 前缀和模板 活动 - AcWing import java.util.*;class Main {static int N100010;static int[] anew int[N],snew int[N];public static void main(String[] args){Scanner scnew Scanner(System.in);int nsc.nex…

ES6新增特性总结

目录 let和const命令 模板字符串 扩展运算符 解构赋值 对象解构 数组解构 扩展的函数 带参数默认值的函数 剩余参数表示不定参 箭头函数 扩展的对象 直接写入变量和函数,作为对象的属性和方法 新增Object.is()/Object.assign()/Object.keys/Object.val…

4个月的测试经验,来面试就开口要17K,面试完,我连5K都不想给他.....

2021年8月份我入职了深圳某家创业公司,刚入职还是很兴奋的,到公司一看我傻了,公司除了我一个测试,公司的开发人员就只有3个前端2个后端还有2个UI,在粗略了解公司的业务后才发现是一个从零开始的项目,目前啥…

使用burpsuite抓包 + sql工具注入 dvwa靶场

使用burpsuite抓包 sql工具注入 dvwa靶场 记录一下自己重新开始学习web安全之路②。 一、准备工作 1.工具准备 sqlmap burpsuite 2.浏览器准备 火狐浏览器 设置代理。 首先,先设置一下火狐浏览器的代理 http代理地址为127.0.0.0.1 ,端口为8080 …

MySQL数据库13——插入数据(INSERT)

下面的语句用于向student表插入数据。 插入语句: INSERT INTO student(ID,name,sex,birthday,origin,contact1,contact2,institute) VALUES (0013,塔赛努,男,1997/9/15,内蒙古自治区,NULL,NULL,计算机学院);INSERT INTO student VALUES (0014,呼和嘎拉,男,1995-02…