原文链接:https://itq5.com/posts/flux_lora
学习了一段时间的ComfyUI了,今天借助腾讯云CloudStudio(每月免费提供10000分钟T4显卡资源以及50000分钟CPU资源)平台训练一个自己的专属LoRA。
1.生成人物形象.json
工作流到本地 https://pan.itq5.com/d/%E5%B7%A5%E4%BD%9C%E6%B5%81/2.LoRA%E8%AE%AD%E7%BB%83/1.%E7%94%9F%E6%88%90%E4%BA%BA%E7%89%A9%E5%BD%A2%E8%B1%A1.json1.生成人物形象.json
拖拉到ComfyUI中加载。管理器
中点击安装缺失节点
,将缺失的节点选中安装姿势图.png
到自己电脑。 https://pan.itq5.com/d/%E5%B7%A5%E4%BD%9C%E6%B5%81/2.LoRA%E8%AE%AD%E7%BB%83/%E5%A7%BF%E5%8A%BF%E5%9B%BE.png姿势图.png
到工作流。管理器
,选择模型管理
。Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro
并下载。face_yolov8m (bbox)
并下载。ComfyUI-AdvancedLivePortrait
节点很长时间没更新版本,torch在新版本中默认开启了weights_only
,需要手动关闭。/root/miniforge3/envs/python-3.11.11/lib/python3.11/site-packages/ultralytics/nn/tasks.py
文件的857和837行,将ckpt = torch.load(file, map_location="cpu")
修改成 ckpt = torch.load(file, map_location="cpu", weights_only=False)
禁用框
中开启第一个1 按姿势图生成多角度图
A character sheet with a white background, featuring multiple views and displayed from various angles. The face is clearly visible. (It is a cute girl wearing a blue shirt and a white short skirt, in an anime style.)
Plain text
Copy
禁用框
中开启剩余节点。项目地址cocktailpeanut/fluxgym: Dead simple FLUX LoRA training UI with LOW VRAM support
git clone https://github.com/cocktailpeanut/fluxgym
cd fluxgym
git clone -b sd3 https://github.com/kohya-ss/sd-scripts
conda create -n fluxgym python=3.11.11 -y
创建虚拟环境。/root/miniforge3/envs/fluxgym/bin/pip install --upgrade pip
更新pipsd-scripts
的依赖 cd /root/fluxgym/sd-scripts/
/root/miniforge3/envs/fluxgym/bin/pip install -r requirements.txt
fluxgym
的依赖cd /root/fluxgym/
/root/miniforge3/envs/fluxgym/bin/pip install -r requirements.txt
/root/miniforge3/envs/fluxgym/bin/pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
vim /root/fluxgym/app.py
修改前:
修改后:
# cat app.py
import os
import sys
......
def download(base_model):
model = models[base_model]
model_file = model["file"]
repo = model["repo"]
# download unet
if base_model == "flux-dev" or base_model == "flux-schnell":
unet_folder = "/workspace/ComfyUI/models/unet"
else:
unet_folder = f"/workspace/ComfyUI/models/unet/{repo}"
unet_path = os.path.join(unet_folder, model_file)
if not os.path.exists(unet_path):
os.makedirs(unet_folder, exist_ok=True)
gr.Info(f"Downloading base model: {base_model}. Please wait. (You can check the terminal for the download progress)", duration=None)
print(f"download {base_model}")
hf_hub_download(repo_id=repo, local_dir=unet_folder, filename=model_file)
# download vae
vae_folder = "/workspace/ComfyUI/models/vae"
vae_path = os.path.join(vae_folder, "ae.safetensors")
if not os.path.exists(vae_path):
os.makedirs(vae_folder, exist_ok=True)
gr.Info(f"Downloading vae")
print(f"downloading ae.sft...")
hf_hub_download(repo_id="cocktailpeanut/xulf-dev", local_dir=vae_folder, filename="ae.sft")
# download clip
clip_folder = "/workspace/ComfyUI/models/clip"
clip_l_path = os.path.join(clip_folder, "clip_l.safetensors")
if not os.path.exists(clip_l_path):
os.makedirs(clip_folder, exist_ok=True)
gr.Info(f"Downloading clip...")
print(f"download clip_l.safetensors")
hf_hub_download(repo_id="comfyanonymous/flux_text_encoders", local_dir=clip_folder, filename="clip_l.safetensors")
# download t5xxl
t5xxl_path = os.path.join(clip_folder, "t5xxl_fp16.safetensors")
if not os.path.exists(t5xxl_path):
print(f"download t5xxl_fp16.safetensors")
gr.Info(f"Downloading t5xxl...")
hf_hub_download(repo_id="comfyanonymous/flux_text_encoders", local_dir=clip_folder, filename="t5xxl_fp16.safetensors")
......
model_config = models[base_model]
model_file = model_config["file"]
repo = model_config["repo"]
if base_model == "flux-dev" or base_model == "flux-schnell":
model_folder = "/workspace/ComfyUI/models/unet"
else:
model_folder = f"/workspace/ComfyUI/models/unet/{repo}"
model_path = os.path.join(model_folder, model_file)
pretrained_model_path = resolve_path(model_path)
clip_path = resolve_path("/workspace/ComfyUI/models/clip/clip_l.safetensors")
t5_path = resolve_path("/workspace/ComfyUI/models/clip/t5xxl_fp16.safetensors")
ae_path = resolve_path("/workspace/ComfyUI/models/vae/ae.safetensors")
......
if __name__ == "__main__":
cwd = os.path.dirname(os.path.abspath(__file__))
demo.launch(debug=True, show_error=True, allowed_paths=[cwd])
vim /root/fluxgym/models.yaml
修改前:
修改后:
# cat models.yaml
# Add your own model here
# <name that will show up on the dropdown>:
# repo: <the huggingface repo ID to pull from>
# base: <the model used to run inference with (The Huggingface "Inference API" widget will use this to generate demo images)>
# license: <follow the other examples. Any model inherited from DEV should use the dev license, schenll is apache-2.0>
# license_name: <follow the other examples. only needed for dev inherited models>
# license_link: <follow the other examples. only needed for dev inherited models>
# file: <the file name within the huggingface repo>
flux-dev:
repo: cocktailpeanut/xulf-dev
base: black-forest-labs/FLUX.1-dev
license: other
license_name: flux-1-dev-non-commercial-license
license_link: https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md
file: flux1-dev.safetensors
flux-schnell:
repo: black-forest-labs/FLUX.1-schnell
base: black-forest-labs/FLUX.1-schnell
license: apache-2.0
file: flux1-schnell.safetensors
bdsqlsz/flux1-dev2pro-single:
repo: bdsqlsz/flux1-dev2pro-single
base: black-forest-labs/FLUX.1-dev
license: other
license_name: flux-1-dev-non-commercial-license
license_link: https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md
file: flux1-dev2pro.safetensors
2.3 启动项目
nohup /root/miniforge3/envs/fluxgym/bin/python3 /root/fluxgym/app.py > /dev/null 2>&1 &
The name of your LoRA
输入LoRA名称。Trigger word/sentence
输入触发词Base mode
中选择基础模型flux-dev
(按实际选择)VRAM
中选择20G
(按实际显卡选择)Step 2.Dataset
中上传处理后的预训练图。Add AI captions with Florence-2
Step 3. Train
中的Start training
开始训练运行中观察Volatile GPU-Util的值,需要大于0,一般是99%或100%。 如果是0,说明停止训练了。
训练中,会在/root/fluxgym/outputs/wdw/
生成对应的lora模型。
/root/fluxgym/outputs/wdw/wdw-000004.safetensors
训练的模型,复制到/workspace/ComfyUI/models/loras
目录下。cp wdw-000004.safetensors /workspace/ComfyUI/models/loras/
Bash
Copy
2.使用LoRa生成统一的人物形象.json
下载到电脑并拖拉到ComfyUI上进行加载。 https://pan.itq5.com/d/%E5%B7%A5%E4%BD%9C%E6%B5%81/2.LoRA%E8%AE%AD%E7%BB%83/2.%E4%BD%BF%E7%94%A8LoRa%E7%94%9F%E6%88%90%E7%BB%9F%E4%B8%80%E7%9A%84%E4%BA%BA%E7%89%A9%E5%BD%A2%E8%B1%A1.jsonwdw-000004.safetensors
END
免责声明:
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。