Buckets:

hf-doc-build/doc / diffusers /main /ja /api /pipelines /bria_fibo_edit.md
mishig's picture
|
download
raw
13.6 kB

Bria Fibo Edit

Fibo Edit は、8B パラメータの image-to-image モデルであり、ソース画像と組み合わせた JSON 入力に対して動作する新しい構造化制御のパラダイムを導入します。これにより、決定論的かつ再現可能な編集ワークフローを可能にします。細粒度の精度を実現するネイティブなマスキング機能を備え、単純なプロンプトベースの拡散を超えて、本番環境向けに最適化された明示的かつ解釈可能な制御を提供します。軽量なアーキテクチャは深いカスタマイズを前提として設計されており、研究者がドメイン固有のタスク向けに特化した「Edit」モデルを構築できる一方で、トップクラスの美的品質を維持します。

詳細については、Bria Fibo Edit の Hugging Face ページを参照してください。蒸留済みチェックポイントは Fibo-Edit-1.5-turbo で利用可能です。

使用方法

このモデルはゲート付きのため、diffusers で使用する前に、まず Bria Fibo Edit の Hugging Face ページ にアクセスしてフォームに記入し、ゲートの承認を行う必要があります。承認が完了したら、システムがゲートの承認済みであることを認識できるよう、ログインしてください。

以下のコマンドを使用してログインします:

hf auth login

BriaFiboEditPipeline[[diffusers.BriaFiboEditPipeline]]

diffusers.BriaFiboEditPipeline[[diffusers.BriaFiboEditPipeline]]

diffusers.BriaFiboEditPipeline(transformer: BriaFiboTransformer2DModel, scheduler: typing.Union[diffusers.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler, diffusers.schedulers.scheduling_utils.KarrasDiffusionSchedulers], vae: AutoencoderKLWan, text_encoder: SmolLM3ForCausalLM, tokenizer: AutoTokenizer)

ソース

パラメータ:

transformer (BriaFiboTransformer2DModel) : 2次元拡散モデリング用のtransformerモデルです。

scheduler (FlowMatchEulerDiscreteScheduler または KarrasDiffusionSchedulers) : transformer と組み合わせて、エンコードされた潜在変数のノイズ除去に使用するスケジューラー。

vae (AutoencoderKLWan) : 画像を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダー。

text_encoder (SmolLM3ForCausalLM) : 入力プロンプトを処理するためのテキストエンコーダー。

tokenizer (AutoTokenizer) : text_encoder に入力するテキストプロンプトを処理するために使用される Tokenizer。

call[[diffusers.BriaFiboEditPipeline.call]]

__call__(prompt: typing.Union[str, typing.List[str]] = None, image: typing.Union[PIL.Image.Image, typing.List[PIL.Image.Image], NoneType] = None, mask: typing.Union[torch.FloatTensor, PIL.Image.Image, typing.List[PIL.Image.Image], typing.List[torch.FloatTensor], numpy.ndarray, typing.List[numpy.ndarray], NoneType] = None, height: int | None = None, width: int | None = None, num_inference_steps: int = 30, timesteps: typing.List[int] = None, seed: int | None = None, guidance_scale: float = 5, negative_prompt: typing.Union[str, typing.List[str], NoneType] = None, num_images_per_prompt: typing.Optional[int] = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.FloatTensor] = None, output_type: str = 'pil', return_dict: bool = True, joint_attention_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None, callback_on_step_end: typing.Optional[typing.Callable[[int, int, typing.Dict], NoneType]] = None, callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'], max_sequence_length: int = 3000, do_patching = False, _auto_resize: bool = True)

ソース

パラメータ:

prompt (str または List[str]) : 画像生成を導くプロンプト、またはプロンプトのリスト。

image (PIL.Image.Image または List[PIL.Image.Image]、任意) : 画像生成をガイドするための1枚以上の参照画像です。リストはバッチではなく複数の参照として解釈されます。各参照画像は独自のアスペクト比でVAEエンコードされ、それぞれが独自のRoPE時間平面1、2、...に配置されます。定義されていない場合、パイプラインはゼロから画像を生成します。

mask (PipelineMaskInput、任意) : imageを編集する領域を定義する任意のマスク。マスクで覆われたピクセルは再生成され、画像の残りは保持されます。

height (int、任意、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像のピクセル単位の縦幅。最適な結果を得るため、デフォルトでは 1024 に設定されています。

width (int、任意、デフォルトは self.unet.config.sample_size * self.vae_scale_factor) : 生成される画像の幅(ピクセル単位)。最適な結果を得るため、デフォルトでは 1024 に設定されています。

num_inference_steps (int、optional、デフォルトは 30) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。

seed (int, 任意) : 生成を決定論的にするためのシード。

timesteps (List[int], 任意) : set_timesteps メソッドで timesteps 引数をサポートするスケジューラーにおいて、デノイジングプロセスに使用するカスタムタイムステップ。未定義の場合、num_inference_steps が渡された際のデフォルトの動作が使用されます。降順で指定する必要があります。

guidance_scale (float、任意、デフォルト値は 5.0) : Classifier-Free Diffusion Guidanceで定義されているガイダンススケールです。guidance_scale は、Imagen Paperの式 2 の w として定義されています。guidance_scale > 1 を設定することで、ガイダンススケールが有効になります。ガイダンススケールを高くすると、prompt のテキストと密接に関連した画像の生成が促されますが、通常は画像の品質が低下する傾向があります。

negative_prompt (str または List[str]、省略可能) : 画像生成をガイドしないプロンプトです。guidance_scale が 1 未満の場合、ガイドを使用していないため無視されます。

num_images_per_prompt (int、任意、デフォルトは 1) : プロンプトごとに生成する画像の数。

generator (torch.Generator または List[torch.Generator]、任意) : 生成を決定論的にするための torch ジェネレーター 1 つまたはそのリスト。

latents (torch.FloatTensor, 任意) : イメージ生成の入力として使用する、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダムなgeneratorを使用してサンプリングを行い、ラテンツのテンソルが生成されます。

output_type (str、任意、デフォルトは "pil") : 生成画像の出力形式。PIL(PIL.Image.Image)または np.array から選択します。

return_dict (bool、任意、デフォルトはTrue) : プレーンなタプルではなく~pipelines.stable_diffusion_xl.StableDiffusionXLPipelineOutputを返すかどうか。

joint_attention_kwargs (dict, 任意) : 指定された場合、diffusers.models.attention_processor の self.processor で定義されている AttentionProcessor に渡される kwargs の辞書です。

callback_on_step_end (Callable、任意) : 推論中の各デノイジングステップの終了時に呼び出される関数です。この関数は、以下の引数とともに呼び出されます: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)。 callback_kwargs には、callback_on_step_end_tensor_inputs で指定されたすべてのテンソルのリストが含まれます。

callback_on_step_end_tensor_inputs (List, 任意) : callback_on_step_end 関数へのテンソル入力のリストです。リストで指定されたテンソルは、callback_kwargs 引数として渡されます。パイプラインクラスの ._callback_tensor_inputs 属性にリストされている変数のみを包含できます。

max_sequence_length (int、デフォルトは 3000) : prompt に使用する最大シーケンス長。

do_patching (bool, 任意, デフォルトは False) : パッチングを使用するかどうか。

_auto_resize (bool, 任意, デフォルトは True) : 既定の出力解像度(最初の参照画像から取得)を、推奨解像度にスナップするかどうかを指定します。

戻り値: ~pipelines.flux.BriaFiboPipelineOutput または tuple

return_dict が True の場合は ~pipelines.flux.BriaFiboPipelineOutput、それ以外の場合は tuple を返します。tuple を返す場合、最初の要素は生成された画像のリストです。

生成用のパイプラインを呼び出したときに実行される関数。

例:

import torch
from PIL import Image

from diffusers import BriaFiboEditPipeline
from diffusers.modular_pipelines import ModularPipelineBlocks

# This prompt-to-JSON block calls Gemini and needs GEMINI_API_KEY in the environment.
vlm_pipe = ModularPipelineBlocks.from_pretrained("briaai/FIBO-edit-gemini-prompt-to-JSON", trust_remote_code=True)
vlm_pipe = vlm_pipe.init_pipeline()

pipe = BriaFiboEditPipeline.from_pretrained(
    "briaai/Fibo-Edit-1.5-base",
    torch_dtype=torch.bfloat16,
)
pipe.to("cuda")

image = Image.open("owl.png")
json_prompt = vlm_pipe(image=image, prompt="Make the owl into a cat").values["json_prompt"]

result = pipe(prompt=json_prompt, image=image, num_inference_steps=30, guidance_scale=5)

# Multiple reference images: pass a list. Each reference conditions the edit at its
# own aspect ratio; the output resolution follows the first reference.
owl, forest = Image.open("owl.png"), Image.open("forest.png")
json_prompt = vlm_pipe(
    image=[owl, forest], prompt="Place the owl from the first image in the forest from the second image"
).values["json_prompt"]
result = pipe(
    prompt=json_prompt,
    image=[owl, forest],
    num_inference_steps=30,
    guidance_scale=5,
)

# The distilled Turbo checkpoint edits in 4 steps without classifier-free guidance.
pipe = BriaFiboEditPipeline.from_pretrained("briaai/Fibo-Edit-1.5-turbo", torch_dtype=torch.bfloat16)
pipe.to("cuda")
result = pipe(prompt=json_prompt, image=[owl, forest], num_inference_steps=4, guidance_scale=1)

encode_prompt[[diffusers.BriaFiboEditPipeline.encode_prompt]]

encode_prompt(prompt: typing.Union[str, typing.List[str]], device: typing.Optional[torch.device] = None, num_images_per_prompt: int = 1, guidance_scale: float = 5, negative_prompt: typing.Union[str, typing.List[str], NoneType] = None, max_sequence_length: int = 3000, lora_scale: bool | None = None)

ソース

パラメータ:

prompt (str または List[str]、省略可能) : エンコードするプロンプト

device : (torch.device): torch デバイス

num_images_per_prompt (int) : プロンプトごとに生成すべき画像の数

guidance_scale (float) : classifier free guidance のガイダンススケール。

negative_prompt (str または List[str]、任意) : 画像生成をガイドしないプロンプトまたはプロンプツのリスト。guidance_scale が 1 未満の場合、無視されます(ガイドを使用していない場合、無視されます)。

prepare_reference_latents[[diffusers.BriaFiboEditPipeline.prepare_reference_latents]]

prepare_reference_latents(image: Image, num_channels_latents: int, dtype: dtype, device: device, do_patching: bool = False, reference_index: int = 1)

ソース

VAEエンコードにより、PIL参照画像をその元のサイズでエンコードし、編集コンテキストのトークンストリームとしてパックします。

Xet Storage Details

Size:
13.6 kB
·
Xet hash:
cb06bb0ac35372066df5535171d99e9c55ce3471a0bcfa17d87afc5aa287a335

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.