原创 爱动手的 2025-07-08 20:21 浙江
魔搭开源了4种全新的Kontext LoRA模型,可用于低分辨率图像高清化、图像外扩、美学提升和玻璃雕像风格转换等图像编辑功能,用户可在AIGC专区体验,本地部署推理和训练可使用DiffSynth-Studio工具
♦
引言
LoRA案例效果
玻璃雕像:一键拥有blingbling的雕像风格
玩法1:低分辨率图像的高清修复
模型链接
https://modelscope.cn/models/DiffSynth-Studio/FLUX.1-Kontext-dev-lora-highresfix编辑指令:Improve the clarity.这个 LoRA 模型是使用大量高清图及其低分辨率版本训练而来的,可以大幅度提升图像的清晰度。例如下面这张图经过模型处理后,画面变得非常清晰。玩法2:图像的局部编辑与外扩
模型链接
https://modelscope.cn/models/DiffSynth-Studio/FLUX.1-Kontext-dev-lora-SuperOutpainting编辑指令:Outpaint the image. + 英文图像描述(可选)Kontext模型本身有一定图像外扩能力,但是对prompt和输入样例不稳定,可能导致非指定区域也被修改。因此,我们使用EliGen训练集构建了Kontext的图像外扩训练集,训练了这个LoRA模型,可以稳定地完成图像外扩,也可以泛化到图像重绘和局部编辑情形。如下,给定部分区域缺失的图像,可以让模型直接进行图像重绘,绘出缺失部分。图像外扩可以进一步用在拉远场景视角上,比如我们将上一个输出的场景图置于图的中央,并再执行一次外扩,可以得到更大视角的场景图。
玩法3:图像的美学提升
模型链接
编辑指令:玩法4:风格变变变
在线图像编辑
LoRA推理与训练
推理:git clone https://github.com/modelscope/DiffSynth-Studio.git
cd DiffSynth-Studio
pip install -e .
DiffSynth-Studio 训练虽然 Kontext 的模型结构与 FLUX 一致,但作为一个图像编辑模型,其生成过程融入了额外的输入图像,因此训练算法也需要作出针对性的修改。DiffSynth-Studio 已经支持了 Kontext 原生编辑模式的训练。以上这些 LoRA 模型都是基于 DiffSynth-Studio 训练的,训练教程可参考往期文章:FLUX.1 Kontext 的全生态教程来啦!AIGC专区在线试玩!DiffSynth框架、Com或进入 DiffSynth-Studio 的开源项目页面查看。 DiffSynth-Studio地址:https://github.com/modelscope/DiffSynth-Studio/tree/main/examples/fluximport torch
from diffsynth.pipelines.flux_image_new import FluxImagePipeline, ModelConfig
from PIL import Image
from modelscope import snapshot_download
pipe = FluxImagePipeline.from_pretrained(
torch_dtype=torch.bfloat16,
device="cuda",
model_configs=[
ModelConfig(model_id="black-forest-labs/FLUX.1-Kontext-dev", origin_file_pattern="flux1-kontext-dev.safetensors"),
ModelConfig(model_id="black-forest-labs/FLUX.1-dev", origin_file_pattern="text_encoder/model.safetensors"),
ModelConfig(model_id="black-forest-labs/FLUX.1-dev", origin_file_pattern="text_encoder_2/"),
ModelConfig(model_id="black-forest-labs/FLUX.1-dev", origin_file_pattern="ae.safetensors"),
],
)
pipe.load_lora(
pipe.dit,
ModelConfig(model_id="DiffSynth-Studio/FLUX.1-Kontext-dev-lora-highresfix", origin_file_pattern="model.safetensors")
)
image = Image.open("your_image.jpg")
image = pipe(
prompt="Improve the clarity.",
kontext_images=image,
embedded_guidance=2.5,
seed=0,
)
image.save("output.jpg")
👇点击关注ModelScope公众号获取
更多技术信息~