def plot_images_encoded_in_latent_space(latent_representations, sample_labels): plt.figure(figsize=(10, 10)) plt.scatter(latent_representations[:, 0], latent_representations[:, 1], cmap="rainbow", c=sample_labels, alpha=0.5, s=2) plt.colorbar() plt.show() if __name__ == "__main__": autoencoder = VAE.load("model") x_train, y_train, x_test, y_test = load_mnist() num_sample_images_to_show = 8 sample_images, _ = select_images(x_test, y_test, num_sample_images_to_show) reconstructed_images, _ = autoencoder.reconstruct(sample_images) plot_reconstructed_images(sample_images, reconstructed_images) num_images = 6000 sample_images, sample_labels = select_images(x_test, y_test, num_images) _, latent_representations = autoencoder.reconstruct(sample_images) plot_images_encoded_in_latent_space(latent_representations, sample_labels)
min_max_values[file_path] for file_path in file_paths ] print(file_paths) print(sampled_min_max_values) return sampled_spectrogrmas, sampled_min_max_values def save_signals(signals, save_dir, sample_rate=22050): for i, signal in enumerate(signals): save_path = os.path.join(save_dir, str(i) + ".wav") sf.write(save_path, signal, sample_rate) if __name__ == "__main__": # initialise sound generator vae = VAE.load("model") sound_generator = SoundGenerator(vae, HOP_LENGTH) # load spectrograms + min max values with open(MIN_MAX_VALUES_PATH, "rb") as f: min_max_values = pickle.load(f) specs, file_paths = load_fsdd(SPECTROGRAMS_PATH) # sample spectrograms + min max values sampled_specs, sampled_min_max_values = select_spectrograms( specs, file_paths, min_max_values, 5) # generate audio for sampled spectrograms signals, _ = sound_generator.generate(sampled_specs, sampled_min_max_values)