-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsettings.py
166 lines (132 loc) · 9.59 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
from tensorflow.python.platform import flags
import os
import utils.helpers as helpers
import warnings
FLAGS = flags.FLAGS
""" Set Model From Model Zoo"""
from models.model_zoo import model_conv5_fc_lstm2_1000_deep_64_vae as model
""""""
# --- SPECIFY MANDATORY VARIABLES--- #
#OUT_DIR = '/common/homes/students/rothfuss/Documents/selected_trainings/7_20bn_mse_segmented_armarkitchen_no_OF'
OUT_DIR = '/common/homes/students/rothfuss/Documents/selected_trainings/9_20bn_vae_no_OF/08-06-18_10-21'
#DUMP_DIR = "/common/homes/students/rothfuss/Documents/selected_trainings/7_20bn_mse_segmented_armarkitchen_no_OF"
DUMP_DIR = "/common/homes/students/rothfuss/Documents/selected_trainings/9_20bn_vae_no_OF/08-06-18_10-21"
TF_RECORDS_DIR = "/localhome/rothfuss/data/20bn-something/tf_records_train"
#TF_RECORDS_DIR = "/localhome/rothfuss/data/activity_net/tf_records_train"
#TF_RECORDS_DIR = '/localhome/rothfuss/data/20bn-something/tf_records_valid'
#TF_RECORDS_DIR = "/localhome/rothfuss/segmented_armarkitchen/tfrecords_no_OF_with_id/"
#TF_RECORDS_DIR = "/PDFData/rothfuss/data/activity_net/tf_records_valid_150"
#TF_RECORDS_DIR = "/PDFData/rothfuss/data/20bn-something/tf_records_valid_150"
MODE = 'valid_mode'
VALID_MODE = 'data_frame' #'data_frame gif'
NUM_IMAGES = 15
NUM_DEPTH = 3
WIDTH = 128
HEIGHT = 128
NUM_THREADS_QUEUERUNNER = 32 # specifies the number of pre-processing threads
# PRETRAINING / FINETUNING
#PRETRAINED_MODEL = "/common/homes/students/rothfuss/Documents/selected_trainings/7_20bn_mse_segmented_armarkitchen_no_OF"
#PRETRAINED_MODEL = "/common/homes/students/rothfuss/Documents/selected_trainings/9_20bn_vae_no_OF/07-19-18_14-08"
PRETRAINED_MODEL = "/common/homes/students/rothfuss/Documents/selected_trainings/9_20bn_vae_no_OF/08-06-18_10-21"
#PRETRAINED_MODEL = ""
EXCLUDE_FROM_RESTORING = None
FINE_TUNING_WEIGHTS_LIST = None
# FINE_TUNING_WEIGHTS_LIST = [ 'train_model/encoder/conv4', 'train_model/encoder/convlstm4', 'train_model/encoder/conv5', 'train_model/encoder/convlstm5',
# 'train_model/encoder/fc_conv', 'train_model/encoder/convlstm6', 'train_model/decoder_pred/upconv4',
# 'train_model/decoder_pred/conv4', 'train_model/decoder_pred/convlstm5', 'train_model/decoder_pred/upconv5',
# 'train_model/decoder_reconst/conv4', 'train_model/decoder_reconst/convlstm5', 'train_model/decoder_reconst/upconv5',
# 'train_model/decoder_reconst/upconv4', 'train_model/decoder_reconst/fc_conv']
# FEEDING
#INPUT_DIR = "/common/homes/students/rothfuss/Documents/example/input"
INPUT_DIR = ""
#MEMORY_PATH = "/common/homes/students/rothfuss/Documents/selected_trainings/8_20bn_gdl_optical_flow/valid_run/metadata_and_hidden_rep_df_08-09-17_17-00-24_valid.pickle"
MEMORY_PATH = ""
# --- INFORMAL LOCAL VARIABLES --- #
LOSS_FUNCTIONS = ['mse', 'gdl', 'mse_gdl', 'vae']
MODES = ["train_mode", "valid_mode", "feeding_mode"]
VALID_MODES = ['count_trainable_weights', 'vector', 'gif', 'similarity', 'data_frame', 'psnr', 'memory_prep', 'measure_test_time']
# --- MODEL INPUT PARAMETERS --- #
flags.DEFINE_integer('num_images', NUM_IMAGES, 'specify the number of images in the tfrecords')
flags.DEFINE_integer('num_depth', NUM_DEPTH, 'specifies the number of depth channels in the images')
flags.DEFINE_integer('width', WIDTH, 'specifies the width of an image')
flags.DEFINE_integer('height', HEIGHT, 'specifies the height of an image')
# --- I/O SPECIFICATIONS --- #
flags.DEFINE_string('tf_records_dir', TF_RECORDS_DIR, 'specify the path to where tfrecords are stored, defaults to "../data/"')
flags.DEFINE_string('output_dir', OUT_DIR, 'directory for model checkpoints.')
flags.DEFINE_string('dump_dir', DUMP_DIR, 'directory for validation dumps such as gif and data_frames')
# --- TFRECORDS --- #
flags.DEFINE_string('train_files', 'train*.tfrecords', 'Regex for filtering train tfrecords files.')
flags.DEFINE_string('valid_files', 'valid*.tfrecords', 'Regex for filtering valid tfrecords files.')
flags.DEFINE_string('test_files', 'test*.tfrecords', 'Regex for filtering test tfrecords files.')
flags.DEFINE_integer('num_threads', NUM_THREADS_QUEUERUNNER, 'specifies the number of threads for the queue runner')
# --- MODEL HYPERPARAMETERS --- #
flags.DEFINE_integer('num_iterations', 1000000, 'specify number of training iterations, defaults to 100000')
flags.DEFINE_string('loss_function', 'vae', 'specify loss function to minimize, defaults to gdl')
flags.DEFINE_integer('batch_size', 50, 'specify the batch size, defaults to 50')
flags.DEFINE_integer('valid_batch_size', 25, 'specify the validation batch size, defaults to 50')
flags.DEFINE_bool('uniform_init', False,
'specifies if the weights should be drawn from gaussian(false) or uniform(true) distribution')
flags.DEFINE_integer('num_gpus', len(helpers.get_available_gpus()), 'specifies the number of available GPUs of the machine')
flags.DEFINE_integer('image_range_start', 5,
'parameter that controls the index of the starting image for the train/valid batch')
flags.DEFINE_integer('overall_images_count', 15,
'specifies the number of images that are available to create the train/valid batches')
flags.DEFINE_integer('encoder_length', 5, 'specifies how many images the encoder receives, defaults to 5')
flags.DEFINE_integer('decoder_future_length', 5,
'specifies how many images the future prediction decoder receives, defaults to 5')
flags.DEFINE_integer('decoder_reconst_length', 5,
'specifies how many images the reconstruction decoder receives, defaults to 5')
flags.DEFINE_integer('num_channels', 3, 'number of channels in the input frames')
flags.DEFINE_bool('fc_layer', True,
'indicates whether fully connected layer shall be added between encoder and decoder')
flags.DEFINE_float('learning_rate_decay', 0.000008, 'learning rate decay factor')
flags.DEFINE_float('learning_rate', 0.0001, 'initial learning rate for Adam optimizer')
flags.DEFINE_float('noise_std', 0.001,
'defines standard deviation of gaussian noise to be added to the hidden representation during training')
flags.DEFINE_float('keep_prob_dopout', 0.85,
'keep probability for dropout during training, for valid automatically 1')
# --- INTERVALS --- #
flags.DEFINE_integer('valid_interval', 100, 'number of training steps between each validation')
flags.DEFINE_integer('summary_interval', 100, 'number of training steps between summary is stored')
flags.DEFINE_integer('save_interval', 1000, 'number of training steps between session/model dumps')
# --- MODE OF OPERATION --- #
flags.DEFINE_string('mode', MODE, 'Allowed modes: ' + str(
MODES) + '. "feeding_mode": model is fed from numpy data directly instead of tfrecords'
'"valid_mode": '
'"train_mode": ')
flags.DEFINE_string('valid_mode', VALID_MODE, 'Allowed modes: ' + str(
VALID_MODES) + '. "vector": encoder latent vector for each validation is exported to '
'"gif": gifs are generated from the videos'
'"similarity": compute (cos) similarity matrix'
'"data_frame": the model output is retrieved as a df'
'"count_trainable_weights": number of tr. weights is emitted to the'
'console')
flags.DEFINE_string('pretrained_model', PRETRAINED_MODEL, 'filepath of a pretrained model to initialize from.')
flags.DEFINE_string('exclude_from_restoring', EXCLUDE_FROM_RESTORING,
'variable names to exclude from saving and restoring')
flags.DEFINE_string('fine_tuning_weights_list', FINE_TUNING_WEIGHTS_LIST,
'variable names (layer scopes) that should be trained during fine-tuning')
# --- FEEDING SPECIFICATION --- #
flags.DEFINE_string('feeding_input_dir', INPUT_DIR, 'specify the path to where the input frames are stored')
flags.DEFINE_string('memory_path', MEMORY_PATH, 'specify the path to where the input frames are stored')
assert os.path.isdir(FLAGS.tf_records_dir), "tf_records_dir must be a directory"
assert os.path.isdir(FLAGS.output_dir), "output_dir must be a directory"
assert not FLAGS.pretrained_model or os.path.isdir(FLAGS.pretrained_model), "pretrained_model must be a directory"
assert not FLAGS.dump_dir or os.path.isdir(FLAGS.dump_dir), "dump_dir must be a directory"
assert any([mode in FLAGS.valid_mode for mode in VALID_MODES]), "valid_mode must contain at least one of the following" + str(VALID_MODES)
assert FLAGS.mode in MODES, "mode must be one of " + str(MODES)
assert WIDTH == HEIGHT, "width must be equal to height"
assert FLAGS.num_images > 0, 'num_images must be positive integer'
assert FLAGS.num_depth > 0, 'num_depth must be positive integer'
assert FLAGS.num_threads > 0, 'num_threads must be a positive integer'
assert FLAGS.num_gpus >= 0
assert FLAGS.loss_function in LOSS_FUNCTIONS, "loss functions must be one of " + str(LOSS_FUNCTIONS)
assert FLAGS.num_depth >= FLAGS.num_channels, "provided number of depth channels in input data must be >= number of channels in model"
assert FLAGS.learning_rate_decay > 0.0 and FLAGS.learning_rate_decay < 1.0, 'learning rate decay should be in [0,1]'
assert FLAGS.learning_rate > 0.0 and FLAGS.learning_rate < 1.0, 'learning rate should be in [0,1]'
#assert FLAGS.noise_std > 0.0 and FLAGS.noise_std < 1.0, 'noise_std should be in [0,1]'
assert FLAGS.keep_prob_dopout > 0.0 and FLAGS.keep_prob_dopout <= 1.0, 'keep_prob_dopout must be in [0,1]'
if FLAGS.exclude_from_restoring:
warnings.warn("exclude_from_restoring is not empty -> layers may be omitted from restoring")
if FLAGS.fine_tuning_weights_list:
warnings.warn("fine_tuning_weights_list is not empty -> layers may be omitted from training")