diff --git a/constants.py b/constants.py index 907bb08..1ef7ab9 100644 --- a/constants.py +++ b/constants.py @@ -65,8 +65,14 @@ PROMPT_FORMAT_OPTIONS = ( DIAGNOSTICS_OFF = "Off" DIAGNOSTICS_BASIC = "Basic" -DIAGNOSTICS_FULL = "Full" +DIAGNOSTICS_FULL = "Detailed Report" +DIAGNOSTICS_LEGACY_FULL = "Full" DIAGNOSTICS_OPTIONS = (DIAGNOSTICS_BASIC, DIAGNOSTICS_FULL, DIAGNOSTICS_OFF) +DIAGNOSTICS_ACCEPTED_OPTIONS = DIAGNOSTICS_OPTIONS + (DIAGNOSTICS_LEGACY_FULL,) + + +def normalize_diagnostics_mode(value: str) -> str: + return DIAGNOSTICS_FULL if value == DIAGNOSTICS_LEGACY_FULL else value SEAM_CORRECTION_AUTO = "Auto" SEAM_CORRECTION_OFF = "Off" diff --git a/v2/diagnostics.py b/v2/diagnostics.py index e5b2502..5ffcba8 100644 --- a/v2/diagnostics.py +++ b/v2/diagnostics.py @@ -27,5 +27,5 @@ def av_duration_error_samples(images,audio): def format_join_metrics(index,metrics): return f"join {index-1}->{index}: video MAE={metrics['video_overlap_mae']:.6f}, PSNR={metrics['video_overlap_psnr']:.2f}dB, audio corr={metrics['audio_overlap_correlation']:.4f}, boundary jump={metrics['audio_boundary_jump']:.6f}" def format_seam_decision(index,decision:SeamDecision,*,full:bool): fallback=decision.fallback_reason or "none" - if not full:return f"seam {index-1}->{index}: cut=-{decision.cut_rewind_frames}f, score {decision.legacy_score:.4f}->{decision.corrected_score:.4f}, video blend={decision.video_blend_frames}f, audio offset={decision.audio_metrics.offset_samples:+d} samples, fallback={fallback}" - return (f"Seam {index-1}->{index}\n Legacy score : {decision.legacy_score:.6f}\n Selected cut : -{decision.cut_rewind_frames} frames\n Cut score : {decision.cut_score:.6f}\n Corrected score : {decision.corrected_score:.6f}\n Improvement : {decision.improvement*100.0:.2f}%\n Luminance gain : {decision.luma_gain:.4f}\n Chroma bias : {decision.chroma_bias}\n Video blend : {decision.video_blend_frames} frames\n Audio correlation : {decision.audio_metrics.correlation_before:.4f}->{decision.audio_metrics.correlation_after:.4f}\n Audio jump : {decision.audio_metrics.boundary_jump_before:.6f}->{decision.audio_metrics.boundary_jump_after:.6f}\n Audio offset : {decision.audio_metrics.offset_samples:+d} samples\n Audio crossfade : {decision.audio_crossfade_samples} samples\n Fallback : {fallback}") + if not full:return f"seam {index-1}->{index}: cut=-{decision.cut_rewind_frames}f, native score {decision.legacy_score:.4f}->{decision.corrected_score:.4f}, video blend={decision.video_blend_frames}f, audio offset={decision.audio_metrics.offset_samples:+d} samples, fallback={fallback}" + return (f"Seam {index-1}->{index}\n Native score : {decision.legacy_score:.6f}\n Selected cut : -{decision.cut_rewind_frames} frames\n Cut score : {decision.cut_score:.6f}\n Candidate score : {decision.candidate_score:.6f}\n Final score : {decision.corrected_score:.6f}\n Improvement : {decision.improvement*100.0:.2f}%\n Native 5f peak : {decision.native_window_peak:.6f}\n Candidate 5f peak : {decision.candidate_window_peak:.6f}\n Luminance gain : {decision.luma_gain:.4f}\n Chroma bias : {decision.chroma_bias}\n Video blend : {decision.video_blend_frames} frames\n Audio correlation : {decision.audio_metrics.correlation_before:.4f}->{decision.audio_metrics.correlation_after:.4f}\n Audio jump : {decision.audio_metrics.boundary_jump_before:.6f}->{decision.audio_metrics.boundary_jump_after:.6f}\n Audio offset : {decision.audio_metrics.offset_samples:+d} samples\n Audio crossfade : {decision.audio_crossfade_samples} samples\n Fallback : {fallback}") diff --git a/v2/nodes.py b/v2/nodes.py index 0545ea1..c63b24e 100644 --- a/v2/nodes.py +++ b/v2/nodes.py @@ -5,6 +5,7 @@ from __future__ import annotations import logging from ..constants import ( + DIAGNOSTICS_ACCEPTED_OPTIONS, DIAGNOSTICS_OPTIONS, PROMPT_FORMAT_OPTIONS, PROMPT_MODE_OPTIONS, @@ -12,6 +13,7 @@ from ..constants import ( SEAM_CORRECTION_OFF, SEAM_CORRECTION_OPTIONS, V2_CONTINUITY_OPTIONS, + normalize_diagnostics_mode, ) from .prompts import ( apply_prompt_overrides, @@ -56,7 +58,7 @@ def _repair_v200_example_widget_shift( back losslessly. """ - if isinstance(exact_total_duration, str) and exact_total_duration in DIAGNOSTICS_OPTIONS: + if isinstance(exact_total_duration, str) and exact_total_duration in DIAGNOSTICS_ACCEPTED_OPTIONS: if isinstance(diagnostics, (int, float, bool)) and not isinstance(diagnostics, str): LOG.warning( "H3 Continuum V2 detected the malformed 2.0.0 bundled workflow widget " @@ -66,7 +68,7 @@ def _repair_v200_example_widget_shift( return ( bool(audio_continuity), True, - exact_total_duration, + normalize_diagnostics_mode(exact_total_duration), int(diagnostics), int(reroll_from_chunk), bool(reroll_nonce), @@ -75,7 +77,7 @@ def _repair_v200_example_widget_shift( return ( bool(audio_continuity), bool(exact_total_duration), - diagnostics, + normalize_diagnostics_mode(diagnostics), int(reroll_from_chunk), int(reroll_nonce), bool(strict_compatibility), @@ -95,6 +97,10 @@ class H3ContinuumSamplerV2: "H3 Continuum V2", ] + @classmethod + def VALIDATE_INPUTS(cls, diagnostics): + return True if diagnostics in DIAGNOSTICS_ACCEPTED_OPTIONS else f"unknown report detail: {diagnostics!r}" + @classmethod def INPUT_TYPES(cls): return { @@ -170,7 +176,14 @@ class H3ContinuumSamplerV2: "tooltip": "Trim or minimally pad the assembled result to chunks × seconds × 24fps.", }, ), - "diagnostics": (DIAGNOSTICS_OPTIONS, {"default": DIAGNOSTICS_OPTIONS[0]}), + "diagnostics": ( + DIAGNOSTICS_OPTIONS, + { + "default": DIAGNOSTICS_OPTIONS[0], + "display_name": "Report Detail", + "tooltip": "Controls report verbosity only; it does not change generation or seam correction.", + }, + ), "reroll_from_chunk": ( "INT", { @@ -201,9 +214,10 @@ class H3ContinuumSamplerV2: { "default": SEAM_CORRECTION_AUTO, "tooltip": ( - "Auto keeps the legacy video boundary unless the guarded candidate " - "improves it. Off preserves the V2.0.2 decode path. Basic always runs " - "the conservative decoded A/V boundary correction." + "Auto keeps native video unless a no-blend candidate improves the boundary " + "and five-frame transition without component regression; audio is guarded " + "independently. Off preserves the decode path. Basic applies the decoded " + "A/V correction including conservative video blend." ), }, ), @@ -512,13 +526,24 @@ class H3ContinuumClipOverrides: class H3ContinuumAdvanced: """Package optional continuation inputs and infrequent sampler settings.""" + @classmethod + def VALIDATE_INPUTS(cls, diagnostics): + return True if diagnostics in DIAGNOSTICS_ACCEPTED_OPTIONS else f"unknown report detail: {diagnostics!r}" + @classmethod def INPUT_TYPES(cls): return { "required": { "audio_continuity": ("BOOLEAN", {"default": True}), "exact_total_duration": ("BOOLEAN", {"default": True}), - "diagnostics": (DIAGNOSTICS_OPTIONS, {"default": DIAGNOSTICS_OPTIONS[0]}), + "diagnostics": ( + DIAGNOSTICS_OPTIONS, + { + "default": DIAGNOSTICS_OPTIONS[0], + "display_name": "Report Detail", + "tooltip": "Controls report verbosity only; it does not change generation or seam correction.", + }, + ), "reroll_from_chunk": ( "INT", {"default": 0, "min": 0, "max": 16, "step": 1}, @@ -563,7 +588,7 @@ class H3ContinuumAdvanced: { "audio_continuity": bool(audio_continuity), "exact_total_duration": bool(exact_total_duration), - "diagnostics": diagnostics, + "diagnostics": normalize_diagnostics_mode(diagnostics), "reroll_from_chunk": int(reroll_from_chunk), "reroll_nonce": int(reroll_nonce), "strict_compatibility": bool(strict_compatibility), @@ -633,7 +658,13 @@ class H3ContinuumSampler: ), "seam_correction": ( SEAM_CORRECTION_OPTIONS, - {"default": SEAM_CORRECTION_AUTO}, + { + "default": SEAM_CORRECTION_AUTO, + "tooltip": ( + "Auto is native-first: video correction is adopted only when the boundary " + "and five-frame transition clearly improve; audio is guarded independently." + ), + }, ), }, "optional": { diff --git a/v2/seam_guard.py b/v2/seam_guard.py index 26151aa..fe60082 100644 --- a/v2/seam_guard.py +++ b/v2/seam_guard.py @@ -5,6 +5,8 @@ import torch import torch.nn.functional as F from .seam_types import AudioSeamMetrics, SeamDecision, VideoSeamMetrics COMPARE_SIZE=96; MAX_CUT_REWIND=3; MIN_RELATIVE_IMPROVEMENT=0.10; MIN_ABSOLUTE_IMPROVEMENT=0.003; SAFE_SCORE_LIMIT=0.35 +AUTO_MIN_RELATIVE_IMPROVEMENT=0.20; AUTO_WINDOW_FRAMES=5; AUTO_MIN_WINDOW_RELATIVE_IMPROVEMENT=0.05; AUTO_MIN_WINDOW_ABSOLUTE_IMPROVEMENT=0.0005 +AUTO_COMPONENT_RELATIVE_TOLERANCE=0.01; AUTO_COMPONENT_ABSOLUTE_TOLERANCE=0.0001 WEIGHT_PIXEL=0.35; WEIGHT_LUMA=0.20; WEIGHT_CHROMA=0.10; WEIGHT_EDGE=0.15; WEIGHT_TEMPORAL=0.20 def _video_shape(frames,label): @@ -67,20 +69,37 @@ def apply_video_blend(previous_frames,aligned_next_frames,*,blend_frames): for index in range(blend_frames): progress=float(index+1)/float(blend_frames+1); alpha=0.5-0.5*math.cos(math.pi*progress); previous[index].mul_(1.0-alpha).add_(current[index],alpha=alpha) return previous +def _seam_window_peak(previous_images,next_images,*,window_frames=AUTO_WINDOW_FRAMES): + if previous_images.shape[0]<1 or next_images.shape[0]<2: raise ValueError("video seam window scoring needs one previous and two next frames") + count=min(max(2,int(window_frames)),int(next_images.shape[0])); sequence=torch.cat((previous_images[-1:],next_images[:count]),dim=0); rgb=_downsample_rgb(sequence) + pixel_delta=torch.mean(torch.abs(rgb[1:]-rgb[:-1]),dim=(1,2,3)); mean_luma=_luma(rgb).mean(dim=(1,2)); luma_delta=torch.abs(mean_luma[1:]-mean_luma[:-1]); combined=0.75*pixel_delta+0.25*luma_delta + peak=float(torch.max(combined).item()) + if not math.isfinite(peak): raise ValueError("video seam window score is not finite") + return max(0.0,min(1.0,peak)) +def _auto_rejection_reason(legacy,candidate,*,improvement,absolute_improvement,native_window_peak,candidate_window_peak): + if candidate.score>SAFE_SCORE_LIMIT: return "Auto kept native video; candidate score exceeded the safe limit" + if improvementlimit: return f"Auto kept native video; {label} regressed" + window_absolute=native_window_peak-candidate_window_peak; window_relative=window_absolute/max(native_window_peak,1e-12) + if window_relative0: - video_patch=apply_video_blend(kept_previous[-blend_frames:],next_raw_images[cut_index-blend_frames:cut_index],blend_frames=blend_frames); score_previous=kept_previous[-2:].clone(); replaced=min(blend_frames,2); score_previous[-replaced:].copy_(video_patch[-replaced:]); corrected=_boundary_metrics(score_previous,current[:2]) - improvement=(legacy.score-corrected.score)/max(legacy.score,1e-12) + video_patch=apply_video_blend(kept_previous[-blend_frames:],next_raw_images[cut_index-blend_frames:cut_index],blend_frames=blend_frames); replaced=min(blend_frames,2); score_previous[-replaced:].copy_(video_patch[-replaced:]); corrected=_boundary_metrics(score_previous,current[:2]) + candidate_window_peak=_seam_window_peak(score_previous,current); improvement=(legacy.score-corrected.score)/max(legacy.score,1e-12); absolute_improvement=legacy.score-corrected.score if corrected.score>legacy.score*1.01: - return next_raw_images[int(context_frames):].clone().contiguous(),SeamDecision(legacy_score=legacy.score,cut_score=legacy.score,corrected_score=legacy.score,fallback_reason="corrected score was worse than legacy"),None - absolute_improvement=legacy.score-corrected.score - if automatic and (improvement