def output(file_count): import level1 files = level1.get_files_data() file = files[0] file = file.reshape(len(file), level1.INPUT_COUNT, 1) del files model = level1.Level1Model() print(file.shape) file = model.encode(file) print(file.shape) del model backend.clear_session() model = Level2Model() file = model.predict_output(file) del model backend.clear_session() model = level1.Level1Model() file = model.decode(file) del model backend.clear_session() write_wav(get_output_path(f"output-level2-0.wav"), file.flatten())
def output(file_count): files = get_files_data() model = Level1Model() for i in range(min(len(files), file_count)): inp = files[i].reshape(len(files[i]), INPUT_COUNT, 1) output = model.predict_output(inp).flatten() write_wav(get_output_path(f"output-level1-{i}.wav"), output)
def visualize(model_cls, input_data): os.environ["FFMPEG_BINARY"] = "ffmpeg" model = model_cls() output = model.encode(input_data) output = output.reshape(output.shape[0] * 512, 128) min_val = np.amin(output) max_val_normalized = np.amax(output) - min_val last_percentage = -1 figures = [] # (graph total duration / graph datapoint count) * (graph datapoint count / graph width) figure_snapshot_rate = 40 tick_to_sample_ratio = 32.87890625 # This is still off sync with the audio, 2:53 becomes 2:58 for some reason frame_duration = (figure_snapshot_rate * tick_to_sample_ratio) / 44100 for i in range(128): column = i % 16 row = int(i / 16) figures.append(Figure(60, 60, row, column, frame_duration)) print(f"Rendering output: {output.shape}") for index, entry in enumerate(output): should_snapshot = index % figure_snapshot_rate == 0 for plot_index, plot in enumerate(figures): plot.push((entry[plot_index] - min_val) / max_val_normalized) if should_snapshot: plot.snapshot() percentage = int(index / len(output) * 100) if percentage % 1 == 0 and last_percentage != percentage: last_percentage = percentage print(f"Capturing figures: {percentage}%...") print(f"{len(figures[0].figures)} figure frames rendered") clips = [FigureClip(figure) for figure in figures] audio_filename = f"vis/output.wav" output = model.predict_output(input_data).flatten() write_wav(audio_filename, output) del model backend.clear_session() audio = AudioFileClip(audio_filename) audio = audio.set_start(0) audio = audio.set_duration( min(audio.duration, frame_duration * len(figures[0].figures))) result = CompositeVideoClip(clips, size=(16 * 66 + 12, 8 * 66 + 12)) result = result.set_audio(audio) result.write_videofile("vis/output.mp4", fps=1 / frame_duration)
def output(file_count): import level1 import level2 model1 = level1.Level1Model() model2 = level2.Level2Model() model3 = Level3Model() files = level1.get_files_data() file = files[0] file = file.reshape(len(file), level1.INPUT_COUNT, 1) del files file = model1.encode(file) file = model2.encode(file) file = model3.predict_output(file) file = model2.decode(file) file = model1.decode(file) write_wav(get_output_path(f"output-level3-0.wav"), file.flatten())