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


    功能
    1. stable-diffusion(文本生成图片)
    2. PaddleHub,HuggingFace两种调用方式
    PaddleHub
    环境
    1. pip install paddlepaddle-gpu
    2. pip install paddlehub
    代码
    1. from PIL import Image
    2. import paddlehub as hub
    3. module = hub.Module(name='stable_diffusion')
    4. ## 保存在demo目录
    5. 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
    代码
    1. import torch
    2. from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
    3. import matplotlib.pyplot as plt
    4. import matplotlib.image as mpimg
    5. def show(image_path):
    6. # 使用 Matplotlib 加载图片文件
    7. image = mpimg.imread(image_path)
    8. # 显示图片
    9. plt.imshow(image)
    10. plt.axis('off') # 关闭坐标轴
    11. plt.show()
    12. model_id = "stabilityai/stable-diffusion-2-1"
    13. # Use the DPMSolverMultistepScheduler (DPM-Solver++) scheduler here instead
    14. pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
    15. pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
    16. pipe = pipe.to("cuda")
    17. prompt = "clouds surround the mountains and Chinese palaces,sunshine,lake,overlook,overlook,unreal engine,light effect,Dream,Greg Rutkowski,James Gurney,artstation"
    18. image = pipe(prompt).images[0]
    19. image.save("test.png")
    20. show('test.png')
    结果

  • 相关阅读:
    ClickHouse(18)ClickHouse集成ODBC表引擎详细解析
    Rocky9 上安装 redis-dump 和redis-load 命令
    4.6shell中的运算
    电脑重装系统提示activex部件不能创建对象如何解决
    C语言典型例题31
    浅析如何在抖音快速通过新手期并积累粉丝
    学习MySQL的第六天:事务(基础篇)
    FX5800计算器测量程序集2.4
    1、pinpoint-简介
    区块链的认识
  • 原文地址:https://blog.csdn.net/u010379996/article/details/138145905