🚀 可爱涂鸦LoRA - HiDream
这是一个基于 HiDream-ai/HiDream-I1-Full 的LyCORIS适配器。它主要用于生成可爱风格的涂鸦图像,在训练过程中使用特定的验证提示来确保生成图像的质量。
🚀 快速开始
本项目是一个基于 HiDream-ai/HiDream-I1-Full 的LyCORIS适配器,用于生成可爱风格的涂鸦图像。
✨ 主要特性
- 基于HiDream-I1-Full模型,生成可爱风格的涂鸦图像。
- 提供了训练和验证的详细设置,确保模型的稳定性和生成效果。
- 支持推理代码示例,方便用户快速上手。
📦 安装指南
文档未提供具体安装步骤,故跳过此章节。
💻 使用示例
基础用法
import torch
from diffusers import DiffusionPipeline
from lycoris import create_lycoris_from_weights
def download_adapter(repo_id: str):
import os
from huggingface_hub import hf_hub_download
adapter_filename = "pytorch_lora_weights.safetensors"
cache_dir = os.environ.get('HF_PATH', os.path.expanduser('~/.cache/huggingface/hub/models'))
cleaned_adapter_path = repo_id.replace("/", "_").replace("\\", "_").replace(":", "_")
path_to_adapter = os.path.join(cache_dir, cleaned_adapter_path)
path_to_adapter_file = os.path.join(path_to_adapter, adapter_filename)
os.makedirs(path_to_adapter, exist_ok=True)
hf_hub_download(
repo_id=repo_id, filename=adapter_filename, local_dir=path_to_adapter
)
return path_to_adapter_file
model_id = 'HiDream-ai/HiDream-I1-Full'
adapter_repo_id = 'markury/cute-doodles-lokr-hidream'
adapter_filename = 'pytorch_lora_weights.safetensors'
adapter_file_path = download_adapter(repo_id=adapter_repo_id)
pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
lora_scale = 1.0
wrapper, _ = create_lycoris_from_weights(lora_scale, adapter_file_path, pipeline.transformer)
wrapper.merge_to()
prompt = "a cute doodle of an orange tabby cat, with a grey mouse in its mouth."
negative_prompt = 'blurry, cropped, ugly'
from optimum.quanto import quantize, freeze, qint8
quantize(pipeline.transformer, weights=qint8)
freeze(pipeline.transformer)
pipeline.to('cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu')
model_output = pipeline(
prompt=prompt,
negative_prompt=negative_prompt,
num_inference_steps=50,
generator=torch.Generator(device='cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu').manual_seed(42),
width=1024,
height=1024,
guidance_scale=5.0,
).images[0]
model_output.save("output.png", format="PNG")
高级用法
文档未提供高级用法相关代码,故跳过此部分。
📚 详细文档
验证设置
- CFG:
5.0
- CFG 缩放:
0.0
- 步数:
50
- 采样器:
FlowMatchEulerDiscreteScheduler
- 随机种子:
42
- 分辨率:
1024,1024
注意:验证设置不一定与训练设置相同。
你可以在以下图库中找到一些示例图像:
文本编码器未进行训练。你可以重用基础模型的文本编码器进行推理。
训练设置
- 训练轮数:0
- 训练步数:600
- 学习率:0.0001
- 最大梯度值:0.01
- 有效批次大小:2
- 微批次大小:2
- 梯度累积步数:1
- GPU 数量:1
- 梯度检查点:启用
- 预测类型:flow_matching(额外参数=['shift=3'])
- 优化器:optimi-lion
- 可训练参数精度:Pure BF16
- 基础模型精度:
int8-quanto
- 字幕丢弃概率:0.0%
LyCORIS 配置:
{
"algo": "lokr",
"multiplier": 1.0,
"linear_dim": 10000,
"linear_alpha": 1,
"factor": 16,
"apply_preset": {
"target_module": [
"Attention",
"FeedForward"
],
"module_algo_map": {
"Attention": {
"factor": 16
},
"FeedForward": {
"factor": 16
}
}
}
}
数据集
涂鸦数据集
- 重复次数:7
- 图像总数:183
- 纵横比桶总数:1
- 分辨率:1.048576 兆像素
- 裁剪:是
- 裁剪风格:随机
- 裁剪纵横比:方形
- 用于正则化数据:否
🔧 技术细节
本项目基于LyCORIS技术对HiDream-I1-Full模型进行微调,通过特定的训练设置和数据集,使得模型能够生成可爱风格的涂鸦图像。在训练过程中,使用了flow_matching预测类型和optimi-lion优化器,同时对模型进行了量化处理以节省显存。
📄 许可证
许可证类型:其他