diff options
| author | Matt Cooper <matthew_cooper@brown.edu> | 2016-08-17 19:51:18 -0400 |
|---|---|---|
| committer | Matt Cooper <matthew_cooper@brown.edu> | 2016-08-17 19:51:18 -0400 |
| commit | 14ad89afcfe776d6ca290856bd24256a6e9bdc89 (patch) | |
| tree | 61bae700c5c0190205f94bbb2896feb9aa9eae22 | |
| parent | 9177c7e9696b4fbd6feaecb0067ac1fce0cb5bdb (diff) | |
safe path joining with os.path.join
| -rw-r--r-- | Code/constants.py | 20 | ||||
| -rw-r--r-- | Code/g_model.py | 19 | ||||
| -rw-r--r-- | Code/utils.py | 3 |
3 files changed, 22 insertions, 20 deletions
diff --git a/Code/constants.py b/Code/constants.py index 61e9fea..dfd3660 100644 --- a/Code/constants.py +++ b/Code/constants.py @@ -43,7 +43,7 @@ def clear_dir(directory): print(e) def get_test_frame_dims(): - img_path = glob(TEST_DIR + '*/*')[0] + img_path = glob(os.path.join(TEST_DIR, '*/*'))[0] img = imread(img_path, mode='RGB') shape = np.shape(img) @@ -63,12 +63,12 @@ def set_test_dir(directory): # root directory for all data DATA_DIR = get_dir('../Data/') # directory of unprocessed training frames -TRAIN_DIR = DATA_DIR + 'Ms_Pacman/Train/' +TRAIN_DIR = os.path.join(DATA_DIR, 'Ms_Pacman/Train/') # directory of unprocessed test frames -TEST_DIR = DATA_DIR + 'Ms_Pacman/Test/' +TEST_DIR = os.path.join(DATA_DIR, 'Ms_Pacman/Test/') # Directory of processed training clips. # hidden so finder doesn't freeze w/ so many files. DON'T USE `ls` COMMAND ON THIS DIR! -TRAIN_DIR_CLIPS = get_dir(DATA_DIR + '.Clips/') +TRAIN_DIR_CLIPS = get_dir(os.path.join(DATA_DIR, '.Clips/')) # For processing clips. l2 diff between frames must be greater than this MOVEMENT_THRESHOLD = 100 @@ -93,9 +93,9 @@ def set_save_name(name): global SAVE_NAME, MODEL_SAVE_DIR, SUMMARY_SAVE_DIR, IMG_SAVE_DIR SAVE_NAME = name - MODEL_SAVE_DIR = get_dir(SAVE_DIR + 'Models/' + SAVE_NAME) - SUMMARY_SAVE_DIR = get_dir(SAVE_DIR + 'Summaries/' + SAVE_NAME) - IMG_SAVE_DIR = get_dir(SAVE_DIR + 'Images/' + SAVE_NAME) + MODEL_SAVE_DIR = get_dir(os.path.join(SAVE_DIR, 'Models/', SAVE_NAME)) + SUMMARY_SAVE_DIR = get_dir(os.path.join(SAVE_DIR, 'Summaries/', SAVE_NAME)) + IMG_SAVE_DIR = get_dir(os.path.join(SAVE_DIR, 'Images/', SAVE_NAME)) def clear_save_name(): """ @@ -112,11 +112,11 @@ SAVE_DIR = get_dir('../Save/') # inner directory to differentiate between runs SAVE_NAME = 'Default/' # directory for saved models -MODEL_SAVE_DIR = get_dir(SAVE_DIR + 'Models/' + SAVE_NAME) +MODEL_SAVE_DIR = get_dir(os.path.join(SAVE_DIR, 'Models/', SAVE_NAME)) # directory for saved TensorBoard summaries -SUMMARY_SAVE_DIR = get_dir(SAVE_DIR + 'Summaries/' + SAVE_NAME) +SUMMARY_SAVE_DIR = get_dir(os.path.join(SAVE_DIR, 'Summaries/', SAVE_NAME)) # directory for saved images -IMG_SAVE_DIR = get_dir(SAVE_DIR + 'Images/' + SAVE_NAME) +IMG_SAVE_DIR = get_dir(os.path.join(SAVE_DIR, 'Images/', SAVE_NAME)) STATS_FREQ = 10 # how often to print loss/train error stats, in # steps diff --git a/Code/g_model.py b/Code/g_model.py index 9db07da..4e0df31 100644 --- a/Code/g_model.py +++ b/Code/g_model.py @@ -3,6 +3,7 @@ import numpy as np from scipy.misc import imsave from skimage.transform import resize from copy import deepcopy +import os import constants as c from loss_functions import combined_loss @@ -318,20 +319,20 @@ class GeneratorModel: # for every clip in the batch, save the inputs, scale preds and scale gts for pred_num in xrange(len(input_frames)): - pred_dir = c.get_dir(c.IMG_SAVE_DIR + 'Step_' + str(global_step) + '/' + str( - pred_num) + '/') + pred_dir = c.get_dir(os.path.join(c.IMG_SAVE_DIR, 'Step_' + str(global_step), + str(pred_num))) # save input images for frame_num in xrange(c.HIST_LEN): img = input_frames[pred_num, :, :, (frame_num * 3):((frame_num + 1) * 3)] - imsave(pred_dir + 'input_' + str(frame_num) + '.png', img) + imsave(os.path.join(pred_dir, 'input_' + str(frame_num) + '.png'), img) # save preds and gts at each scale # noinspection PyUnboundLocalVariable for scale_num, scale_pred in enumerate(scale_preds): gen_img = scale_pred[pred_num] - path = pred_dir + 'scale' + str(scale_num) + path = os.path.join(pred_dir, 'scale' + str(scale_num)) gt_img = scale_gts[scale_num][pred_num] imsave(path + '_gen.png', gen_img) @@ -410,19 +411,19 @@ class GeneratorModel: if save_imgs: for pred_num in xrange(len(input_frames)): - pred_dir = c.get_dir( - c.IMG_SAVE_DIR + 'Tests/Step_' + str(global_step) + '/' + str(pred_num) + '/') + pred_dir = c.get_dir(os.path.join( + c.IMG_SAVE_DIR, 'Tests/Step_' + str(global_step), str(pred_num))) # save input images for frame_num in xrange(c.HIST_LEN): img = input_frames[pred_num, :, :, (frame_num * 3):((frame_num + 1) * 3)] - imsave(pred_dir + 'input_' + str(frame_num) + '.png', img) + imsave(os.path.join(pred_dir, 'input_' + str(frame_num) + '.png'), img) # save recursive outputs for rec_num in xrange(num_rec_out): gen_img = rec_preds[rec_num][pred_num] gt_img = gt_frames[pred_num, :, :, 3 * rec_num:3 * (rec_num + 1)] - imsave(pred_dir + 'gen_' + str(rec_num) + '.png', gen_img) - imsave(pred_dir + 'gt_' + str(rec_num) + '.png', gt_img) + imsave(os.path.join(pred_dir, 'gen_' + str(rec_num) + '.png'), gen_img) + imsave(os.path.join(pred_dir, 'gt_' + str(rec_num) + '.png'), gt_img) print '-' * 30 diff --git a/Code/utils.py b/Code/utils.py index 2b97bdb..c2bf856 100644 --- a/Code/utils.py +++ b/Code/utils.py @@ -2,6 +2,7 @@ import tensorflow as tf import numpy as np from scipy.ndimage import imread from glob import glob +import os import constants as c from tfutils import log10 @@ -77,7 +78,7 @@ def get_full_clips(data_dir, num_clips, num_rec_out=1): # get a random clip of length HIST_LEN + 1 from each episode for clip_num, ep_dir in enumerate(ep_dirs): - ep_frame_paths = glob(ep_dir + '/*') + ep_frame_paths = glob(os.path.join(ep_dir, '*')) start_index = np.random.choice(len(ep_frame_paths) - (c.HIST_LEN + num_rec_out - 1)) clip_frame_paths = ep_frame_paths[start_index:start_index + (c.HIST_LEN + num_rec_out)] |
