🚀 Flux Edit
このプロジェクトは、画像編集のためにblack-forest-labs/FLUX.1-dev と TIGER-Lab/OmniEdit-Filtered-1.2M で学習された制御重みを提供します。微調整にはFlux Control framework を使用しています。
🚀 クイックスタート
これらの制御重みは、画像編集に使用できます。以下に、推論と高速化の方法を紹介します。
✨ 主な機能
💻 使用例
基本的な使用法
from diffusers import FluxControlPipeline, FluxTransformer2DModel
from diffusers.utils import load_image
import torch
path = "sayakpaul/FLUX.1-dev-edit-v0"
edit_transformer = FluxTransformer2DModel.from_pretrained(path, torch_dtype=torch.bfloat16)
pipeline = FluxControlPipeline.from_pretrained(
"black-forest-labs/FLUX.1-dev", transformer=edit_transformer, torch_dtype=torch.bfloat16
).to("cuda")
url = "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/flux-edit-artifacts/assets/mushroom.jpg"
image = load_image(url)
print(image.size)
prompt = "turn the color of mushroom to gray"
image = pipeline(
control_image=image,
prompt=prompt,
guidance_scale=30.,
num_inference_steps=50,
max_sequence_length=512,
height=image.height,
width=image.width,
generator=torch.manual_seed(0)
).images[0]
image.save("edited_image.png")
高度な使用法
Turbo LoRAを使用して推論を高速化する例です。
from diffusers import FluxControlPipeline, FluxTransformer2DModel
from diffusers.utils import load_image
from huggingface_hub import hf_hub_download
import torch
path = "sayakpaul/FLUX.1-dev-edit-v0"
edit_transformer = FluxTransformer2DModel.from_pretrained(path, torch_dtype=torch.bfloat16)
pipeline = FluxControlPipeline.from_pretrained(
"black-forest-labs/FLUX.1-dev", transformer=edit_transformer, torch_dtype=torch.bfloat16
).to("cuda")
pipeline.load_lora_weights(
hf_hub_download("ByteDance/Hyper-SD", "Hyper-FLUX.1-dev-8steps-lora.safetensors"), adapter_name="hyper-sd"
)
pipeline.set_adapters(["hyper-sd"], adapter_weights=[0.125])
url = "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/flux-edit-artifacts/assets/mushroom.jpg"
image = load_image(url)
print(image.size)
prompt = "turn the color of mushroom to gray"
image = pipeline(
control_image=image,
prompt=prompt,
guidance_scale=30.,
num_inference_steps=8,
max_sequence_length=512,
height=image.height,
width=image.width,
generator=torch.manual_seed(0)
).images[0]
image.save("edited_image.png")
推論速度の比較
guidance_scaleの影響
プロンプト |
Collage (gs: 10) |
Collage (gs: 20) |
Collage (gs: 30) |
Collage (gs: 40) |
Give this the look of a traditional Japanese woodblock print. |
 |
 |
 |
 |
transform the setting to a winter scene |
 |
 |
 |
 |
turn the color of mushroom to gray |
 |
 |
 |
 |
🔧 技術詳細
学習詳細
微調整のコードベースはこちらにあります。学習のハイパーパラメータは以下の通りです。
- 1GPUあたりのバッチサイズ: 4
- 勾配蓄積ステップ: 4
- ガイダンススケール: 30
- BF16混合精度
- AdamWオプティマイザー (8bit from
bitsandbytes
)
- 固定学習率 5e-5
- 重み減衰 1e-6
- 学習ステップ数 20000
学習は8xH100のノードを使用して行われました。
線形補間を行うための簡略化されたフローメカニズムの疑似コードは以下の通りです。
sigmas = torch.rand(batch_size)
timesteps = (sigmas * noise_scheduler.config.num_train_timesteps).long()
...
noisy_model_input = (1.0 - sigmas) * pixel_latents + sigmas * noise
ここで、pixel_latents
はソース画像から計算され、noise
はガウス分布からサンプリングされます。詳細はリポジトリを参照してください。
📄 ライセンス
こちらに記載されているライセンス条項に従ってください。
📚 ドキュメント
想定される使用法と制限
推論
上記のコード例を参照してください。また、メモリ要件がハードウェアで満たせない場合は量子化を行うこともできます。詳細はDiffusers documentation を参照してください。
制限とバイアス
Flux Controlの正確な学習詳細が不明なため、モデルの性能は十分でない場合があります。