混合展示(Mix-of-Show)项目安装与配置指南

混合展示(Mix-of-Show)项目安装与配置指南

Mix-of-Show NeurIPS 2023, Mix-of-Show: Decentralized Low-Rank Adaptation for Multi-Concept Customization of Diffusion Models Mix-of-Show 项目地址: https://gitcode.com/gh_mirrors/mi/Mix-of-Show

1. 项目基础介绍

混合展示(Mix-of-Show)是一个开源项目,旨在通过去中心化的低秩适配技术对扩散模型进行多概念定制。该项目基于深度学习,可以实现对图像生成模型的多重概念融合,而不损失原有身份特征。主要编程语言为Python。

2. 项目使用的关键技术和框架

  • 扩散模型(Diffusion Models):一种生成模型,可以生成高质量、高分辨率的图片。
  • LoRA(Low-Rank Adaptation):一种微调技术,用于在少量样本上快速适应新概念。
  • XFormer:一种用于节省内存的优化技术。
  • Diffusers:用于处理扩散模型的库。

3. 项目安装和配置准备工作

在开始安装之前,请确保您的系统中已安装以下软件和依赖项:

  • Python 3.9 或更高版本:建议使用Anaconda或Miniconda进行环境管理。
  • Git:用于克隆和下载项目代码。

安装步骤

  1. 克隆项目仓库

    打开命令行工具,执行以下命令克隆项目:

    git clone https://github.com/TencentARC/Mix-of-Show.git
    cd Mix-of-Show
    
  2. 安装依赖项

    在项目根目录下,使用pip安装所需的Python依赖:

    pip install -r requirements.txt
    
  3. 准备预训练模型

    克隆预训练模型仓库:

    cd experiments/pretrained_models
    git-lfs clone https://huggingface.co/windwhinny/chilloutmix.git
    git-lfs clone https://huggingface.co/andite/anything-v4.0.git
    
  4. 数据准备

    根据项目说明,数据选择和标记对于单概念微调非常重要。请参照项目中的Dataset.md文件进行数据准备工作。处理好的数据可以从Google Drive下载。

  5. 配置文件修改

    在开始微调之前,需要修改配置文件,指定数据路径和调整超参数。配置文件位于datasets/data_cfgs/目录下。根据您要微调的概念,修改相应的JSON文件。

  6. 开始微调

    使用以下命令开始微调过程(假设您已根据指南修改了配置文件):

    accelerate launch train_edlora.py -opt options/train/EDLoRA/real/8101_EDLoRA_potter_Cmix_B4_Repeat500.yml
    
  7. 采样

    微调完成后,您可以下载训练好的模型并使用以下代码进行采样:

    import torch
    from diffusers import DPMSolverMultistepScheduler
    from mixofshow.pipelines.pipeline_edlora import EDLoRAPipeline, StableDiffusionPipeline
    from mixofshow.utils.convert_edlora_to_diffusers import convert_edlora
    
    # 加载预训练模型和调度器
    pretrained_model_path = 'experiments/pretrained_models/chilloutmix'
    lora_model_path = 'experiments/2002_EDLoRA_hermione_Cmix_B4_Iter1K/models/checkpoint-latest/edlora.pth'
    enable_edlora = True
    
    # 选择EDLoRAPipeline或StableDiffusionPipeline
    pipeclass = EDLoRAPipeline if enable_edlora else StableDiffusionPipeline
    pipe = pipeclass.from_pretrained(
        pretrained_model_path,
        scheduler=DPMSolverMultistepScheduler.from_pretrained(pretrained_model_path, subfolder='scheduler'),
        torch_dtype=torch.float16
    ).to('cuda')
    
    # 转换EDLoRA配置
    new_concept_cfg = convert_edlora(
        pipe,
        torch.load(lora_model_path),
        enable_edlora=enable_edlora,
        alpha=0.7
    )
    pipe.set_new_concept_cfg(new_concept_cfg)
    
    # 设置采样提示
    TOK = '<hermione1> <hermione2>'
    prompt = f'a {TOK} in front of eiffel tower, 4K, high quality, high resolution'
    negative_prompt = 'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'
    
    # 生成图像
    image = pipe(
        prompt,
        negative_prompt=negative_prompt,
        height=768,
        width=512,
        num_inference_steps=50,
        guidance_scale=7.5
    ).images[0]
    
    # 保存图像
    image.save('res.jpg')
    

请按照以上步骤进行安装和配置。祝您使用混合展示(Mix-of-Show)项目愉快!

Mix-of-Show NeurIPS 2023, Mix-of-Show: Decentralized Low-Rank Adaptation for Multi-Concept Customization of Diffusion Models Mix-of-Show 项目地址: https://gitcode.com/gh_mirrors/mi/Mix-of-Show

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

方玉蜜United

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值