From 1b486d1cd648a66906543b4ba4cbdf099b52d3f3 Mon Sep 17 00:00:00 2001 From: Michael <m.langguth@fz-juelich.de> Date: Thu, 20 May 2021 17:09:57 +0200 Subject: [PATCH] Add model_helpers.py to repo which can be used by all video frame prediction models. --- .../video_prediction/models/model_helpers.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 video_prediction_tools/model_modules/video_prediction/models/model_helpers.py diff --git a/video_prediction_tools/model_modules/video_prediction/models/model_helpers.py b/video_prediction_tools/model_modules/video_prediction/models/model_helpers.py new file mode 100644 index 00000000..a81f4631 --- /dev/null +++ b/video_prediction_tools/model_modules/video_prediction/models/model_helpers.py @@ -0,0 +1,28 @@ +__email__ = "b.gong@fz-juelich.de" +__author__ = "Bing Gong, Michael Langguth" +__date__ = "2021-20-05" + +""" +Some auxiliary functions that can be used by any video prediction model +""" + + +def set_and_check_pred_frames(seq_length, context_frames): + """ + Checks if sequence length and context_frames are set properly and returns number of frames to be predicted. + :param seq_length: number of frames/images per sequences + :param context_frames: number of context frames/images + :return: number of predicted frames + """ + + method = set_and_check_pred_frames.__name__ + + # sanity checks + assert isinstance(seq_length, int), "%{0}: Sequence length (seq_length) must be an integer".format(method) + assert isinstance(context_frames, int), "%{0}: Number of context frames must be an integer".format(method) + + if seq_length > context_frames: + return seq_length - context_frames + else: + raise ValueError("%{0}: Sequence length ({1}) must be larger than context frames ({2})." + .format(method, seq_length, context_frames)) \ No newline at end of file -- GitLab