# Ovis-Image

![concepts](https://github.com/AIDC-AI/Ovis-Image/blob/main/docs/imgs/ovis_image_case.png)

Ovis-Imageは、高品質なテキストレンダリングに特化して最適化された7Bのテキストから画像を生成するモデルであり、厳格な計算リソースの制約下でも効率的に動作するように設計されています。

Alibaba GroupのGuo-Hua Wang、Liangfu Cao、Tianyu Cui、Minghao Fu、Xiaohao Chen、Pengxin Zhan、Jianshan Zhao、Lan Li、Bowen Fu、Jiaqi Liu、Qing-Guo Chenによる[Ovis-Image Technical Report](https://arxiv.org/abs/2511.22982)

論文の抄録は以下の通りです：

*当社は、厳格な計算リソース制約下で効率的に動作するよう、高品質なテキストレンダリングに特化して最適化された7Bパラメータのテキストから画像生成モデル、Ovis-Image を紹介します。Ovis-Image は、以前の Ovis-U1 フレームワークを基盤として構築されており、拡散ベースのビジュアルデコーダーと、より強力な Ovis 2.5 マルチモーダルバックボーンを統合しています。さらに、大規模な事前学習と、慎重に調整された事後学習による微調整を組み合わせた、テキスト中心の学習パイプラインを活用しています。コンパクトなアーキテクチャにもかかわらず、Ovis-Image は Qwen-Image といったはるかに大規模なオープンモデルと同等のテキストレンダリング性能を達成し、Seedream や GPT4o といったクローズドソースのシステムに迫る性能を示しています。特に重要なのは、このモデルが中程度のメモリを備えた単一のハイエンド GPU 上でデプロイ可能であり、フロンティアレベルのテキストレンダリングと実用的なデプロイメントの間のギャップを縮小している点です。当社の結果は、強力なマルチモーダルバックボーンと、慎重に設計されたテキストに焦点を当てた学習レシピを組み合わせることで、過大規模なモデルやプロプライエタリモデルに頼らずとも、信頼性の高いバイリンガルテキストレンダリングを達成できることを示しています。*

**ハイライト**：

*   **コンパクトな7B規模での強力なテキストレンダリング**: Ovis-Imageは7Bのテキストto画像モデルであり、Qwen-Imageのようなはるかに大きな20Bクラスのシステムと同等のテキストレンダリング品質を提供し、テキスト中心のシナリオではGPT4oなどの主要なクローズドソースモデルと競合できるレベルにありながら、広く利用可能なハードウェア上で実行できるほど小型です。
*   **テキストが多く、レイアウトに敏感なプロンプトにおける高忠実度**: 言語的な内容とレンダリングされたタイポグラフィの間の密接な整合性を要求するプロンプト（ポスター、バナー、ロゴ、UIモックアップ、インフォグラフィックなど）において、このモデルは優れた性能を発揮します。多様なフォント、サイズ、アスペクト比にわたって、視認性があり、スペルが正しく、意味的に一貫性のあるテキストを生成し、全体の視覚的品質を損なうことなく実現します。
*   **効率性とデプロイ可能性**: 7Bパラメータの予算とスリムなアーキテクチャにより、Ovis-Imageは中程度のメモリを持つ単一のハイエンドGPUに収まり、低レイテンシの対話的利用をサポートするとともに、バッチ生成サービングへのスケーリングにも対応します。これにより、数百億パラメータのモデルが現実的でないアプリケーションにおいて、フロンティア級に迫るテキストレンダリングを実現します。

このパイプラインは Ovis-Image Team によって提供されました。元のコードベースは[こちら](https://github.com/AIDC-AI/Ovis-Image)で確認できます。

利用可能なモデル:

| モデル | 推奨されるdtype |
|:-----:|:-----------------:|
| [`AIDC-AI/Ovis-Image-7B`](https://huggingface.co/AIDC-AI/Ovis-Image-7B) | `torch.bfloat16` |

詳細については、[こちら](https://huggingface.co/collections/AIDC-AI/ovis-image)のコレクションを参照してください。

## OvisImagePipeline[[diffusers.OvisImagePipeline]]

#### diffusers.OvisImagePipeline[[diffusers.OvisImagePipeline]]

```python
diffusers.OvisImagePipeline(scheduler: FlowMatchEulerDiscreteScheduler, vae: AutoencoderKL, text_encoder: Qwen3Model, tokenizer: Qwen2Tokenizer, transformer: OvisImageTransformer2DModel)
```

[ソース](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/ovis_image/pipeline_ovis_image.py#L129)

**パラメータ:**

transformer ([OvisImageTransformer2DModel](/docs/diffusers/v0.43.0/ja/api/models/ovisimage_transformer2d#diffusers.OvisImageTransformer2DModel)) : エンコードされた画像潜在変数をデノイズするための条件付き Transformer (MMDiT) アーキテクチャ。

scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/v0.43.0/ja/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラー。

vae ([AutoencoderKL](/docs/diffusers/v0.43.0/ja/api/models/autoencoderkl#diffusers.AutoencoderKL)) : 画像を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ（VAE）モデル。

text_encoder (`Qwen3Model`) : クラス [Qwen3Model](https://huggingface.co/docs/transformers/en/model_doc/qwen3#transformers.Qwen3Model) のテキストエンコーダー。

tokenizer (`Qwen2TokenizerFast`) : クラス [Qwen2TokenizerFast](https://huggingface.co/docs/transformers/en/model_doc/qwen2#transformers.Qwen2TokenizerFast) の Tokenizer。

テキストから画像を生成するためのOvis-Imageパイプライン。

参考: https://github.com/AIDC-AI/Ovis-Image

#### __call__[[diffusers.OvisImagePipeline.__call__]]

```python
__call__(prompt: str | list[str] = None, negative_prompt: str | list[str] = '', guidance_scale: float = 5.0, height: int | None = None, width: int | None = None, num_inference_steps: int = 50, sigmas: list[float] | None = None, num_images_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.FloatTensor] = None, prompt_embeds: typing.Optional[torch.FloatTensor] = None, negative_prompt_embeds: typing.Optional[torch.FloatTensor] = None, output_type: str | None = 'pil', return_dict: bool = True, joint_attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 256)
```

[ソース](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/ovis_image/pipeline_ovis_image.py#L457)

**パラメータ:**

prompt (`str` または `list[str]`、*省略可*) : 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。

negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。定義されていない場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイドを使用していない場合は無視されます（`guidance_scale` が `1` 以下の場合に無視されます）。

guidance_scale (`float`、*任意*、デフォルト値は 1.0) : `guidance_scale` > 1 かつ `negative_prompt` が指定されている場合、True に設定すると classifier-free guidance（guidance scale）が有効になります。

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`、*任意*、デフォルト値は 50) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。

sigmas (`list[float]`, *任意*) : `set_timesteps` メソッドで `sigmas` 引数をサポートするスケジューラーにおいて、デノイジングプロセスに使用するカスタムシグマ。`num_inference_steps` が渡された場合のデフォルトの動作が使用されます。

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

generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための [torch ジェネレーター](https://pytorch.org/docs/stable/generated/torch.Generator.html) 1 つまたはそのリスト。

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

prompt_embeds (`torch.FloatTensor`、*任意*) : 事前に生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを簡単に実行できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。

negative_prompt_embeds (`torch.FloatTensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを簡単に実行できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。

output_type (`str`、*任意*、デフォルトは `"pil"`) : 生成画像の出力形式。[PIL](https://pillow.readthedocs.io/en/stable/)（`PIL.Image.Image`）または `np.array` から選択します。

return_dict (`bool`、*任意*、デフォルトは`True`) : 通常のタプルではなく`~pipelines.flux.FluxPipelineOutput`を返すかどうか。

joint_attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `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`、デフォルトは 512) : `prompt` に使用する最大シーケンス長。

**戻り値:** [OvisImagePipelineOutput](/docs/diffusers/v0.43.0/ja/api/pipelines/ovis_image#diffusers.pipelines.ovis_image.OvisImagePipelineOutput) または `tuple`

`return_dict` が True の場合は [OvisImagePipelineOutput](/docs/diffusers/v0.43.0/ja/api/pipelines/ovis_image#diffusers.pipelines.ovis_image.OvisImagePipelineOutput)、それ以外の場合は `tuple` を返します。tuple を返す場合、最初の要素は生成された画像のリストです。

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

例:
```py
>>> import torch
>>> from diffusers import OvisImagePipeline

>>> pipe = OvisImagePipeline.from_pretrained("AIDC-AI/Ovis-Image-7B", torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")
>>> prompt = 'A creative 3D artistic render where the text "OVIS-IMAGE" is written in a bold, expressive handwritten brush style using thick, wet oil paint. The paint is a mix of vibrant rainbow colors (red, blue, yellow) swirling together like toothpaste or impasto art. You can see the ridges of the brush bristles and the glossy, wet texture of the paint. The background is a clean artist's canvas. Dynamic lighting creates soft shadows behind the floating paint strokes. Colorful, expressive, tactile texture, 4k detail.'
>>> image = pipe(prompt, negative_prompt="", num_inference_steps=50, guidance_scale=5.0).images[0]
>>> image.save("ovis_image.png")
```

#### encode_prompt[[diffusers.OvisImagePipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, device: typing.Optional[torch.device] = None, num_images_per_prompt: int = 1, max_sequence_length: int = 256, prompt_embeds: typing.Optional[torch.FloatTensor] = None, negative_prompt_embeds: typing.Optional[torch.FloatTensor] = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/ovis_image/pipeline_ovis_image.py#L269)

**パラメータ:**

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

negative_prompt (`str` または `list[str]`、*任意*) : 画像生成をガイドしないプロンプトです。`do_classifier_free_guidance` が `True` の場合のみ使用されます。定義されていない場合、空の文字列が使用されます。

do_classifier_free_guidance (`bool`、*任意*、デフォルトは`True`) : classifier-free guidance 用に`negative_prompt`もエンコードするかどうか。

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

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

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

prompt_embeds (`torch.FloatTensor`、*任意*) : 事前に生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを簡単に実行できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。

negative_prompt_embeds (`torch.FloatTensor`、*任意*) : 事前に生成されたネガティブテキストの埋め込み。指定されない場合、`negative_prompt`から生成されます。

## OvisImagePipelineOutput[[diffusers.pipelines.ovis_image.OvisImagePipelineOutput]]

#### diffusers.pipelines.ovis_image.OvisImagePipelineOutput[[diffusers.pipelines.ovis_image.OvisImagePipelineOutput]]

```python
diffusers.pipelines.ovis_image.OvisImagePipelineOutput(images: list[PIL.Image.Image, numpy.ndarray])
```

[ソース](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/pipelines/ovis_image/pipeline_output.py#L24)

**パラメータ:**

images (`list[PIL.Image.Image]` または `np.ndarray`) : 長さ `batch_size` のデノイズ済み PIL イメージのリスト、または形状 `(batch_size, height, width, num_channels)` の numpy 配列。PIL イメージまたは numpy 配列は、拡散パイプラインのデノイズ済みイメージを表します。

Ovis-Image パイプライン用の出力クラスです。

