Krea 2 JSON/BBOX Layout LoRA

Krea 2 Raw 用の LoRA です。漫画1ページの設計図を JSON で書くと、そのとおりに描かせることができます。設計図には、コマ・人物・吹き出し・台詞(日本語)・漫符の位置(BBOX)を書きます。

  • コマ割りと配置:指示したコマの数・並びと、人物・吹き出しの位置に寄せて描く。
  • 日本語の台詞:text に書いた台詞を、吹き出しの中に読める日本語の縦書きで描く。
  • 人物ごとの LoRA:人物に付けた名前("lora": "character_1")の範囲だけに、別の人物 LoRA を当てられる(同梱の generate.py)。
  • ポーズ:人物ごとに pose で体勢・動作・表情を指定できる。
  • 漫符:汗・赤面・ぐるぐる目・涙・怒りマーク・集中線などを、指定したコマの人物のそばに描く。

English follows the Japanese section → English

これは Krea の公式モデルではなく、Krea が認めたものでもありません。Krea 2 Community License に従います(ライセンス)。

LoRA あり・なしの比較

同じ指示・同じシード(101 と 202)で、LoRA なしとありを並べました。選んだ結果ではありません。左端は指示した枠です(黒=コマ、赤=人物、青=文字、緑=吹き出し・漫符)。

例1:学校の朝 例2:ケーキ作り 例3:サッカー

  • LoRA なし:コマ割りは少し出ますが、指示の JSON の座標や断片をそのまま文字として描いてしまいます。吹き出しの中も崩れた文字になります。
  • LoRA あり:「おはよー!」「カバン忘れた…」「焼けたかな?」「大丈夫よ」「速い!」「ドカッ」が、指示した場所の近くに読める形で入ります。

指示は examples/ にあります(*.json が設計図、*.prompt.txt が実際にモデルへ渡す文、*_layout.png が枠の図)。

5つの目標と検証の結果

目標 結果
1. JSON/BBOX の指示に従う ○ LoRA なしより明らかに良い。元の漫画には届かない
2. 人物ごとに LoRA を切り替える ○ 入れ替えると見た目も入れ替わる。24か所で取り違えは0、はっきり再現できたのは22
3. 日本語の台詞を正しく描く ◎ 指示した台詞が読める形で入る。一致度は元の漫画の8割ほど
4. 人物 LoRA と同時にポーズを指定する ○ 体勢は12枚すべて指示どおり(人物 LoRA ありでは24か所中23)。人物の大きさは BBOX より小さくなりがち
5. 漫符を描き、指定の場所に置く ○ 21種のうち17〜19種が、指示したコマの人物のそばに描かれる

1・3. 配置と日本語(学習に使っていない80ページで測定)

学習に使っていない本の80ページの指示で生成し、検出器(Manga109 で学習した YOLO)で見つけたコマ・人物・文字の枠を、指示の BBOX と比べました(IoU、1が完全一致)。台詞は、絵の中の文字を全部 OCR で読み、指示の台詞といちばん近い読みとの一致度(1−編集距離/長さ)を取りました(75ページ・581行)。

コマ IoU 人物 IoU 文字 IoU 台詞の一致度 台詞が完全に一致
元の漫画(上限の目安) 0.724 0.630 0.571 0.714 32%
LoRA なし 0.196 0.122 0.067 0.188 2%
この LoRA 0.353 0.227 0.113 0.556 13%
  • コマの重なりは80ページ中65ページで LoRA なしより良くなりました(差 +0.156、95%区間 +0.120〜+0.196)。
  • 台詞は75ページ中69ページで良くなりました(差 +0.337、95%区間 +0.289〜+0.382)。元の漫画を同じ方法で読んだ値(0.714)は OCR の上限の目安で、その8割ほどに届いています。
  • 配置は元の漫画の半分ほどです。コマの数や位置はずれることがあります。

2. 人物ごとの LoRA

試験のために、架空の人物を2人作りました。A は緑の三つ編み・丸眼鏡・黄色いレインコート、B は白いツンツン頭・眼帯・オレンジのマフラー・紺のコートです。それぞれ Krea 2 本体で16枚描き、人物 LoRA を学習しました(examples/characters/)。設計図の人物の caption はどちらも「a person in casual clothes」にしてあり、見た目は人物 LoRA だけが決めます。同じ設計図で、人物 LoRA の当て方だけを変えています。

試験用の人物 A・B

領域ごとの LoRA(シード101) 領域ごとの LoRA(シード202)

  • 左の列は人物 LoRA なし(この LoRA だけ)、中と右は A と B の当てる場所を入れ替えたものです。
  • 1コマ(2人)と3コマ(1コマ目に1人、2コマ目にもう1人、3コマ目に2人)の2ページ × 2シードで、人物が出る24か所を見ました。A と B が取り違えられたところは0か所でした。特徴(髪・眼鏡・眼帯・服)がはっきり出たのは22か所です。残る2か所は、髪の色が出ないなど一部だけでした。
  • 台詞・吹き出し・コマ割りは、人物 LoRA を当てても保たれます。
  • 弱点:服やマフラーの色が少し混ざることがあります(コートの色が入れ替わるなど)。白黒のページでも、カラーで学習した人物 LoRA を当てると色が付きます。同じ人物が2回描かれたことが1度ありました。
  • 人物 LoRA が弱いと効きません。最初に作った弱い人物 LoRA(rank 16・400ステップ)では、ページ全体に当てても特徴がほとんど出ませんでした。人物 LoRA だけを当てた1枚の絵で、特徴がはっきり出ることを先に確かめてください。

4. ポーズ

1コマに1人、見た目は同じで pose だけを変えた6ページです(シード101)。

ポーズ

  • LoRA あり:手を上げて立つ・あぐら・右へ走る・仰向け・膝を抱えてしゃがむ・両手を上げて跳ぶ、の6種とも、シード101・202の両方で指示どおりの体勢になりました(12/12)。
  • LoRA なしでも体勢はおおむね出ますが、画面に座標の文字が描かれます。
  • 弱点:BBOX をコマいっぱいにしても、人物は小さく描かれがちです。上に細い余分なコマが入ることもあります。
  • 人物 LoRA を当てた場合(24か所)も、手を振る・腕を組む・走る・本を読む・指さして笑う・頭をかく、がほぼ指定どおりでした。外れたのは1か所で、走るはずの人物が立っていました(上の目標2の図)。

5. 漫符

21種の漫符を置いた試験ページ6枚です(シード101)。

漫符

各ページは4コマで、1コマに1種ずつ漫符を置いています(6ページ目は1コマ)。指示したコマ(読む順で対応させたもの)に、その漫符が描かれたかを2シードで数えました。

シード101 シード202
LoRA あり 19 / 21 17 / 21
  • 2シードとも出たもの(17種):汗の飛び散り、湯気、赤面、震え線、浮かぶハート、!、?、怒りマーク、ぐるぐる目、縦線(どんより)、涙、音符、キラキラ、集中線、スピード線、動線、衝撃。
  • 片方だけ:汗(大粒)、振動の線。
  • 出なかった:汗ばみ(肌のつや)、目がハート。
  • 置き場所:漫符は、指示したコマの人物の頭・顔・体のまわりに描かれます。ただ生成されたコマの形が指示とずれることがあるので、ページ上の座標(BBOX)とぴったり重なるとは限りません。ハートの瞳のように小さい記号は出にくいです。
  • LoRA なしでも、!・?・キラキラ・集中線などは描かれます(各シード8〜10種)。ただ画面じゅうに座標の文字が出て、コマ割りも崩れます。

使い方

1. 用意するもの

  • NVIDIA GPU(bf16 で VRAM 約45GB。人物 LoRA を使う場合も同じ)
  • Python 3.10 以上と、torch・diffusers(Krea2Pipeline が入った版。0.42.1 で確認)・transformers・peft・safetensors・Pillow
  • krea/Krea-2-Raw(本体。このリポジトリには含みません)
pip install torch diffusers transformers peft safetensors pillow huggingface_hub
hf download darask0/krea-2-json-bbox-layout-lora --local-dir krea-2-json-bbox-layout-lora
cd krea-2-json-bbox-layout-lora

本体は初回の実行時に自動で落ちてきます(--model に手元のフォルダを渡すこともできます)。

ファイル 中身
krea2_json_bbox_layout.safetensors この LoRA(rank 64、200MB)
generate.py 設計図から1枚生成する。人物ごとの LoRA にも対応
make_prompt.py 設計図を確かめて、モデルに渡す文と生成の大きさを出す
examples/ 例の設計図5つ(ex*=比較用、regional_*=人物ごとの LoRA 用)と、試験用の人物 LoRA 2つ(characters/、架空の人物、各100MB)
LICENSE.pdf・NOTICE.txt Krea 2 Community License と、その表示

2. 生成する

python generate.py examples/ex1_school.json -o ex1.png --seed 101
python generate.py examples/ex1_school.json -o ex1_nolora.png --seed 101 --no-lora   # 比べるとき

設定は 28ステップ・CFG 4.5・負の指示は空文字です(--steps・--guidance で変えられます)。1枚 約30秒(RTX PRO 6000 Blackwell)。

3. 人物ごとに LoRA を当てる

python generate.py layout.json -o out.png \
  --region character_1=alice.safetensors:1.0 \
  --region character_2=bob.safetensors:1.0

--region 名前=ファイル:強さ で、設計図の中で "lora": "名前" の人物の BBOX の中だけに、その人物 LoRA を当てます。範囲のふちはぼかしてあります。各ステップで、人物 LoRA ごとにモデルをもう2回(指示あり・なし)動かすので、人物が2人なら3倍ほど時間がかかります。

人物 LoRA は Krea 2 Raw 用(diffusers の load_lora_adapter で読める形)が必要です。試しに使える人物 LoRA を2つ同梱しています(上の A・B)。

python generate.py examples/regional_1panel.json -o rg.png --seed 101 \
  --region character_1=examples/characters/test_character_A.safetensors:1.0 \
  --region character_2=examples/characters/test_character_B.safetensors:1.0

4. 設計図を書く

座標はピクセルで [左, 上, 右, 下]、原点は左上です。

python make_prompt.py layout.json --preview layout.png

設計図の誤り(コマの ID・読む順・枠のはみ出し・吹き出しの参照など)を確かめ、モデルに渡す文(krea_layout_v1 {...})を出します。座標は 0〜1000 に直り、項目の並びも学習と同じにそろえます。--preview で枠の図を描きます。生成の大きさは、縦横比を保って 0.8〜1.1 メガピクセル(16の倍数)です。

5. プログラムから使う

import torch
from diffusers import Krea2Pipeline
from safetensors.torch import load_file
from make_prompt import load

layout, prompt, (W, H) = load("examples/ex1_school.json")
pipe = Krea2Pipeline.from_pretrained("krea/Krea-2-Raw", torch_dtype=torch.bfloat16).to("cuda")
pipe.transformer.load_lora_adapter(load_file("krea2_json_bbox_layout.safetensors"), prefix=None, adapter_name="layout")
image = pipe(prompt=prompt, negative_prompt="", width=W, height=H, num_inference_steps=28, guidance_scale=4.5,
             max_sequence_length=8192,  # the layout prompt is long; the default 512 cuts it off
             generator=torch.Generator("cuda").manual_seed(101)).images[0]
image.save("out.png")

max_sequence_length=8192 を必ず渡してください(既定の512では設計図の途中で切れます)。generate.py は学習のときと同じく、指示の埋め込みから pad を除いて渡します。上の pipe(...) は diffusers の標準の処理なので、結果は少し変わることがあります。検証の数値は generate.py と同じ処理で出しました。

設計図(JSON)の書き方

全体

{
  "width": 864, "height": 1216,
  "summary": {"caption": "ページ全体を英語1文で(場面・人数・雰囲気、カラーか白黒か)"},
  "panels": [ {"id": "p1", "reading_order": 0, "bbox": [40, 40, 824, 420]} ],
  "items":  [ {"label": "character", "...": "..."} ]
}
欄 書くこと
width・height ページの大きさ(ピクセル)。どの縦横比でもかまいません。
summary.caption ページ全体を英語1文で。固有名詞は書かない。カラーか白黒か、コマの数も書くと効きます(例 A three-panel black-and-white manga page: ...)。
panels コマの一覧。id(p1…)、reading_order(0からの連番。日本の漫画の読む順=右上から左下)、bbox。
items コマの中身の一覧。読む順に並べます(コマの順 → コマの中は右上から)。

人物(label: "character")

{"label": "character", "caption": "a girl with short black hair in a navy school uniform with a red ribbon",
 "bbox": [480, 110, 800, 420], "panel_id": "p1", "character_id": "ex1/c1", "lora": "character_1",
 "pose": "upper body, waving one hand, smiling, looking to the left"}
欄 書くこと
caption コマが変わっても変わらない見た目(髪型・髪の色・服・持ち物)を英語の短い句で。同じ人物は全コマで同じ文にします。人物 LoRA を当てるなら、見た目は LoRA に任せて短くしてもかまいません。
pose そのコマでの体勢・動作・向き・視線・表情。英語の短い句をコンマで区切る。見た目は書かない。
bbox そのコマで見えている体の範囲。
panel_id どのコマにいるか。
character_id 同じ人物にはページ内の全コマで同じ ID。群衆には付けない。
lora character_1、character_2… を、ページで最初に出てきた順に。generate.py --region はこの名前で人物 LoRA を当てます。

吹き出し(label: "object")

{"label": "object", "kind": "speech_balloon", "caption": "a white manga speech balloon with a dark outline",
 "bbox": [330, 60, 470, 260], "panel_id": "p1", "id": "b1"}
kind caption(固定文)
speech_balloon(普通の吹き出し) a white manga speech balloon with a dark outline
thought_balloon(雲形) a cloud-shaped manga thought balloon
shout_balloon(ギザギザ・叫び) a spiky manga shout balloon
narration_box(四角のナレーション枠) a rectangular narration box

台詞から参照するので、吹き出しには id(b1…)を付けます。

文字(label: "text")

{"label": "text", "caption": "Japanese comic lettering", "text": "おはよー!",
 "bbox": [370, 80, 430, 240], "panel_id": "p1", "kind": "dialogue", "balloon_id": "b1", "speakers": ["character_1"]}
欄 書くこと
kind dialogue(台詞・心の声)、sound_effect(擬音・描き文字)、narration(ナレーション)
caption 台詞・ナレーションは Japanese comic lettering、擬音は Japanese manga sound-effect lettering。色は後ろにコンマで足す(例 Japanese manga sound-effect lettering, pink)。
text 描かせたい日本語。改行は入れない。短いほど正確です(10文字ほどまでが安定)。
bbox 文字の塊だけを囲む(吹き出しの枠ではなく)。縦書きなら縦長に。
balloon_id 吹き出しの中の台詞なら、その吹き出しの id。
speakers 話す人物の lora 名のリスト(例 ["character_1"])。
sfx_type(擬音だけ・任意) heartbeat 心拍、trembling 震え、impact 衝撃、motion 動き、contact 触れる、voice 声・息、environment 環境音、mimetic 擬態語
lettering(任意) bold_outlined 太字に白フチ、handwritten 手書き、glowing 発光、background_faint 背景に薄く、repeated 繰り返し

漫符・効果(label: "object")

{"label": "object", "kind": "sweat_drops", "caption": "a few large sweat drops beside the head",
 "bbox": [560, 500, 640, 600], "panel_id": "p2"}

kind と caption は下の表の組み合わせで書きます。caption の位置の語(above the head など)は、置きたい場所に合わせて変えてかまいません。BBOX は記号のまとまりに沿って小さく、集中線・スピード線はコマ全体を囲みます。吹き出しの中の「!」「?」は文字として書き、人物の近くに浮かぶものだけを漫符にします。

漫符・効果の一覧(56種類)
区分 日本語 kind caption(固定文)
感情記号(顔・頭のまわり) 汗(冷や汗・焦り) sweat_drops a few large sweat drops beside the head
感情記号(顔・頭のまわり) 大きな一粒の汗(気まずさ・あきれ) sweat_drops a single large sweat drop beside the head
感情記号(顔・頭のまわり) 飛び散る汗・水滴 droplets_splash sweat droplets flying off the head
感情記号(顔・頭のまわり) 赤面(頬の斜線) heavy_blush heavy blush lines across the cheeks
感情記号(顔・頭のまわり) 青ざめ(顔にかかる縦線) emotion_mark vertical pale lines over the face
感情記号(顔・頭のまわり) 浮かぶハート(好意・うっとり) floating_hearts small floating hearts around the head
感情記号(顔・頭のまわり) 目がハート heart_in_eyes heart-shaped pupils
感情記号(顔・頭のまわり) 割れたハート(失恋・ショック) emotion_mark a cracked heart symbol
感情記号(顔・頭のまわり) びっくりマーク(!) surprise_mark an exclamation mark above the head
感情記号(顔・頭のまわり) はてなマーク(?) question_mark a question mark above the head
感情記号(顔・頭のまわり) 頭上に複数の?(状況が飲み込めない) question_mark several question marks above the head
感情記号(顔・頭のまわり) !?(驚きと疑問が同時) surprise_mark an exclamation and question mark above the head
感情記号(顔・頭のまわり) 怒りマーク(青筋) anger_vein a cross-shaped anger vein mark on the forehead
感情記号(顔・頭のまわり) ぐるぐる目(混乱・目が回る) dizzy_eyes spiral dizzy eyes
感情記号(顔・頭のまわり) 頭上の渦・輪(目まい・クラクラ) emotion_mark a spinning swirl above the head
感情記号(顔・頭のまわり) 目が星(憧れ・興味) emotion_mark star-shaped sparkles in the eyes
感情記号(顔・頭のまわり) 白目(ギャグの驚き・放心) emotion_mark blank white eyes for comic shock
感情記号(顔・頭のまわり) 縦線(落ち込み・どんより・ドン引き) emotion_mark vertical gloom lines above the head
感情記号(顔・頭のまわり) 涙(滝涙・涙目を含む) emotion_mark streams of tears
感情記号(顔・頭のまわり) 目に浮かぶ涙(うるうる) emotion_mark small tears welling in the eyes
感情記号(顔・頭のまわり) 音符(上機嫌・鼻歌) emotion_mark small musical notes floating near the head
感情記号(顔・頭のまわり) キラキラ(期待・自信・美化) emotion_mark sparkles around the character
感情記号(顔・頭のまわり) ひらめき(電球・ピコーン) emotion_mark a small light bulb flash above the head
感情記号(顔・頭のまわり) 鼻ちょうちん・Zzz(居眠り) emotion_mark a snot bubble and floating Z letters for sleeping
感情記号(顔・頭のまわり) 魂が抜ける(放心・燃え尽き) emotion_mark a small ghostly soul floating out of the mouth
感情記号(顔・頭のまわり) ため息の吹き出し(ふぅ) emotion_mark a small puff of breath for a sigh
感情記号(顔・頭のまわり) ドキッ・心拍のマーク(緊張・ときめき) emotion_mark short radiating pulse marks near the chest
感情記号(顔・頭のまわり) 衝撃のトゲ・稲妻(頭上のギザ、髪が逆立つ) emotion_mark jagged lightning spikes above the head, hair standing on end
感情記号(顔・頭のまわり) 鼻血(興奮のギャグ表現) emotion_mark a comedic nosebleed
感情記号(顔・頭のまわり) 状態の紋(頭上の魔法陣・光輪・バフの印) emotion_mark a small glowing magic circle above the head
体の効果 汗ばみ(肌のつや汗) sweat_sheen glistening sweat sheen on the skin
体の効果 体に散る汗の粒(熱・興奮) droplets_splash small sweat beads scattered over the body
体の効果 湯気・荒い吐息(怒り・興奮・疲労) steam_breath puffs of steam rising from the head
体の効果 震え線(恐怖・寒さ・緊張) trembling_lines small trembling lines around the body
体の効果 振動の線(物・体の揺れ) vibration_marks vibration marks around the shaking object
動き・画面の効果 集中線 focus_lines radial focus lines converging on the subject
動き・画面の効果 スピード線(流線) speed_lines parallel speed lines across the panel
動き・画面の効果 落下の縦線 speed_lines vertical speed lines for falling
動き・画面の効果 動線(動きの軌跡) motion_lines motion lines trailing the moving limb
動き・画面の効果 動作の弧(手・腰・武器の軌跡) motion_lines curved motion arc following the swing
動き・画面の効果 残像(薄く残る前のポーズ) motion_lines faint afterimages of the previous pose
動き・画面の効果 走りの土煙 motion_lines a cloud of dust kicked up behind the runner
動き・画面の効果 衝撃(インパクト・爆発の放射) impact_burst a spiky impact burst at the point of contact
動き・画面の効果 接触のトゲ(当たった点から出る白いギザ) impact_burst small white spiky marks at the point of contact
動き・画面の効果 ベタフラッシュ(黒地の放射・衝撃や戦慄) focus_lines black background with white radiating flash lines
動き・画面の効果 ウニフラッシュ(白い放射・ひらめきや驚愕) focus_lines spiky white radial flash behind the character
動き・画面の効果 一斉に走る白線のフラッシュ(山場・絶頂・覚醒) focus_lines bright white lines bursting across the whole panel
背景・空気 花背負い(うっとり・美化の背景) emotion_mark decorative flowers in the background behind the character
背景・空気 キラキラの背景(華やか・憧れ) emotion_mark a sparkling background behind the character
背景・空気 泡・水玉の背景(ふんわり・夢見心地) emotion_mark soft round bubbles floating in the background
背景・空気 燃える闘志(背景の炎) emotion_mark flames rising behind the character
背景・空気 暗いオーラ(不穏・怒り・落ち込み) emotion_mark a dark wavy aura around the character
背景・空気 ガーン(背景の稲妻) emotion_mark a lightning bolt behind the character for shock
背景・空気 どんよりトーン(暗いグラデーション背景) emotion_mark dark gradient screentone background for a gloomy mood
背景・空気 空気の地(ピンク・紫のグラデーション、煙) emotion_mark soft pink and purple gradient background haze
背景・空気 催眠の波模様(同心円・渦の地) emotion_mark concentric hypnotic wave pattern in the background

よい結果を出すコツ

  • 学習データと同じ書き方にそろえる:吹き出し・漫符の caption は固定文、人物の caption は全コマで同じ文、項目は読む順。make_prompt.py を通すと並びがそろいます。
  • summary.caption にカラーか白黒か、コマの数を書く。
  • 台詞は短く。長い台詞は字が抜けたり、似た字に置き換わったりします。
  • 同じ指示でもシードで結果が大きく変わります。何枚か生成して選んでください。

限界

  • 配置の正確さは元の漫画の半分ほどです。コマの数がずれる、コマの位置が入れ替わる、ことがあります。
  • 台詞の一致度は0.556(元の漫画を同じ方法で読んで0.714)で、完全に一致する行は13%ほどです。字の抜け・似た字への置き換えがあるので、使う前に確かめてください。
  • 人物の大きさは BBOX に合わないことが多いです(特に大きな人物を1人だけ置くとき)。
  • 漫符のうち、汗ばみ(肌のつや)と目がハートは出ませんでした。漫符はコマの中の人物のそばに出ますが、ページ上の座標とはずれることがあります。
  • 人物 LoRA を当てると、服の色が人物の間で混ざることや、白黒のページに色が付くことがあります。人物 LoRA 自体が弱いと効きません。

学習の条件

項目 値
学習した本体 Krea 2 Raw(krea/Krea-2-Raw)
LoRA rank 64(alpha 64)、transformer の注意層(to_q・to_k・to_v・to_gate・to_out.0)だけ
学習率など 1e-4(AdamW)、バッチ2×勾配累積2、3000ステップ、bf16
データ 漫画のページ2,030枚と、その JSON/BBOX の注釈(モデルで下書きし、人が確認したもの)
画像の大きさ 縦横比を保って最大110万画素

評価には学習に使っていない本のページだけを使いました。目標2・4・5の試験と、このページの比較画像は、すべて架空の設計図から作りました。

ライセンス

  • この LoRA は Krea 2 Raw の派生物で、Krea 2 Community License Agreement(LICENSE.pdf)に従います。使う人・配る人はこの契約に拘束されます。年間売上100万米ドル以上の組織の商用利用には、Krea との別の契約が必要です。
  • Krea 2 is licensed under the Krea 2 Community License Agreement. For more information, visit https://krea.ai/krea-2-licensing. この LoRA は Krea 2 Raw を改変(追加学習)したものです(NOTICE.txt)。
  • 契約に含まれる Krea の Acceptable Use Policy を守ってください。このモデルを使ったサービスを公開する場合は、契約が求める内容のフィルター(不適切な指示・出力を止める仕組み)を用意してください。
  • 学習に使った画像には、Manga109(学術目的に限る)や、ネットで集めたイラスト(gelbooru)が含まれます。生成物をどう使うかは、それぞれの条件と法律に照らして、使う人が判断してください。

English

A LoRA for Krea 2 Raw that draws a manga page from a JSON layout. The layout gives the boxes (BBOX) for panels, characters, balloons, Japanese dialogue and manga effect marks (manpu).

  • Panels and placement: follows the requested panel count, panel order and character/balloon positions.
  • Japanese dialogue: writes the text you give, as readable vertical Japanese, inside the balloons.
  • Per-character LoRAs: applies a separate character LoRA only inside the boxes of the characters named by "lora": "character_1" etc. (generate.py --region).
  • Pose: set the body pose, action and expression per character with pose.
  • Manga effects: blush, spiral eyes, tears, sparkles, focus and speed lines, and more, placed in the requested panel next to the character.

Not an official Krea model and not endorsed by Krea. Licensed under the Krea 2 Community License (see License).

With vs. without LoRA. The images at the top use the same prompt and seeds (101, 202; not cherry-picked). The left column shows the requested boxes. Without the LoRA, Krea 2 prints the JSON coordinates as text in the image and the balloons hold garbled text. With the LoRA, the page gets clean balloons with the requested dialogue.

Results for the five goals

Goal Result
1. Follow the JSON/BBOX layout Clearly better than without the LoRA; about half of the real-page ceiling
2. Switch LoRA per character region Works: in 24 character slots the identity never landed on the wrong character; 22 were clearly right
3. Render the Japanese dialogue Readable; dialogue similarity reaches about 80% of the real-page score
4. Pose together with character LoRAs 12/12 poses as requested (23/24 with character LoRAs); figures are often smaller than the box
5. Draw manga marks in place 17–19 of 21 marks appear in the requested panel, next to the character

80 held-out pages (books not used for training). Boxes were found with a Manga109 YOLO detector and compared with the prompt by IoU. Dialogue was read with OCR anywhere on the page and matched to the requested lines (1 − edit distance / length; 75 pages, 581 lines).

Panel IoU Character IoU Text IoU Dialogue similarity Exact lines
Real page (ceiling) 0.724 0.630 0.571 0.714 32%
No LoRA 0.196 0.122 0.067 0.188 2%
This LoRA 0.353 0.227 0.113 0.556 13%

Paired differences vs. no LoRA: panel IoU +0.156 (95% CI +0.120 to +0.196; 65 wins / 13 losses); dialogue +0.337 (+0.289 to +0.382; 69 wins / 5 losses).

Per-character LoRAs. Two made-up characters (A: green braids, round glasses, yellow raincoat; B: white spiky hair, eyepatch, orange scarf, navy coat) were drawn with Krea 2 (16 images each) and trained as character LoRAs (examples/characters/). In the layout both characters have the same plain caption, a person in casual clothes, so only the LoRA decides the look. The images in the Japanese section swap which LoRA goes to character_1 and character_2. Across 2 pages × 2 seeds × 2 assignments (24 character slots), A and B were never swapped; 22 slots showed the character clearly and 2 only partly. Dialogue, balloons and panels stay in place, and each character keeps its own pose. Clothing colors sometimes mix, and color LoRAs add color to black-and-white pages. A weak character LoRA (rank 16, 400 steps) had almost no effect, so check that a character LoRA works on its own first.

python generate.py examples/regional_1panel.json -o rg.png --seed 101 \
  --region character_1=examples/characters/test_character_A.safetensors:1.0 \
  --region character_2=examples/characters/test_character_B.safetensors:1.0

Manga marks: 6 test pages with one mark per panel (21 marks). With the LoRA, 19/21 (seed 101) and 17/21 (seed 202) marks appeared in the requested panel, next to the character's head, face or body.

  • Both seeds: flying sweat, steam, blush, trembling lines, floating hearts, !, ?, anger vein, spiral eyes, gloom lines, tears, music notes, sparkles, focus lines, speed lines, motion lines, impact burst.
  • One seed: large sweat drops, vibration marks. Never: sweat sheen, heart-shaped pupils.
  • Marks follow the character in the generated panel, so they may not overlap the exact page coordinates when the panel shape drifts.
  • Without the LoRA some marks appear too (8–10 per seed), but the page fills with printed coordinates and the panels break.

Usage

Requirements: an NVIDIA GPU with about 45 GB of VRAM (bf16), Python 3.10+, torch, diffusers with Krea2Pipeline (tested with 0.42.1), transformers, peft, safetensors, Pillow. The base model krea/Krea-2-Raw is downloaded on first run and is not part of this repository.

pip install torch diffusers transformers peft safetensors pillow huggingface_hub
hf download darask0/krea-2-json-bbox-layout-lora --local-dir krea-2-json-bbox-layout-lora
cd krea-2-json-bbox-layout-lora

python generate.py examples/ex1_school.json -o ex1.png --seed 101             # with the LoRA
python generate.py examples/ex1_school.json -o ex1_nolora.png --no-lora      # base model, for comparison
python generate.py layout.json -o out.png \
  --region character_1=alice.safetensors:1.0 \
  --region character_2=bob.safetensors:1.0                                   # per-character LoRAs
python make_prompt.py layout.json --preview layout.png                       # check a layout, print the prompt
  • Settings: 28 steps, CFG 4.5, empty negative prompt.
  • --region ALIAS=FILE[:STRENGTH] applies a Krea 2 character LoRA inside the boxes of the characters whose lora is ALIAS (feathered mask). Each region adds two model passes per step.
  • make_prompt.py validates the layout (pixel coordinates [x1, y1, x2, y2], origin top left). It converts the boxes to 0–1000 and keeps the training key order. It prints krea_layout_v1 {...} and the generation size (same aspect ratio, 0.8–1.1 MP, multiples of 16).
  • generate.py drops prompt padding, as in training. Plain pipe(prompt=..., max_sequence_length=8192) also works (the default 512 cuts the layout off) but may differ slightly.

Layout fields

  • Page: width, height, summary.caption (one English sentence; say color or black-and-white and the panel count), panels[] with id, reading_order (Japanese order: top right to bottom left) and bbox.
  • character: caption (appearance, the same in every panel), pose (action, facing, expression), bbox, panel_id, character_id (same across panels), lora (character_1, character_2, … in order of first appearance; used by --region).
  • Balloons (object): speech_balloon / a white manga speech balloon with a dark outline, thought_balloon / a cloud-shaped manga thought balloon, shout_balloon / a spiky manga shout balloon, narration_box / a rectangular narration box. Give each an id.
  • text: kind (dialogue, sound_effect, narration), caption (Japanese comic lettering or Japanese manga sound-effect lettering, optional color after a comma), text (keep it short), bbox (the lettering only), balloon_id, speakers, optional sfx_type and lettering.
  • Manga effects (object): a kind + caption pair from the table in the Japanese section, for example sweat_drops + a few large sweat drops beside the head. Focus and speed lines cover the whole panel.

Limitations

  • Placement is about half of the real-page ceiling; panel counts and positions can be off.
  • Dialogue similarity is 0.556 (real pages: 0.714) and only ~13% of lines are exact; check the text.
  • Characters are often drawn smaller than their box.
  • Sweat sheen and heart-shaped pupils were not drawn; marks may drift from the exact page coordinates with their panel.
  • Per-character LoRAs can mix clothing colors between characters and add color to black-and-white pages; the character LoRA itself must be strong enough to show the character on its own.

Training

Krea 2 Raw; rank 64 LoRA on the transformer attention layers (to_q, to_k, to_v, to_gate, to_out.0); AdamW lr 1e-4, batch 2 × grad accumulation 2, 3000 steps, bf16; 2,030 manga pages with reviewed JSON/BBOX annotations, up to 1.1 MP at the original aspect ratio. Evaluation used only held-out books. All goal tests and README images use made-up layouts.

License

  • This LoRA is a Derivative of Krea 2 Raw and is distributed under the Krea 2 Community License Agreement (LICENSE.pdf); anyone using or redistributing it is bound by that agreement. Commercial use requires annual revenue under USD 1,000,000; above that, contact Krea.
  • Krea 2 is licensed under the Krea 2 Community License Agreement. For more information, visit https://krea.ai/krea-2-licensing. This LoRA is a modification (fine-tune) of Krea 2 Raw (NOTICE.txt).
  • Follow Krea's Acceptable Use Policy, and put the content filters the agreement requires in front of any public deployment.
  • Training images include Manga109 (academic use only) and illustrations collected from gelbooru. You are responsible for checking how you use the outputs.
Downloads last month
3
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for darask0/krea-2-json-bbox-layout-lora

Base model

krea/Krea-2-Raw
Adapter
(1,228)
this model