AIGC-stable-diffusion(文本生成图片)+PaddleHub/HuggingFace

功能
  1. stable-diffusion(文本生成图片)
  2. PaddleHub,HuggingFace两种调用方式
PaddleHub
环境
pip install paddlepaddle-gpu
pip install paddlehub
代码
from PIL import Image
import paddlehub as hub
module = hub.Module(name='stable_diffusion')

## 保存在demo目录
result = module.generate_image(text_prompts="clouds surround the mountains and Chinese palaces,sunshine,lake,overlook,overlook,unreal engine,light effect,Dream,Greg Rutkowski,James Gurney,artstation", output_dir='demo')
结果

HuggingFace
环境
pip install diffusers transformers accelerate scipy safetensors
代码
import torch
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

def show(image_path):
    # 使用 Matplotlib 加载图片文件
    image = mpimg.imread(image_path)

    # 显示图片
    plt.imshow(image)
    plt.axis('off')  # 关闭坐标轴
    plt.show()

model_id = "stabilityai/stable-diffusion-2-1"

# Use the DPMSolverMultistepScheduler (DPM-Solver++) scheduler here instead
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe = pipe.to("cuda")


prompt = "clouds surround the mountains and Chinese palaces,sunshine,lake,overlook,overlook,unreal engine,light effect,Dream,Greg Rutkowski,James Gurney,artstation"
image = pipe(prompt).images[0]
    
image.save("test.png")
show('test.png')


结果

相关推荐

  1. #07 使用Stable Diffusion生成高质量图片的技巧

    2024-04-25 07:18:02       9 阅读
  2. AIGC stable diffusion学习笔记

    2024-04-25 07:18:02       39 阅读

最近更新

  1. 根据关键词query获取google_img(api方式)

    2024-04-25 07:18:02       0 阅读
  2. redis中的事务和mysql中的事务有什么区别?

    2024-04-25 07:18:02       1 阅读
  3. C# 构造函数依赖注入 使用out向外传递参数

    2024-04-25 07:18:02       1 阅读
  4. 信息时代,呼唤新的哲学

    2024-04-25 07:18:02       1 阅读
  5. 【数据基础】— B树

    2024-04-25 07:18:02       1 阅读
  6. Vue 路由传参 query方法 bug 记录

    2024-04-25 07:18:02       1 阅读
  7. 翻页 上一页/下一页

    2024-04-25 07:18:02       1 阅读

热门阅读

  1. linux命令之printf

    2024-04-25 07:18:02       14 阅读
  2. TCP详解

    TCP详解

    2024-04-25 07:18:02      13 阅读
  3. 【Altium Designer-画板指南】

    2024-04-25 07:18:02       12 阅读
  4. 骑砍2霸主MOD开发(8)-action_sets.xml骨骼动画

    2024-04-25 07:18:02       15 阅读
  5. elment-table实现行滚动效果

    2024-04-25 07:18:02       14 阅读
  6. 平时学习得到的

    2024-04-25 07:18:02       19 阅读
  7. 开源协议与商业许可:选择与遵循

    2024-04-25 07:18:02       18 阅读
  8. RabbitMQ spring boot TTL延时消费

    2024-04-25 07:18:02       18 阅读