Beispiel #1
0
def save_results(entry: InferSentence, output: InferenceEntryOutput, infer_dir: str, mel_postnet_npy_paths: List[Dict[str, Any]]):
  result_name = get_result_name(entry)
  dest_dir = get_infer_sent_dir(infer_dir, result_name)
  imageio.imsave(os.path.join(dest_dir, MEL_PNG), output.mel_img)
  imageio.imsave(os.path.join(dest_dir, MEL_POSTNET_PNG), output.postnet_img)
  imageio.imsave(os.path.join(dest_dir, ALIGNMENTS_PNG), output.alignments_img)

  mel_postnet_npy_path = os.path.join(dest_dir, "inferred.mel.npy")
  np.save(mel_postnet_npy_path, output.postnet_mel)

  stack_images_vertically(
    list_im=[
      os.path.join(dest_dir, MEL_PNG),
      os.path.join(dest_dir, MEL_POSTNET_PNG),
      os.path.join(dest_dir, ALIGNMENTS_PNG),
    ],
    out_path=os.path.join(dest_dir, "comparison.png")
  )

  mel_info = get_mel_info_dict(
    identifier=result_name,
    path=mel_postnet_npy_path,
    sr=output.sampling_rate,
  )

  mel_postnet_npy_paths.append(mel_info)
Beispiel #2
0
def mel_inferred_denoised_v_plot(infer_dir: str, sentences: InferenceEntries):
    paths = [
        os.path.join(get_inferred_mel_dir(infer_dir, x.identifier),
                     "inferred_denoised.png") for x in sentences.items()
    ]
    path = os.path.join(infer_dir, "inferred_denoised_v.png")
    stack_images_vertically(paths, path)
Beispiel #3
0
def save_val_comparison(val_dir: str):
    parent_dir = get_parent_dirname(val_dir)
    path1 = os.path.join(val_dir, f"{parent_dir}_orig.png")
    path2 = os.path.join(val_dir, f"{parent_dir}.png")
    assert os.path.exists(path1)
    assert os.path.exists(path2)
    path = os.path.join(val_dir, f"{parent_dir}_comp.png")
    stack_images_vertically([path1, path2], path)
Beispiel #4
0
def plot_batches_h_v(batches: List[List[Path]], plots_dir: Path) -> None:
    for i, v_batch in enumerate(tqdm(batches)):
        h_files = []
        for h_batch in v_batch:
            h_path = mktemp(suffix=".png")
            stack_images_horizontally(h_batch, h_path)
            h_files.append(h_path)
        outpath = plots_dir / f"{i}.png"
        stack_images_vertically(h_files, outpath)
        for v_file in h_files:
            os.remove(v_file)
Beispiel #5
0
def save_results(entry: PreparedData, output: ValidationEntryOutput, val_dir: str, iteration: int, mel_postnet_npy_paths: List[Dict[str, Any]]):
  result_name = get_result_name(entry, iteration, output.repetition)
  dest_dir = get_val_entry_dir(val_dir, result_name)
  write(os.path.join(dest_dir, "original.wav"), output.orig_sr, output.wav_orig)
  imageio.imsave(os.path.join(dest_dir, "original.png"), output.mel_orig_img)
  imageio.imsave(os.path.join(dest_dir, "original_aligned.png"), output.mel_orig_aligned_img)
  imageio.imsave(os.path.join(dest_dir, "inferred.png"), output.mel_postnet_img)
  imageio.imsave(os.path.join(dest_dir, "inferred_aligned.png"), output.mel_postnet_aligned_img)
  imageio.imsave(os.path.join(dest_dir, "mel.png"), output.mel_img)
  imageio.imsave(os.path.join(dest_dir, "alignments.png"), output.alignments_img)
  imageio.imsave(os.path.join(dest_dir, "alignments_aligned.png"), output.alignments_aligned_img)
  imageio.imsave(os.path.join(dest_dir, "diff.png"), output.mel_postnet_diff_img)
  imageio.imsave(os.path.join(dest_dir, "diff_aligned.png"), output.mel_postnet_aligned_diff_img)
  np.save(os.path.join(dest_dir, "original.mel.npy"), output.mel_orig)
  np.save(os.path.join(dest_dir, "original_aligned.mel.npy"), output.mel_orig_aligned)

  mel_postnet_npy_path = os.path.join(dest_dir, "inferred.mel.npy")
  np.save(mel_postnet_npy_path, output.mel_postnet)
  np.save(os.path.join(dest_dir, "inferred_aligned.mel.npy"), output.mel_postnet_aligned)

  stack_images_vertically(
    list_im=[
      os.path.join(dest_dir, "original.png"),
      os.path.join(dest_dir, "inferred.png"),
      os.path.join(dest_dir, "diff.png"),
      os.path.join(dest_dir, "alignments.png"),
      os.path.join(dest_dir, "mel.png"),
    ],
    out_path=os.path.join(dest_dir, "comparison.png")
  )

  stack_images_vertically(
    list_im=[
      os.path.join(dest_dir, "original.png"),
      os.path.join(dest_dir, "inferred.png"),
      os.path.join(dest_dir, "original_aligned.png"),
      os.path.join(dest_dir, "inferred_aligned.png"),
      os.path.join(dest_dir, "diff_aligned.png"),
      os.path.join(dest_dir, "alignments_aligned.png"),
    ],
    out_path=os.path.join(dest_dir, "comparison_aligned.png")
  )

  mel_info = get_mel_info_dict(
    identifier=result_name,
    path=mel_postnet_npy_path,
    sr=output.mel_postnet_sr,
  )

  mel_postnet_npy_paths.append(mel_info)
Beispiel #6
0
def save_results(entry: PreparedData, output: ValidationEntryOutput, val_dir: str, iteration: int):
  dest_dir = get_val_entry_dir(val_dir, entry, iteration)
  imageio.imsave(os.path.join(dest_dir, "original.png"), output.mel_orig_img)
  imageio.imsave(os.path.join(dest_dir, "inferred_denoised.png"), output.mel_inferred_denoised_img)
  imageio.imsave(os.path.join(dest_dir, "diff.png"), output.mel_denoised_diff_img)
  np.save(os.path.join(dest_dir, "original.mel.npy"), output.mel_orig)
  np.save(os.path.join(dest_dir, "inferred_denoised.mel.npy"), output.mel_inferred_denoised)
  float_to_wav(output.wav_orig, os.path.join(
    dest_dir, "original.wav"), sample_rate=output.orig_sr)

  float_to_wav(output.wav_inferred_denoised, os.path.join(
    dest_dir, "inferred_denoised.wav"), sample_rate=output.inferred_sr)

  float_to_wav(output.wav_inferred, os.path.join(
    dest_dir, "inferred.wav"), sample_rate=output.inferred_sr)

  stack_images_vertically(
    list_im=[
      os.path.join(dest_dir, "original.png"),
      os.path.join(dest_dir, "inferred_denoised.png"),
      os.path.join(dest_dir, "diff.png"),
    ],
    out_path=os.path.join(dest_dir, "comparison.png")
  )
Beispiel #7
0
def save_results(output: InferenceEntryOutput, infer_dir: str,
                 denoised_audio_wav_paths: List[Dict[str, Any]]):
    dest_dir = get_inferred_mel_dir(infer_dir, output.identifier)
    os.makedirs(dest_dir, exist_ok=True)
    imageio.imsave(os.path.join(dest_dir, "original.png"), output.mel_orig_img)
    imageio.imsave(os.path.join(dest_dir, "inferred_denoised.png"),
                   output.mel_inferred_denoised_img)
    imageio.imsave(os.path.join(dest_dir, "diff.png"),
                   output.mel_denoised_diff_img)
    np.save(os.path.join(dest_dir, "original.mel.npy"), output.mel_orig)
    np.save(os.path.join(dest_dir, "inferred_denoised.mel.npy"),
            output.mel_inferred_denoised)

    inferred_denoised_path = os.path.join(dest_dir, "inferred_denoised.wav")
    float_to_wav(output.wav_inferred_denoised,
                 inferred_denoised_path,
                 sample_rate=output.inferred_sr)

    float_to_wav(output.wav_inferred,
                 os.path.join(dest_dir, "inferred.wav"),
                 sample_rate=output.inferred_sr)

    stack_images_vertically(list_im=[
        os.path.join(dest_dir, "original.png"),
        os.path.join(dest_dir, "inferred_denoised.png"),
        os.path.join(dest_dir, "diff.png"),
    ],
                            out_path=os.path.join(dest_dir, "comparison.png"))

    wav_info = get_wav_info_dict(
        identifier=output.identifier,
        path=inferred_denoised_path,
        sr=output.inferred_sr,
    )

    denoised_audio_wav_paths.append(wav_info)
Beispiel #8
0
def save_mel_postnet_v_plot(infer_dir: str, sentences: InferSentenceList):
  paths = [os.path.join(get_infer_sent_dir(infer_dir, get_result_name(x)),
                        MEL_POSTNET_PNG) for x in sentences]
  path = os.path.join(infer_dir, "mel_postnet_v.png")
  stack_images_vertically(paths, path)
Beispiel #9
0
def save_alignments_v_plot(infer_dir: str, sentences: InferSentenceList):
  paths = [os.path.join(get_infer_sent_dir(infer_dir, get_result_name(x)),
                        ALIGNMENTS_PNG) for x in sentences]
  path = os.path.join(infer_dir, "alignments_v.png")
  stack_images_vertically(paths, path)
Beispiel #10
0
def save_v(infer_dir: str):
  path1 = os.path.join(infer_dir, f"{get_parent_dirname(infer_dir)}_orig.png")
  path2 = os.path.join(infer_dir, f"{get_parent_dirname(infer_dir)}.png")
  path3 = os.path.join(infer_dir, f"{get_parent_dirname(infer_dir)}_diff.png")
  path = os.path.join(infer_dir, f"{get_parent_dirname(infer_dir)}_v.png")
  stack_images_vertically([path1, path2, path3], path)
Beispiel #11
0
def _save_comparison(dest_dir: Path, dest_name: str, paths: List[Path]) -> str:
    path = dest_dir / f"{dest_name}.png"
    stack_images_vertically(paths, path)
    return path