diff options
Diffstat (limited to 'Code/utils.py')
| -rw-r--r-- | Code/utils.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/Code/utils.py b/Code/utils.py index 39a7e11..d5c5d05 100644 --- a/Code/utils.py +++ b/Code/utils.py @@ -90,6 +90,36 @@ def get_full_clips(data_dir, num_clips, num_rec_out=1): return clips +def get_all_clips(data_dir): + """ + Loads all clips from a directory. + + @param data_dir: The directory of the data to read. Should be either c.TRAIN_DIR or c.TEST_DIR. + @param num_clips: The number of clips to read. + @param num_rec_out: The number of outputs to predict. Outputs > 1 are computed recursively, + using the previously-generated frames as input. Default = 1. + + @return: An array of shape + [num_clips, c.TRAIN_HEIGHT, c.TRAIN_WIDTH, (3 * (c.HIST_LEN + num_rec_out))]. + A batch of frame sequences with values normalized in range [-1, 1]. + """ + # get all the clips + clip_frame_paths = sorted(glob(os.path.join(data_dir, '*'))) + + clips = np.empty([len(clip_frame_paths), + c.FULL_HEIGHT, + c.FULL_WIDTH, + (3 * (c.HIST_LEN + num_rec_out))]) + + # read in frames + for frame_num, frame_path in enumerate(clip_frame_paths): + frame = imread(frame_path, mode='RGB') + norm_frame = normalize_frames(frame) + + clips[clip_num, :, :, frame_num * 3:(frame_num + 1) * 3] = norm_frame + + return clips + def process_clip(): """ Gets a clip from the train dataset, cropped randomly to c.TRAIN_HEIGHT x c.TRAIN_WIDTH. @@ -193,8 +223,8 @@ def sharp_diff_error(gen_frames, gt_frames): # TODO: Could this be simplified with one filter [[-1, 2], [0, -1]]? pos = tf.constant(np.identity(3), dtype=tf.float32) neg = -1 * pos - filter_x = tf.expand_dims(tf.pack([neg, pos]), 0) # [-1, 1] - filter_y = tf.pack([tf.expand_dims(pos, 0), tf.expand_dims(neg, 0)]) # [[1],[-1]] + filter_x = tf.expand_dims(tf.stack([neg, pos]), 0) # [-1, 1] + filter_y = tf.stack([tf.expand_dims(pos, 0), tf.expand_dims(neg, 0)]) # [[1],[-1]] strides = [1, 1, 1, 1] # stride of (1, 1) padding = 'SAME' |
