ComfyUI.Tokyo

サイト内検索 help
複数条件の場合はキーワードの間にスペースを入れてください。
例 ksampler controlnet

Ollama Generate 画像をテキストに

Ollama Generateに挑戦します。

Download Ollama

結構簡単に設定できました。

llama3.2-visionを設定しました。

Ollamaは、Cドライブに自動で設定されますが、ComfyUI でOllama Generateをワークフローに用いると自動でリンクしています。

使用ノード

ComfyUI + Ollama(llama3.2-vision) を使って、画像から自動で文章(プロンプト)を生成するワークフローです。

原理を整理します。

ワークフローの流れ

  1. Load Image ノード
    • 入力した画像を ComfyUI 内に読み込む。
    • ここでは「女性整備士が車を点検している写真」。
  2. Ollama Connectivity ノード
    • Ollama サーバー(http://127.0.0.1:11434)と接続。
    • モデルは llama3.2-vision:latest を指定。
    • このモデルは画像を解析できるマルチモーダル LLaMA です。
  3. 3. Ollama Generate ノード
    • 画像データをモデルに入力し、同時にテキスト指示(例: "Describe the image in detail.")を送る。
    • llama3.2-vision が 画像解析 → 言語化 を行い、テキストを出力。
    • 出力内容は「プロンプト」として利用できる。
  4. Show Text ノード
    • Ollama から返ってきたテキストを表示する。
    • 例: “The image shows a young woman working on a car in a garage…

生成の原理

  1. 画像を特徴量ベクトルに変換
    • llama3.2-vision の内部で、画像は CNN + Transformer 系のビジョンエンコーダで処理され、意味情報(物体、人物、シーン、関係性など)を抽出。
  2. テキスト指示に基づく出力
    • "Describe the image" という指示に従い、モデルは抽出した特徴を自然言語で表現する。
    • このとき、学習済みの知識に基づき「人物」「背景」「動作」などを文章化。
  3. 結果を ComfyUI に返す
    • 文章化された出力が、そのまま「画像から生成されたプロンプト」として利用できる。

まとめると

この仕組みは 「画像を入力 → マルチモーダル LLM が解析 → テキスト化 → ComfyUI に表示」 という流れで動いています。

生成されたテキストはそのまま 次の画像生成用プロンプト に流用できるので、

  • 「自動キャプション生成」
  • 「画像からプロンプト作成して再生成」

などに応用できます。

Workflow

生成されたプロンプト

  • The image shows a young woman working on a car in a garage. The woman is wearing a black and blue uniform. She is leaning over the hood of a car, looking into the engine. She is holding a tool in her right hand and has a white glove on her left hand. The engine is open and the hood is propped up. The background shows a garage with other cars and tools. The image suggests that the woman is a mechanic or a technician working on a car.

手直ししたプロンプト

  • This photo shows a young Caucasian woman working on a car in a repair shop, smiling for the camera. The woman, wearing a black and blue uniform, is checking the engine oil. She holds a short, very thin stainless steel dipstick in her left hand and, wearing a white glove in her right hand, is wiping away any slight dirt from the tip of the dipstick. The engine is open, and the hood is propped up by a very thin hood stay. In the background, the inside of the repair shop can be seen, with other cars and tools inside. From the photo, the woman is likely a mechanic or technician working on a car.

ちなみに、ChatGTPに画像を見てもらいました。

  • A professional female mechanic working in a car repair shop, smiling while checking the engine of a car with the hood open. She is wearing a black and blue work uniform and white gloves, holding a dipstick to check the engine oil. The background shows tools, workbenches, and another car inside the brightly lit garage. Realistic photography, high detail, natural lighting, candid moment.

Workflow

生成画像

元の画像

Ollama Generate は、役に立ちそうですね。


Link