なにメモ

コンピュータビジョンや機械学習関係の話題を書き綴ると思うブログです。

Cool Japan Diffusion 2.1.1 の取扱説明書

はじめに

本記事では、2023/1/14に公開した画像生成AI、Cool Japan Diffusion 2.1.1 の取り扱い方について説明します。 まず、デモの使い方を説明します。 次に本格的に使うために、インストール方法をざっくり説明します。 その後、使い方の説明、特にプロンプトのテンプレートを説明します。 最後に、クリエイターの方々へ、ユーザの方々へメッセージをお送りします。

デモの使い方

Hugging Face上でデモを行っているので、そちらを使うのが楽です。 テキスト欄にgirlやboyなどを入力して生成してみてください。 (詳細は後日)

インストール方法

基本的には、Web UIを想定しています。 ほとんど、Cool Japan Diffusion 2.1.1 Beta と変わらないため、 こちらの記事を参考にすると良いかもしれません。 Safetensors形式にも対応したので、安全性が気になる人はこちらを使ってください。

本格的な使い方

パソコンからWeb UIのアドレスにアクセスしてください。 パソコンでは次のような画面が出てきます。

Text-to-Imageの使い方

Text-to-Imageを使うと、文章から画像を生成することができます。この文章のことをプロンプトといいます。また、生成される画像の中に含まれてほしくない文章をネガティブプロンプトといいます。 Cool Japan Diffusionのプロンプト形式はNovel AI Diffusionなどとは全く違います。 これは研究用途以外には倫理的問題のあるデータセットであるDanbooruデータセットを含んでいないためです。 Cool Japan Diffusionのプロンプト形式は通常のStable Diffusionと同じものだと考えてください。このため、他のモデルやサービスと違って手軽さはありません。 一方で、基本的には形式に従って入力すれば、かんたんに出力することができます。 形式に従う必要はありませんが、手軽に楽しむためには形式をコピー・アンド・ペーストすることをおすすめします。

Cool Japan Diffusionでは、日本の文化、クールジャパンを(イラストを含む)アニメ、マンガ、ゲームの3種類で大まかに分類して生成することができます。 まず、それぞれの例を紹介します。

prompt: anime, a portrait of a girl with blue short hair and red eyes, official art, 4k, detailed

negative prompt: (((deformed))), blurry, ((((bad anatomy)))), bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 2d, 3d, cg, text

prompt: manga, black and white manga style, shojo manga, a close up of a cool girl, official artwork, award winning manga style, 4k, detailed

negative prompt: (((deformed))), blurry, ((((bad anatomy)))), bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 2d, 3d, cg, text

prompt: game, final fantasy 15, elden ring, close up of a dragon, 4k, 8k, highly detailed

negative prompt: (((deformed))), blurry, ((((bad anatomy)))), bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 2d, 3d, cg, text

このようにプロンプトは長いですが、このプロンプトをベースに微妙に修正するだけでいろいろなバリエーションを生むことができます。

Cool Japan Diffusionのプロンプトは次のような形式をとっています。

クールジャパンの種類, 画風(作家名、作品名), 描写したい内容, フレーバーテキスト

例として具体的なプロンプトに当てはめてみます。

game(クールジャパンの種類), final fantasy 15, elden ring, (画風)close up of a dragon,(描写したい内容) 4k, 8k, highly detailed(フレーバーテキスト)

大まかにはこのような形式でいろんな画像を生成できます。なお、画風はなくても構いません。 付録に形式に使えるフレーズをまとめましたので、参考に使ってください。 ただし、画風に作品名や作家名を入れた場合、著作権を侵害するおそれがあることから、2つ以上混ぜたりしてください。 作品名や作家名はチートコマンドのようなものだと思ってください。

Image-to-Imageの使い方

Image-to-Imageとは、画像からプロンプトに沿った画像に変換する機能のことを言います。 Image-to-Imageを使うと、顔画像をアニメ化したり、ラフ画を具体化したりすることができます。

顔画像のアニメ化

Image-to-Imageを使うと、Meitsuのように自分の顔をアニメにすることができます。 img2imgのタブクリックして次の画面を開いてください。

例えば、次のような写真を用意します。

この写真は本機能のテストのために使ってもらって大丈夫です。 この目的であれば、SNS上に変換後の画像を公開しても、私は著作権や肖像権を行使しません。 なお、他の人の写真や絵に対してImage-to-Imageをかける行為は絶対しないでください著作権や肖像権を侵害するおそれがあります。

これを説明するプロンプトを作り、プロンプトの形式の描きたい内容として入力します。 プロンプトを考えるのがめんどくさい場合は、"Interrogate CLIP"ボタンを押してください。 ここではエヴァの画風にします。 Denoising strengthは0.5ぐらいがおすすめです。

prompt: anime, evangelion, a face of a man wearing a brown mask and black glasses in front of wooden wall, 4k, detailed

negative prompt: low quality, bad face, ((((bad anatomy)))), ((bad hand)), lowres, jpeg artifacts, 2d, 3d, cg, text

このようにエヴァに出てくるキャラっぽくなります。 他にもいろんなタイプや画風が試せます。次のは少女漫画っぽくする例とエルデンリングっぽくする例を紹介します。

prompt: manga, monochrome, black and white manga style, shoujo manga style, a face of a man wearing a white mask and black glasses in front of wooden wall, 4k, detailed

negative prompt: low quality, bad face, ((((bad anatomy)))), ((bad hand)), lowres, jpeg artifacts, 2d, 3d, cg, text

prompt: game, ((elden ring)), a face of a man wearing a white mask and black glasses in front of wooden wall, 4k, detailed

negative prompt: low quality, bad face, ((((bad anatomy)))), ((bad hand)), lowres, jpeg artifacts, 2d, 3d, cg, text

顔写真だけではなく、いろんなものに試してみてください。

ラフ画の具体化

画像を入れてプロンプトを入力するとできます。

(後日詳細を伝えます。)

プロンプトの形式

ここでは、生成したいものに応じて、プロンプトの作り方を説明します。

キャラクター編

基本的には、ネガティブプロンプトにbad anatomyを全力でいれてください。 ネガティブプロンプトに

(((deformed))), blurry, ((((bad anatomy)))), bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 2d, 3d, cg, text

を入れておけば、だいたい大丈夫だと思います。

キャラクターを表示するときに役立つカメラアングルとしては、portraitとfull bodyがあります。 キャラクターを横長に生成したい場合は、768x576 (4:3)の解像度で生成してください。 (Highreso. fixは不要です。)

prompt anime, a portrait of a girl with black short hair and red eyes wearing red kimono in a japanese shrine, from front side,, full color illustration, official art, 4k, detailed

negative prompt: (((deformed))), blurry, ((((bad anatomy)))), bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 2d, 3d, cg, text

キャラクターを縦長に生成したい場合は、576x768 (3:4)の解像度で生成してください。

prompt: anime, a full body of a girl with black short hair and red eyes wearing red kimono standing neutrally, from front side, gray background, good anatomy, good hands, full color illustration, official art, 4k, detailed

negative prompt: (((deformed))), blurry, ((((bad anatomy)))), bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 2d, 3d, cg, text

背景編

基本的には、ネガティブプロンプトにphotoを全力でいれてください。 ネガティブプロンプトに

(((deformed))), photo, people, girl, boy

を入れておけば、だいたい大丈夫だと思います。

背景を横長に生成したい場合は、768x576の解像度で生成してください。

prompt: anime, (shinkai makoto), mount fuji, official art, 4k, 8k, highly detailed

negative prompt: (((deformed))), photo, people, girl, boy

背景を縦長に生成したい場合は、576x768 (3:4)の解像度で生成してください。

prompt: anime, (shinkai makoto), Tokyo Sky Tree, 4k, 8k, highly detailed

negative prompt: (((deformed))), photo, people, girl, boy

ChatGPT編

一発ネタとして、プロンプトをChatGPTに考えさせることはできます。 例えば、このようにメガネを掛けた美少女のプロンプトを考えさせることができます。

このプロンプトを入力するとそれっぽいものが出てきます。なお、ネガティブプロンプトは別途入れてください。

prompt: Generate an image of a beautiful girl with glasses drawn in the style of Ilya Kuvshinov, as if she were a character in Evangelion.

negative prompt: low quality, bad face, ((((bad anatomy)))), ((bad hand)), lowres, jpeg artifacts, 2d, 3d, cg, text

ね、かんたんでしょ。

応用編

応用編として、東方シリーズのサウンドノベルの画面を雑に作ってみましょう。 シーンとしては博麗霊夢霧雨魔理沙が会話しているシーンとしてみましょう。

まず、切り抜きやすいようにシンプルな背景で博麗霊夢を生成します。

prompt: game, touhou project, a portrait of a beautiful girl with back long hair on ((gray background)), hakurei reimu, touhou project official artwork, 4k, detailed

negative prompt: low quality, bad face, ((((bad anatomy)))), ((bad hand)), lowres, jpeg artifacts, 2d, 3d, cg, text

次に、切り抜きやすいようにシンプルな背景で霧雨魔理沙を生成します。

prompt: game, touhou project, a portrait of a beautiful girl on ((gray background)), kirisame marisa, touhou project official artwork, 4k, detailed

negative prompt: low quality, bad face, ((((bad anatomy)))), ((bad hand)), lowres, jpeg artifacts, 2d, 3d, cg, text

そして、それっぽい背景である神社を生成します。

prompt: anime, shinkai makoto style, makoto shinkai style, 神社 in japan, 4k, 8k, highly detailed

negative prompt: photo, people

最後にPhotoshopで合成します。

完成しました。所要時間は30分もかかっていないと思います。 本当は顔の大きさとか色々考えて調整したほうが良いと思います。

公開にあたってのメッセージ

クリエイターの方々へ

私は先日、新海誠監督の最新作『すずめの戸締まり』を見てきました。 あの映画を見るまでは心のなかで創作業界に対する心配でいっぱいでした。 しかし、その心配は不要だと感じました。 『すずめの戸締まり』ほど日本人の心を揺さぶる物語はChatGPTとStable Diffusionではまだできないと感じました。 日本の創作業界はStable Diffusionのようなおもちゃで敗れるそんなやわなものではないと思っています。 ただ、近い未来、AIに負けてしまう危険はあると思っています。 覚悟を持って今できる行動をとってください。

ユーザの方々へ

Stable Diffusionを始めとする拡散モデルは包丁と同じです。人を育てることをできれば、人を傷つけることもできます。 包丁はなんのために存在しているのかを考えてください。 ひとえに人を育てるために使われるのです。 拡散モデルも同じです。人を傷つけるために使う力ではありません。 拡散モデルは現代科学の結晶であり、大いなる力を宿しています。

大いなる力には大いなる責任が伴う

この言葉を理解できない人は拡散モデルそのものを使うべきではありません。 この言葉を常に胸に当て、この大いなる力を活用してください。

ノブレスオブリージュ。貴方が今後も救世主たらんことを

付録

プロンプトの形式詳細