def generate_video(saved_model_path, video_category=None): """Uses the trained model to predict the frames and produce a video out of them""" # load model model = load_model(saved_model_path) which_one = video_category train_files, test_files = get_train_test_files(which=which_one) test_gen = get_data_gen(files=test_files, timesteps=timesteps, batch_size=batch_size, im_size=(im_width, im_height)) y_true = [] y_pred = [] for _ in range(200): x, y = next(test_gen) y_true.extend(y) predictions = model.predict_on_batch(x) y_pred.extend(predictions) clip1 = ImageSequenceClip([denormalize(i) for i in y_true], fps=5) clip2 = ImageSequenceClip([denormalize(i) for i in y_pred], fps=5) clip2 = clip2.set_position((clip1.w, 0)) video = CompositeVideoClip((clip1, clip2), size=(clip1.w * 2, clip1.h)) video.write_videofile( "{}.mp4".format(which_one if which_one else "render"), fps=5)