AI-ToolkitでZ-Image Turbo用の顔LoRA作成 その1 学習用画像準備編
AI-ToolkitでZ-Image Turbo用の顔LoRAを作成する手順のうち、学習用の画像を選ぶ場合の注意点などを説明します。
はじめに・注意事項
本記事は、AI画像生成における顔LoRA作成の技術的な解説を目的としています。
実在する人物の顔写真を使用する場合は、必ず本人の許可を得た画像のみを使用してください。
また、第三者へのなりすまし、誹謗中傷、ディープフェイク、権利侵害、公序良俗に反する用途など、他者に迷惑や被害を与える目的での利用は絶対に行わないでください。
使用するモデル・サービスの利用規約や、各国の法律を確認したうえで、自己責任でご利用ください。
学習元画像の著作権にもご注意ください。
芸能人写真・有料写真集・転載画像など、著作権や利用権に問題のある画像の使用にもご注意ください。
まず、顔写真1枚を元に、バリエーションを変えた画像を30枚用意します。
私は、Google Flowを使用して、バリエーションを変えた画像を生成しています。
※顔LoRAの場合、20枚構成で十分という説もあるのですが、30枚構成の場合で説明します。
Google Flowで、元の画像を参照して髪型や服装を変えた画像を生成しても、元の画像の顔と似てないことがあります。
30種類のバリエーションで、各8枚~12枚ずつ生成して、できるだけ元の画像に顔が似ている画像を各1枚選ぶので、合計300枚くらい画像を生成します。
Google Flowは無料でも利用できますが、もしかしたら、画像を30枚用意する前に、生成回数の上限に達してしまうかもしれません。
私は、有料のGoogle AI Proに加入していますが、今のところ、顔LoRA用の画像を生成していて、Nano Banana 2なら上限に達したことはありません。
Nano Banana Proはすぐ上限に達してしまいますが、使用する画像は1024x1024サイズなので、Nano Banana 2で十分です。
元になる顔写真は、ChatGPTで生成した、架空の日本人女性の画像を使用しました。
どこかで見たような気が・・・?
架空の俺の嫁!

この画像を元に、以下のようにバリエーションを変えた画像を30枚用意します。
※元の画像は30枚の中に入っていません。

どのような構成で30枚を用意すれば良いかは、Geminiに教えてもらいました。
【1】真顔〜かすかな微笑み:基本骨格の学習(計18枚)
【2】歯が見えるほどの笑い:笑顔のバリエーション(計8枚)
【3】大笑い・目を閉じる:表情の可動域(計4枚)
いっそのこと、画像生成AIに投げるプロンプトも作ってと、Geminiに作ってもらいました。
それを、使いやすいように編集したプロンプトがこちらです。
コメント(/* */)も含めてそのまま1行ずつコピペし、画像生成AIで使用できます。
/* 1. 正面、真顔、顔アップ、黒髪ショートヘア、白Tシャツ、シンプル背景 */ A high-quality photo capturing the face of the woman in a strict close-up framing (70-80% of the frame). She looks directly at the camera with a neutral, calm expression. She has short black hair, wearing a simple white t-shirt. Natural, soft light against a plain background.
/* 2. わずかな右斜め、かすかな微笑み、顔アップ、金髪セミロング、カフェ */ A close-up photo of the woman, turned slightly to the right, with a soft, slight smile. Her hair is now shoulder-length blonde, and she is wearing a simple grey knit sweater. The background is a softly blurred interior of a sunlit cafe.
/* 3. 右向き、真顔、顔アップ、赤髪ロング、ポニーテール、公園 */ A detailed face shot of the woman in profile, looking to the right with a neutral expression. She has long, dark red hair tied into a high ponytail. She wears a simple blue denim shirt. Blurred greenery in the background (outdoors).
/* 4. 左向き、かすかな微笑み、顔アップ、ダークブラウンのボブカット、オフィス */ A close-up photograph capturing the woman from a slight left-side angle, showing a soft, gentle smile. Her hair is cut into a dark brown bob. She wears a light-striped blouse. The blurred background is a modern office environment.
/* 5. 上向き、真顔、顔アップ、ピンク髪ロング、夜の街 */ A low-angle shot looking up at the face of the woman. She looks up with a serious, neutral expression. She has long pink hair, wearing a black hoodie. The background shows blurred city lights at night.
/* 6. 正面、真顔、バストアップ、黒髪ロング、お団子ヘア、リビング */ A bust-up shot of the woman, looking directly at the camera with a calm, neutral expression. Her dark hair is styled into a bun. She wears a simple grey t-shirt. The background is a gently blurred cozy living room.
/* 7. 正面、かすかな微笑み、バストアップ、シルバーヘア、図書室 */ A bust-up photograph capturing the woman in soft focus. She has a faint smile. Her hair is short and silver-grey. She wears a white blouse. The background is a library with blurred wooden bookshelves.
/* 8. 右向き、真顔、バストアップ、茶髪ツインテール、スタジオ */ A bust-up photo of the woman from a three-quarter right-side angle. She has a neutral expression. Her hair is tied into medium-length brown pigtails. She wears a light grey sweatshirt in a simple studio setting.
/* 9. 左向き、かすかな微笑み、バストアップ、ロングヘア、ウェーブ、庭 */ A bust-up photograph of the woman from a left-side profile angle. She has a subtle smile. Her long, dark brown hair has soft waves. She wears a simple light blue dress. The background is a lush, blurred garden in the afternoon.
/* 10. 下向き、真顔、バストアップ、緑髪ショート、レザージャケット */ A photograph from a slight high-angle, looking down at the bust-up of the woman. She has a neutral, focused expression. Her hair is short and forest green. She is wearing a black leather jacket against a concrete wall.
/* 11. 正面、真顔、上半身、青髪ミディアム、白Tシャツ、キッチン */ An upper-body shot (waist-up) of the woman, looking directly at the camera with a neutral expression. Her hair is medium-length, wavy blue. She wears a simple white t-shirt and a dark cardigan. The background is a softly blurred modern kitchen.
/* 12. 左向き、かすかな微笑み、上半身、オレンジヘア、ベリーショート、ジム */ An upper-body shot capturing the woman from a three-quarter left-side angle. She has a soft smile. Her hair is an orange pixie cut. She wears black athletic wear and a sports bra. The blurred background is a gym.
/* 13. 正面、かすかな微笑み、ドアップ、パープルヘア、編み込み */ An extreme close-up shot focusing tightly on the face of the woman. She looks at the viewer with a gentle smile. Her dark hair is styled with complex purple braids. Natural light, simple background.
/* 14. わずかな右斜め、真顔、ドアップ、アッシュグレーヘア、都会の風景 */ A tight face shot of the woman from a subtle right angle, maintaining a neutral expression. Her hair is short and ash grey. She wears a black t-shirt against a blurred, busy urban landscape in daylight.
/* 15. 下向き、真顔、ドアップ、ライトブルーヘア、ロング、セーター */ A detailed high-angle close-up looking down at the face of the woman. She looks forward with a serious, calm expression. Her hair is long, straight light blue. Soft natural light, blurred background.
/* 16. 正面、かすかな微笑み、バストアップ、カーリーヘア、ブラウン、室内 */ A bust-up shot of the woman looking at the camera with a gentle smile. Her hair is short and curly, brown. She wears a warm-toned knit top in a cozy, sunlit room.
/* 17. 右向き、かすかな微笑み、上半身、金髪、サイドポニー、田舎の景色 */ A waist-up shot of the woman from a three-quarter right-side angle, showing a subtle, happy smile. Her blonde hair is tied into a side ponytail. She wears a floral sundress. The background is a gently blurred rural landscape.
/* 18. 見下ろす、正面、真顔、全身、黒髪ロング、ストリート */ A full-body photograph from a slight high-angle, looking down at the woman. She looks forward with a serious, neutral expression. Her hair is long, straight black. She wears a denim jacket and dark pants against a blurred street background.
/* 19. 正面、歯が見える笑い、ドアップ、黒髪ロング、ストレート */ A tight face shot (70-80% of the frame) of the woman, looking directly at the camera with a wide, open-mouthed smile, showing teeth. Her long black hair is straight and styled simply. Soft, bright light against a plain background.
/* 20. わずかな右斜め、歯が見える笑い、ドアップ、金髪ショート、ビーチ */ A close-up shot capturing the woman from a slight right angle, smiling broadly with teeth visible. Her short blonde hair is messy from the breeze. She is on a sunlit beach with a blurred ocean background.
/* 21. 右向き、歯が見える笑い、ドアップ、赤髪ボブ、フェス */ A detailed face shot of the woman from a three-quarter right profile angle, showing a joyful, wide smile with teeth. Her hair is dark red, cut in a bob. The background is a blurred outdoor music festival with crowd elements.
/* 22. 正面、歯が見える笑い、バストアップ、茶髪ポニーテール、パーカー */ A bust-up photograph of the woman looking at the camera with a genuine, beaming smile showing teeth. Her brown hair is in a ponytail. She wears a simple grey hoodie against a soft, simple background.
/* 23. 正面、歯が見える笑い、バストアップ、シルバーヘア、カーリー、パーティー */ A bust-up shot of the woman smiling joyfully at the camera with teeth visible. Her hair is short, curly silver-grey. She wears a simple black dress in a festive, blurred indoor party setting with lights.
/* 24. 左向き、歯が見える笑い、バストアップ、ピンク髪ロング、柔らかい光 */ A bust-up photograph of the woman from a three-quarter left-side angle, smiling broadly and happily with teeth shown. Her long pink hair is styled with soft waves. Natural, soft light, plain background.
/* 25. 正面、歯が見える笑い、上半身、緑髪ショート、カジュアル室内 */ A waist-up shot of the woman looking at the camera with a joyful, wide smile showing teeth. Her hair is short and vibrant green. She wears a plaid shirt in a casual, softly blurred living room.
/* 26. 見下ろす、正面、歯が見える笑い、全身、青髪ミディアム、公園 */ A full-body photograph from a slight high-angle looking down at the woman, smiling broadly and happily at the camera with teeth shown. Her hair is medium-length blue. She wears a simple white t-shirt and jeans in a grassy park.
/* 27. 正面、大笑い、ドアップ、黒髪ロング、お団子、幸せな表情 */ A tight face shot (70-80% of the frame) of the woman looking directly at the camera, laughing uncontrollably with her mouth wide open and eyes crinkled. Her hair is styled in a bun. White blouse, warm light.
/* 28. 左向き、大笑い・目を閉じる、ドアップ、金髪セミロング、楽しい会話 */ A detailed close-up shot capturing the woman from a three-quarter left angle. She is laughing hysterically with her eyes completely closed and mouth wide open. Her shoulder-length blonde hair is loose. Blurred background of a happy social gathering.
/* 29. 正面、大笑い、バストアップ、茶髪ツインテール、パーカー */ A bust-up photograph of the woman beaming at the camera while laughing heartily, mouth wide open. Her brown hair is in pigtails. She wears a light blue hoodie in a simple, brightly lit room.
/* 30. 右向き、大笑い・目を閉じる、上半身、赤髪ロング、カジュアル屋外 */ A waist-up shot capturing the woman from a three-quarter right angle, laughing with intense joy, mouth wide open and eyes tightly shut. Her long red hair falls loose. Blurred casual outdoor setting in the afternoon.
このプロンプトを、AI-Toolkitで使用するキャプション用に、30個のテキストファイルに分割したものを添付しますので、ご利用ください。
私が実際に顔LoRAを作成して分かった、画像を選ぶ際の注意点です。
画像サイズは1024x1024の正方形の画像にする。
GeminiやChatGPTに尋ねたら、AI-Toolkitで設定する画像サイズは、顔LoRAの場合、512x512で十分とのことです。
ですが、512x512だと画像自体が粗くなるため、用意する画像を1024x1024にして、AI-Toolkitの設定を512x512にすれば良いそうです。
実際に作成したLoRAを、Z-Image Turboで使用して画像生成してみたところ、512x512でも問題なく、学習に使用した画像に似た顔になりました。
Windows 11 Pro、RTX 5060 Ti 16GB、メインメモリ64GBの環境で、LoRA学習用の画像30枚、AI-Toolkitの画像サイズ設定を512x512にして、3000steps学習すると、LoRA完成まで約1時間半ほどかかります。
1024x1024に設定すると、512x512に設定した場合に比べて画素数が4倍になるため、LoRA学習にかかる時間も約4倍になると予想されます。
(試すのにも時間がかかりすぎるので、未確認です。)元の画像と顔が似ている画像を選ぶ。
当たり前のことなのですが、ここで妥協すると失敗してしまうので、できる限り、元の画像と顔が似ているものを選びましょう。
大笑いしている顔は、真顔と似てないのは仕方がないので、想像でこんな顔になるだろうと思うものを、好みで選んでOKです。キャプションは必ずつける。
画像1枚につき1つ、画像を説明するキャプションを書いたテキストファイルを作成します。
私が一番最初にLoRAを作成したとき、キャプション無しで作成してみたのですが、背景が屋外の緑の画像が多いせいか、作成したLoRAを適用して生成した画像が、背景が屋外で緑の画像が多く生成されるようになってしまいました。
例えば、初音ミクのように、髪型や髪色に特徴があり、キャラクターとして固定したい場合は、学習用の画像を、すべて髪型や髪色が同じになっているものにして、キャプションを書かないことで固定できます。
髪型や髪色などを固定したい → キャプションに髪型や髪色などを書かない
髪型や髪色などをプロンプトで変えたい → キャプションに髪型や髪色などを書く画像とキャプションは必ず一致させる。
これも当たり前なのですが、画像の顔は左向きなのに、キャプションに「右を向いている」と書いてあると、作成したLoRAを適用して生成した画像の顔の向きが、プロンプトで指定した通りにならないことがあります。
髪型、髪色、顔の表情、向き、服装、背景なども、画像とキャプションを一致させます。顔の向きと体の向きが同じ画像を選ぶ。
例えば、画面に向かって顔だけ右向きで、体が正面向きの画像を選ぶと失敗します。
私はこれで失敗して、顔が正面と左向きにはなるのに、プロンプトで指定しても、どうやっても顔が右向きにならないLoRAになってしまいました。肩から腕にかけてのラインが分かりにくい画像は避ける。
肩から腕のラインが分かりにくい画像があると、作成したLoRAを適用して生成した画像が、肩幅と頭の大きさのバランスが崩れてしまうことがあります。
肩幅に比べて、頭が大きくなりすぎたりします。
どのような画像を選べば良いのか、実際にGoogle Flowで生成した画像で説明します。
緑色で囲んだ画像が、LoRA学習用に選択した画像です。
赤色で囲んだ画像は、キャプションと逆向きなのでNGです。
黄色で囲んだ画像は、顔は右向きですが、体が正面向きなのでNGです。

次も、緑色で囲んだ画像が、LoRA学習用に選択した画像です。
とても微妙なのですが、赤色で囲んだ画像は、肩幅がギリギリで入っていて、肩から腕のラインが分かりにくくなっています。
このような画像を選ぶと、作成したLoRAを適用して生成した画像が、肩幅に比べて、頭が大きくなりすぎたりします。

学習用の画像が用意できたら、次はAI-Toolkitで顔LoRAを作成する手順を説明します。