混合展示(Mix-of-Show)项目安装与配置指南
1. 项目基础介绍
混合展示(Mix-of-Show)是一个开源项目,旨在通过去中心化的低秩适配技术对扩散模型进行多概念定制。该项目基于深度学习,可以实现对图像生成模型的多重概念融合,而不损失原有身份特征。主要编程语言为Python。
2. 项目使用的关键技术和框架
- 扩散模型(Diffusion Models):一种生成模型,可以生成高质量、高分辨率的图片。
- LoRA(Low-Rank Adaptation):一种微调技术,用于在少量样本上快速适应新概念。
- XFormer:一种用于节省内存的优化技术。
- Diffusers:用于处理扩散模型的库。
3. 项目安装和配置准备工作
在开始安装之前,请确保您的系统中已安装以下软件和依赖项:
- Python 3.9 或更高版本:建议使用Anaconda或Miniconda进行环境管理。
- Git:用于克隆和下载项目代码。
安装步骤
-
克隆项目仓库
打开命令行工具,执行以下命令克隆项目:
git clone https://github.com/TencentARC/Mix-of-Show.git cd Mix-of-Show
-
安装依赖项
在项目根目录下,使用pip安装所需的Python依赖:
pip install -r requirements.txt
-
准备预训练模型
克隆预训练模型仓库:
cd experiments/pretrained_models git-lfs clone https://huggingface.co/windwhinny/chilloutmix.git git-lfs clone https://huggingface.co/andite/anything-v4.0.git
-
数据准备
根据项目说明,数据选择和标记对于单概念微调非常重要。请参照项目中的
Dataset.md
文件进行数据准备工作。处理好的数据可以从Google Drive下载。 -
配置文件修改
在开始微调之前,需要修改配置文件,指定数据路径和调整超参数。配置文件位于
datasets/data_cfgs/
目录下。根据您要微调的概念,修改相应的JSON文件。 -
开始微调
使用以下命令开始微调过程(假设您已根据指南修改了配置文件):
accelerate launch train_edlora.py -opt options/train/EDLoRA/real/8101_EDLoRA_potter_Cmix_B4_Repeat500.yml
-
采样
微调完成后,您可以下载训练好的模型并使用以下代码进行采样:
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)项目愉快!
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考