Size the default Jev aspect ratio from megapixels in in_value_1

This commit is contained in:
kantan-kanto
2026-09-26 19:00:01 +09:00
parent 40b2a5fa92
commit 6949a6f236
2 changed files with 19 additions and 15 deletions
+1 -1
View File
@@ -109,7 +109,7 @@ probs = jev.probabilities(it1, "Which orientation suits this prompt?", ["portrai
ot1 = f"{kind} (portrait: {probs['portrait']:.3f}, landscape: {probs['landscape']:.3f})"
```
The node's default script picks one of eight aspect ratios for the prompt in `it1`, outputs its width and height to `out_value_1` / `out_value_2`, and lists every ratio's probability in `out_text_1`.
The node's default script picks one of eight aspect ratios for the prompt in `it1`, sizes it to the megapixels in `in_value_1` (default `1.0` when unconnected; width and height rounded to multiples of 64), outputs the width and height to `out_value_1` / `out_value_2`, and lists every ratio's probability in `out_text_1`.
Notes:
- Each question takes one forward pass (about 1–1.5 s with a 4B–9B model on GPU); the first question also loads the model.
+18 -14
View File
@@ -874,23 +874,27 @@ class MultiOutputScriptJev(MultiOutputScript):
"# jev.choice(state, question, options) -> str\n"
"# jev.probabilities(state, question, options) -> {option: probability}\n"
"# jev.score(state, question, levels) -> float\n"
"# Example: pick an aspect ratio for the prompt in it1\n"
"sizes = {\n"
" \"1:1 (Square)\": (1024, 1024),\n"
" \"2:3 (Portrait Photo)\": (832, 1216),\n"
" \"3:2 (Photo)\": (1216, 832),\n"
" \"3:4 (Portrait Standard)\": (896, 1152),\n"
" \"4:3 (Standard)\": (1152, 896),\n"
" \"9:16 (Portrait Widescreen)\": (768, 1344),\n"
" \"16:9 (Widescreen)\": (1344, 768),\n"
" \"21:9 (Ultrawide)\": (1536, 640),\n"
"}\n"
"# Example: pick an aspect ratio for the prompt in it1 and size it to iv1 megapixels\n"
"megapixels = iv1 if iv1 > 0 else 1.0\n"
"multiple = 64\n"
"ratios = [\n"
" \"1:1 (Square)\",\n"
" \"2:3 (Portrait Photo)\",\n"
" \"3:2 (Photo)\",\n"
" \"3:4 (Portrait Standard)\",\n"
" \"4:3 (Standard)\",\n"
" \"9:16 (Portrait Widescreen)\",\n"
" \"16:9 (Widescreen)\",\n"
" \"21:9 (Ultrawide)\",\n"
"]\n"
"question = \"Which image aspect ratio best suits this prompt?\"\n"
"ratios = list(sizes)\n"
"best = jev.choice(it1, question, ratios)\n"
"probs = jev.probabilities(it1, question, ratios)\n"
"ov1, ov2 = sizes[best]\n"
"lines = [best]\n"
"rw, rh = best.split(\" \")[0].split(\":\")\n"
"pixels = megapixels * 1024 * 1024\n"
"ov1 = round(math.sqrt(pixels * int(rw) / int(rh)) / multiple) * multiple\n"
"ov2 = round(math.sqrt(pixels * int(rh) / int(rw)) / multiple) * multiple\n"
"lines = [f\"{best} -> {ov1}x{ov2}\"]\n"
"for ratio in ratios:\n"
" lines.append(f\"{ratio}: {probs[ratio]:.3f}\")\n"
"ot1 = \"\\n\".join(lines)\n"