Replace hardcoded color inversion detection with manual --swap_bgr flag

- Remove warn_if_inverted_colors_likely() function (was just assumptions)
- Add --swap_bgr flag to swap BGR<->RGB color channels
- Keep --invert_colors for luminosity inversion
- Users can now manually specify color correction needed

There is no standard way to detect RGB vs BGR output from models - it's model-specific.
parent 1d503f07
......@@ -3596,57 +3596,6 @@ def should_use_low_mem(args, m_info, effective_vram_gb):
return False, f"Safe default (model {model_vram_est:.1f} GB < 90%)"
def warn_if_inverted_colors_likely(model_info, args):
"""Warn user if model is known to produce inverted colors.
Models known to have color inversion issues:
- Wan 2.2 I2V LoRA adapters (particularly with certain base models)
- Models using specific diffusers pipeline versions
Returns True if warning was issued.
"""
if getattr(args, 'invert_colors', False):
return False # User already specified inversion
model_id = model_info.get("id", "").lower()
base_model = model_info.get("base_model", "").lower()
is_lora = model_info.get("is_lora", False)
# Check for known problematic model combinations
likely_inverted = False
reason = ""
# Wan 2.2 I2V models with LoRA
if is_lora and "wan" in model_id and "i2v" in model_id:
likely_inverted = True
reason = "Wan I2V LoRA adapter"
# Wan 2.2 base model (especially I2V variant)
if "wan2.2" in base_model and "i2v" in base_model:
likely_inverted = True
reason = "Wan 2.2 I2V base model"
# Specific known problematic models
problematic_patterns = [
"wan2.2-i2v", "wan2_2_i2v", "wan22i2v",
"wan2.2-i2v_general_nsfw",
]
for pattern in problematic_patterns:
if pattern in model_id or pattern in base_model:
likely_inverted = True
reason = f"Known model pattern: {pattern}"
break
if likely_inverted:
print(f"\n ⚠️ WARNING: This model may produce inverted colors.")
print(f" Reason: {reason}")
print(f" Suggestion: Add --invert_colors if output appears inverted.")
print(f" Example: videogen --model {model_info.get('id', 'model')} --invert_colors ...")
return True
return False
def detect_model_type(info):
"""Detect model capabilities from info dict"""
model_id = info.get("id", "").lower()
......@@ -8770,16 +8719,11 @@ def main(args):
print(f" Base model: {base_model_id}")
model_id_to_load = base_model_id
# Warn about potential color inversion for known problematic models
warn_if_inverted_colors_likely(m_info, args)
# Set up custom VAE for Wan base models
if "wan" in base_model_id.lower():
extra["use_custom_vae"] = True
else:
model_id_to_load = m_info["id"]
# Warn about potential color inversion for known problematic non-LoRA models
warn_if_inverted_colors_likely(m_info, args)
if extra.get("use_custom_vae"):
try:
......@@ -10299,6 +10243,11 @@ def main(args):
print(f" 🎨 Inverting colors as requested (--invert_colors)...")
frames = 1.0 - frames
# Check if BGR->RGB channel swap is needed
if args.swap_bgr:
print(f" 🔄 Swapping BGR to RGB channels as requested (--swap_bgr)...")
frames = frames[..., ::-1] # Reverse channel order
# Now convert from [0, 1] to [0, 255]
frames = np.clip(frames, 0.0, 1.0) * 255
frames = frames.astype(np.uint8)
......@@ -10535,7 +10484,9 @@ List TTS voices:
parser.add_argument("--seed", type=int, default=-1)
parser.add_argument("--no_filter", action="store_true")
parser.add_argument("--invert_colors", action="store_true",
help="Invert video colors after generation (fixes inverted output from some models)")
help="Invert video colors after generation (fixes inverted luminosity)")
parser.add_argument("--swap_bgr", action="store_true",
help="Swap BGR<->RGB color channels (fixes wrong color tint)")
parser.add_argument("--upscale", action="store_true")
parser.add_argument("--upscale_factor", type=float, default=2.0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment