当前位置: 代码网 > 科技>人工智能>智能机器人 > 媲美Midjourney-v6,Kolors最新文生图模型部署

媲美Midjourney-v6,Kolors最新文生图模型部署

2024年07月31日 智能机器人 我要评论
Kolors模型是由快手团队开发的一种文本到图像生成模型。Kolors模型基于Stable Diffusion框架,在海量中英文图文对数据集上进行了训练,特别在中文理解和还原方面表现出色。Kolors模型在图像生成质量、复杂提示词理解、字符文本内容渲染等方面都有优异表现,尤其擅长生成高质量、细节清晰的人像图片。此外,Kolors在人类评估中的表现超过了现有的开源模型,并在视觉吸引力方面达到了Midjourney-v6的水平。

kolors模型是由快手团队开发的大型文本到图像生成模型,专门用于将文本描述转换成高质量的图像。

kolors模型支持中英文双语输入,生成效果与midjourney-v6相媲美,能够处理长达256个字符的文本输入,具备生成中英文文字的能力。

kolors模型的技术优势在于其使用了基于u-net架构的隐空间扩散模型,并引入了大语言模型进行文本表征,这使得它在处理复杂长文本方面表现出色。

kolors模型在图像美感和质量上达到了国际领先水平,这得益于其两阶段的概念学习和美感提升的渐进训练策略以及针对高分辨率图像特性优化的全新加噪策略。

在评测方面,kolors模型在智源flageval文生图模型评测榜单中主观综合评分全球第二,尤其在主观图像质量上表现突出,评分排名第一。

github项目地址:https://github.com/kwai-kolors/kolors。

一、环境安装

1、python环境

建议安装python版本在3.8以上。

2、pip库安装

pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117

pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install pydantic==1.10.2 protobuf==3.20 tensorboard>=1.15.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

3、kolors模型下载

git lfs install

git clone https://huggingface.co/kwai-kolors/kolors.git

、功能测试

1、运行测试

(1)python调用测试

import torch
from kolors.pipelines.pipeline_stable_diffusion_xl_chatglm_256 import stablediffusionxlpipeline
from kolors.models.modeling_chatglm import chatglmmodel
from kolors.models.tokenization_chatglm import chatglmtokenizer
from diffusers import unet2dconditionmodel, autoencoderkl
from diffusers import eulerdiscretescheduler

# 定义模型权重路径
ckpt_dir = 'kolors'

def infer(prompt):
    # 加载文本编码器模型
    text_encoder = chatglmmodel.from_pretrained(
        f'{ckpt_dir}/text_encoder',
        torch_dtype=torch.float16
    ).half()
    
    # 加载分词器
    tokenizer = chatglmtokenizer.from_pretrained(f'{ckpt_dir}/text_encoder')
    
    # 加载图片解码器 vae
    vae = autoencoderkl.from_pretrained(f"{ckpt_dir}/vae", revision=none).half()
    
    # 加载调度器用于生成步骤
    scheduler = eulerdiscretescheduler.from_pretrained(f"{ckpt_dir}/scheduler")
    
    # 加载 u-net 模型
    unet = unet2dconditionmodel.from_pretrained(f"{ckpt_dir}/unet", revision=none).half()
    
    # 设置图像生成管道
    pipe = stablediffusionxlpipeline(
        vae=vae,
        text_encoder=text_encoder,
        tokenizer=tokenizer,
        unet=unet,
        scheduler=scheduler,
        force_zeros_for_empty_prompt=false
    )
    
    # 将管道模型移至 gpu
    pipe = pipe.to("cuda")
    
    # 启用模型 cpu 卸载功能
    pipe.enable_model_cpu_offload()
    
    # 生成图像
    image = pipe(
        prompt=prompt,
        height=1024,                # 图像高度
        width=1024,                 # 图像宽度
        num_inference_steps=50,     # 推理步数
        guidance_scale=5.0,         # 指导比例
        num_images_per_prompt=1,    # 每个提示生成的图像数量
        generator=torch.generator(pipe.device).manual_seed(66)  # 随机种子
    ).images[0]
    
    # 保存生成的图像
    output_path = 'scripts/outputs/sample_test.jpg'
    image.save(output_path)
    print(f"图像已保存至:{output_path}")

if __name__ == '__main__':
    # 定义生成图像的提示
    prompt = '一张瓢虫的照片,微距,变焦,高质量,电影,拿着一个牌子,写着"good"'
    infer(prompt)

(2)web端测试

未完......

更多详细的内容欢迎关注:杰哥新技术

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com