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

功能
  1. stable-diffusion(文本生成图片)
  2. PaddleHub,HuggingFace两种调用方式
PaddleHub
环境
bash 复制代码
pip install paddlepaddle-gpu
pip install paddlehub
代码
bash 复制代码
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
环境
bash 复制代码
pip install diffusers transformers accelerate scipy safetensors
代码
bash 复制代码
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')
结果
相关推荐
kakaZhui8 小时前
【llm对话系统】大模型源码分析之 LLaMA 位置编码 RoPE
人工智能·深度学习·chatgpt·aigc·llama
GISer_Jing13 小时前
AIGC时代的Vue或React前端开发
vue.js·react.js·aigc
kakaZhui16 小时前
【llm对话系统】大模型 Llama 源码分析之 LoRA 微调
pytorch·深度学习·chatgpt·aigc·llama
qq_417719981 天前
DIFY源码解析
人工智能·aigc·源码·注释·dify
kakaZhui1 天前
【llm对话系统】大模型 Llama 源码分析之 Flash Attention
人工智能·chatgpt·aigc·llama
kakaZhui1 天前
【llm对话系统】大模型 Llama 源码分析之并行训练方案
人工智能·chatgpt·aigc·llama
爱研究的小牛2 天前
Deepseek技术浅析(二):大语言模型
人工智能·机器学习·语言模型·自然语言处理·aigc
TGITCIC2 天前
DeepSeek r1本地安装全指南
人工智能·ai·aigc·ollama·deep seek·开源ai·本地安装大模型