Pass target_length to TBMediaLogger so predicted + synthesized mels match ground truth dimensions
Browse files- scripts/train_first.py +14 -1
scripts/train_first.py
CHANGED
|
@@ -462,6 +462,12 @@ def _run_standalone(cfg, resume_path: str | None,
|
|
| 462 |
# Get the original audio for this row
|
| 463 |
row_audio = smoke_rows[i].audio
|
| 464 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
# 1. Log ground truth mel + original audio
|
| 466 |
media_logger.log_ground_truth(
|
| 467 |
step=step,
|
|
@@ -471,6 +477,7 @@ def _run_standalone(cfg, resume_path: str | None,
|
|
| 471 |
)
|
| 472 |
|
| 473 |
# 2. Log predicted mel + Griffin-Lim reconstructed audio
|
|
|
|
| 474 |
# Convert pred_slice (1, T, D) → (n_mels, T) mel
|
| 475 |
pred_mel = pred_slice.squeeze(0).detach().cpu().numpy().T # (D, T)
|
| 476 |
# Pad to (n_mels=80, T) if D < 80
|
|
@@ -481,10 +488,15 @@ def _run_standalone(cfg, resume_path: str | None,
|
|
| 481 |
pred_mel = padded
|
| 482 |
else:
|
| 483 |
pred_mel = pred_mel[:media_logger.n_mels, :]
|
| 484 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 485 |
|
| 486 |
# 3. Log synthesized TTS sample (text → tokens → model → audio)
|
| 487 |
# every 2 steps so we don't bloat the TB logs
|
|
|
|
| 488 |
if step % 2 == 0 or step == 1:
|
| 489 |
tts_text = tts_samples[tts_idx % len(tts_samples)]
|
| 490 |
tts_idx += 1
|
|
@@ -493,6 +505,7 @@ def _run_standalone(cfg, resume_path: str | None,
|
|
| 493 |
text=tts_text,
|
| 494 |
phonemizer=phonemizer,
|
| 495 |
model=model,
|
|
|
|
| 496 |
)
|
| 497 |
|
| 498 |
# Log to LossLogger (also pushes losses.json to HF on a cadence)
|
|
|
|
| 462 |
# Get the original audio for this row
|
| 463 |
row_audio = smoke_rows[i].audio
|
| 464 |
|
| 465 |
+
# Compute the ground truth mel's time dimension — the predicted mel
|
| 466 |
+
# will be upsampled to this length so both mels have the same
|
| 467 |
+
# aspect ratio in TensorBoard's IMAGES tab
|
| 468 |
+
gt_mel = mels[i] # (80, T_gt) — precomputed earlier
|
| 469 |
+
gt_T = gt_mel.shape[1]
|
| 470 |
+
|
| 471 |
# 1. Log ground truth mel + original audio
|
| 472 |
media_logger.log_ground_truth(
|
| 473 |
step=step,
|
|
|
|
| 477 |
)
|
| 478 |
|
| 479 |
# 2. Log predicted mel + Griffin-Lim reconstructed audio
|
| 480 |
+
# UPSAMPLE to match ground truth's time dimension
|
| 481 |
# Convert pred_slice (1, T, D) → (n_mels, T) mel
|
| 482 |
pred_mel = pred_slice.squeeze(0).detach().cpu().numpy().T # (D, T)
|
| 483 |
# Pad to (n_mels=80, T) if D < 80
|
|
|
|
| 488 |
pred_mel = padded
|
| 489 |
else:
|
| 490 |
pred_mel = pred_mel[:media_logger.n_mels, :]
|
| 491 |
+
# Upsample predicted mel to match ground truth's T dimension
|
| 492 |
+
# so both images have the same width in TensorBoard
|
| 493 |
+
media_logger.log_reconstructed(
|
| 494 |
+
step=step, mel=pred_mel, target_length=gt_T,
|
| 495 |
+
)
|
| 496 |
|
| 497 |
# 3. Log synthesized TTS sample (text → tokens → model → audio)
|
| 498 |
# every 2 steps so we don't bloat the TB logs
|
| 499 |
+
# Also upsample to the ground truth's T for consistent display
|
| 500 |
if step % 2 == 0 or step == 1:
|
| 501 |
tts_text = tts_samples[tts_idx % len(tts_samples)]
|
| 502 |
tts_idx += 1
|
|
|
|
| 505 |
text=tts_text,
|
| 506 |
phonemizer=phonemizer,
|
| 507 |
model=model,
|
| 508 |
+
target_length=gt_T,
|
| 509 |
)
|
| 510 |
|
| 511 |
# Log to LossLogger (also pushes losses.json to HF on a cadence)
|