原创 SiliconCloud 2025-01-22 14:23 甘肃
仅需简单配置几个参数,即可获得独特风格的生图 LoRA。
作者|王煜青、王义
自 FLUX.1 [dev] 模型推出以来,其优秀的生图效果和指令遵循能力,广受青睐和赞誉。它也是硅基流动 SiliconCloud 平台的生图模型中应用最广泛、丰富的模型。
近期,在原有 LLM 模型 LoRA 微调的基础上,SiliconCloud 提供了生图模型的 LoRA 模型微调功能。仅需简单配置几个参数,就能获得独特风格的生图 LoRA,从而为 FLUX.1 [dev] 模型的图像生成引入鲜明的风格。
要使用 SiliconCloud 的生图微调功能,需要完成数据集准备、创建微调任务、API 调用并传入 LoRA 参数三个主要环节。以下我们以“国风小猫”为主题,来展示完整的微调过程。
1. 数据集准备
在开始 LoRA 微调之前,你需要先准备好微调所需要的数据。SiliconCloud 对生图微调数据集的要求如下:
数据集应在同一个本地文件夹中,且同时包含图片及对应图片的文本描述;
每个数据集最多包含 100 张图片及其文本描述;
支持的图片格式包括:.jpg、.jpeg、.png、.webp,建议分辨率为:1024*1024、1024*768、768*1024;
不符合上述分辨率的图片,在训练时会被缩放、剪裁为上述分辨率;
图片描述应保存为与图片同名的 .txt 文件;
单张图片不超过 10M,单个图片描述文件不超过 128K;
对于 FLUX.1 模型,图片描述信息不超过 512 tokens,内容过长会被截断。
如果我们想要训练“国风小猫” LoRA,自然需要准备好特定风格的“猫片”和对应的描述。需要特别说明的是,FLUX.1 系列模型仅支持英文,因此图片描述务必使用英文。
下面是一个简单数据集的部分示例内容:
图片文件名:001.png
描述文件名:001.txt
描述内容:Two cats, depicted in a serene, traditional Asian landscape painting style. The cats are positioned in a garden setting, with a small pond in the background. The colors are muted and subtle, with earth tones, greens, and light pastels. A light brownish-tan background suggests a natural, diffused light. The perspective is a slightly elevated view of the landscape; the focal point is on the relationship between the cats and their surroundings. One of the cat facing to a butterfly and trying to catch it, while the other cat is napping. Detailed brushstrokes are used to portray the textures of the fur and foliage. A style characteristic of Chinese traditional painting is evident, characterized by meticulous attention to detail. The image displays a calm atmosphere, capturing the tranquility of the scene.
图片文件名:002.png
描述文件名:002.txt
描述内容:Traditional Chinese watercolor painting style featuring two playful cats with soft, fluffy fur and delicate patterns. Surrounding them are branches of a tree adorned with vibrant orange-yellow berries and lush green leaves. The background is minimalist, with a soft beige or parchment tone, emphasizing the natural elements and the cats. The composition radiates a sense of harmony and gentle curiosity, characteristic of classical Chinese brush art. Add elegant calligraphy to complement the scene.
图片文件名:003.png
描述文件名:003.txt
描述内容:A playful kitten rendered in a traditional East Asian watercolor style, pawing curiously at a colorful toy dangling from a string. The composition includes vibrant yellow butterflies fluttering around the kitten, adding a whimsical and lively atmosphere. The background is a textured parchment-like beige, highlighting the delicate brushwork and natural tones. The scene evokes joy and curiosity, with a focus on the kitten's soft fur and the dynamic interaction between the elements
按上述方式组织的图片和图片描述文件,需要在本地放在同一个文件夹中,这里我们放在本地的 ChineseCat 文件夹中。
值得注意的是,与 LLM 微调一样,并不是数据越多,训练效果就一定越好,通常 20 张图片就足以产生足够好的训练效果,图片的多寡也直接影响 LoRA 超参数的配置选择。
至此,数据准备环节大功告成,接下来我们开始创建微调 LoRA。
2. 创建任务训练微调 LoRA
登录 SiliconCloud 并进入“模型微调”页面,点击“新建微调任务”并在弹出的侧边窗口中选择“生图模型微调”;
填写基础信息,选择微调的基础模型;
上传此前准备好的微调数据集:此处与 LLM 模型微调略有不同,上传时需选择本地文件夹,系统会上传文件夹中的所有文件,并校验图片与描述文件的匹配情况,通过校验后则会在云端将数据集保存为一个 .zip 文件方便后续使用;
设置微调参数,核对费用并“开始微调”。
在设置参数时,可参考下列信息:
微调任务创建成功后,会进入训练排队中,等待任务执行完毕,即可在界面上看到训练产生的 LoRA 模型清单。
3. 应用 LoRA 模型
在 SiliconCloud 训练的生图 LoRA,与语言模型一样无需再进行部署,只需更换 API 参数即可调用(生图 LoRA 暂时仅支持 API 调用,后续提供在线体验和对比功能)。
调用 LoRA 模型,使用的依然是 /image/generations API,可以参见创建图片生成请求(https://docs.siliconflow.cn/api-reference/images/images-generations)。请求时注意使用 LoRA/black-forest-labs/FLUX.1-dev 模型,并添加 loras 对象数组,传入需要的 LoRA 和每个 LoRA 的系数即可。
至此,我们就在 SiliconCloud 平台上完成了图片模型微调的整个过程。
附:FLUX.1 [dev] 微调效果
strength 分别为 0、0.5、1.0
提示词:A tabby cat resting on a wooden bridge in a traditional Chinese garden, painted in soft watercolor tones. Cherry blossoms gently fall around the scene, and the brushwork emphasizes fluidity and harmony, inspired by ancient Chinese art
strength 分别为 0、0.5、1.0
提示词:A playful kitten in a Chinese watercolor style, leaping among bamboo stalks. The background features soft washes of ink, with subtle hints of green and gold, evoking the elegance of classical Chinese painting.
strength 分别为 0、0.5、1.0
提示词:A sleepy cat curled up on a windowsill overlooking a traditional Chinese courtyard, painted in delicate watercolor. The scene includes intricate details of wooden lattice windows and potted plants, with a soft, dreamy atmosphere
近期更新
• BizyAir用户评测:无显卡玩转ComfyUI
• Siliconcloud上线加速版CosyVoice2
• 音频模型调用成本高?SiliconCloud价格砍半
• SiliconCloud x 麦悠电台:制作专属 AI 播客
• 成本直降100倍!LLM清洗/蒸馏数据高效方法
• 4步速通LLM微调:手把手带你打造领域大模型
让超级产品开发者实现“Token自由”
邀好友用SiliconCloud,狂送2000万Token/人
即刻体验加速版FLUX.1
cloud.siliconflow.cn
扫码加入用户交流群
(备注“BizyAir”)