def main(): ## # Handle command line input. ## load_path = None test_only = False num_test_rec = 1 # number of recursive predictions to make on test try: opts, _ = getopt.getopt(sys.argv[1:], 'l:t:r:a:n:OTH', [ 'load_path=', 'test_dir=', 'recursions=', 'adversarial=', 'name=', 'overwrite', 'test_only', 'help', 'stats_freq=', 'summary_freq=', 'img_save_freq=', 'test_freq=', 'model_save_freq=' ]) except getopt.GetoptError: usage() sys.exit(2) for opt, arg in opts: if opt in ('-l', '--load_path'): load_path = arg if opt in ('-t', '--test_dir'): c.set_test_dir(arg) if opt in ('-r', '--recursions'): num_test_rec = int(arg) if opt in ('-a', '--adversarial'): c.ADVERSARIAL = (arg.lower() == 'true' or arg.lower() == 't') if opt in ('-n', '--name'): c.set_save_name(arg) if opt in ('-O', '--overwrite'): c.clear_save_name() if opt in ('-H', '--help'): usage() sys.exit(2) if opt in ('-T', '--test_only'): test_only = True if opt == '--stats_freq': c.STATS_FREQ = int(arg) if opt == '--summary_freq': c.SUMMARY_FREQ = int(arg) if opt == '--img_save_freq': c.IMG_SAVE_FREQ = int(arg) if opt == '--test_freq': c.TEST_FREQ = int(arg) if opt == '--model_save_freq': c.MODEL_SAVE_FREQ = int(arg) # set test frame dimensions assert os.path.exists(c.TEST_DIR) c.FULL_HEIGHT, c.FULL_WIDTH = c.get_test_frame_dims() ## # Init and run the predictor ## runner = AVGRunner(load_path, num_test_rec) if test_only: runner.test() else: runner.train()
def main(): ## # Handle command line input. ## load_path = None test_only = False num_steps = 1000001 try: opts, _ = getopt.getopt(sys.argv[1:], 'l:t:r:a:n:s:c:g:OTH', [ 'load_path=', 'test_dir=', 'adversarial=', 'name=', 'steps=', 'overwrite', 'test_only', 'help', 'stats_freq=', 'summary_freq=', 'img_save_freq=', 'test_freq=', 'model_save_freq=', 'clips_dir=', 'adv_w=', 'lp_w=', 'gdl_w=', 'batch_size=', 'lrateG=', 'lrateD=' ]) except getopt.GetoptError: usage() sys.exit(2) for opt, arg in opts: if opt in ('-l', '--load_path'): load_path = arg if opt in ('-t', '--test_dir'): c.TEST_DIR = arg c.NUM_TEST_CLIPS = len(glob(c.TEST_DIR + '*.npz')) c.TEST_EXAMPLES = np.array(glob(c.TEST_DIR + '*.npz')) if c.NUM_TEST_CLIPS > 0: path = c.TEST_DIR + '0.npz' clip = np.load(path)['arr_0'] c.FULL_HEIGHT = clip.shape[0] c.FULL_WIDTH = clip.shape[1] #c.set_test_dir(arg) if opt in ('-a', '--adversarial'): c.ADVERSARIAL = (arg.lower() == 'true' or arg.lower() == 't') if opt in ('-n', '--name'): c.set_save_name(arg) if opt in ('-s', '--steps'): num_steps = int(arg) if opt in ('-O', '--overwrite'): c.clear_save_name() if opt in ('-H', '--help'): usage() sys.exit(2) if opt in ('-T', '--test_only'): test_only = True if opt == '--stats_freq': c.STATS_FREQ = int(arg) if opt == '--summary_freq': c.SUMMARY_FREQ = int(arg) if opt == '--img_save_freq': c.IMG_SAVE_FREQ = int(arg) if opt == '--test_freq': c.TEST_FREQ = int(arg) if opt == '--model_save_freq': c.MODEL_SAVE_FREQ = int(arg) if opt in ('-c', '--clips_dir'): c.TRAIN_DIR_CLIPS = arg c.NUM_CLIPS = len(glob(c.TRAIN_DIR_CLIPS + '*.npz')) c.TRAIN_EXAMPLES = np.array(glob(c.TRAIN_DIR_CLIPS + '*.npz')) if opt in ('--adv_w'): c.LAM_ADV = float(arg) if opt in ('--lp_w'): c.LAM_LP = float(arg) if opt in ('--gdl_w'): c.LAM_GDL = float(arg) if opt in ('--batch_size'): c.BATCH_SIZE = int(arg) if opt in ('--lrateG'): c.LRATE_G = float(arg) if opt in ('--lrateD'): c.LRATE_D = float(arg) # set test frame dimensions #assert os.path.exists(c.TEST_DIR) #c.FULL_HEIGHT, c.FULL_WIDTH = c.get_test_frame_dims() ## # Init and run the predictor ## runner = AVGRunner(num_steps, load_path) if test_only: runner.test() else: runner.train()
def main(): ## # Handle cmd line input ## model_type = 'test_model.TestModel' model_load_path = None test_only = False write_csv = False try: opts, _ = getopt.getopt(sys.argv[1:], 'm:l:t:v:n:OT', [ 'model_type=', 'load_path=', 'train_dir=', 'validation_dir=' 'name=', 'overwrite', 'test_only', 'write_csv', 'stats_freq=', 'summary_freq=', 'test_freq=', 'model_save_freq=' ]) except getopt.GetoptError: usage() sys.exit(2) for opt, arg in opts: if opt in ('-m', '--model_type'): model_type = arg if opt in ('-l', '--load_path'): model_load_path = arg if opt in ('-t', '--train_dir'): c.TRAIN_DIR = arg if opt in ('-v', '--validation_dir'): c.TEST_DIR = arg if opt in ('-n', '--name'): c.set_save_name(arg) if opt in ('-O', '--overwrite'): c.clear_save_name() if opt in ('-T', '--test_only'): test_only = True if opt in ('-C', '--write_csv'): write_csv = True if opt == '--stats_freq': c.STATS_FREQ = int(arg) if opt == '--summary_freq': c.SUMMARY_FREQ = int(arg) if opt == '--test_freq': c.TEST_FREQ = int(arg) if opt == '--model_save_freq': c.MODEL_SAVE_FREQ = int(arg) ## # Run the model ## sess = tf.Session() summary_writer = tf.train.SummaryWriter(c.SUMMARY_SAVE_DIR, graph=sess.graph) print 'Init model...' model = get_class(model_type)() print 'Init variables...' saver = tf.train.Saver() sess.run(tf.initialize_all_variables()) # if load path specified, load a saved model if model_load_path is not None: saver.restore(sess, model_load_path) print 'Model restored from ' + model_load_path if test_only: model.test(sess, summary_writer, write_csv=write_csv) else: model.train(0, sess, saver, summary_writer, write_csv=write_csv)