def main(): load_path = None artist_name = 'kanye_west' test = False prime_text = None try: opts, _ = getopt.getopt(sys.argv[1:], 'l:m:a:p:s:t', [ 'load_path=', 'model_name=', 'artist_name=', 'prime=', 'seq_len', 'test', 'save_freq=' ]) except getopt.GetoptError: sys.exit(2) for opt, arg in opts: if opt in ('-l', '--load_path'): load_path = arg if opt in ('-m', '--model_name'): c.set_save_name(arg) if opt in ('-a', '--artist_name'): artist_name = arg if opt in ('-p', '--prime'): prime_text = arg if opt in ('-s', '--seq_len'): c.SEQ_LEN = arg if opt in ('-t', '--test'): test = True if opt == '--save_freq': c.MODEL_SAVE_FREQ = int(arg) LyricGenRunner(load_path, artist_name, test, prime_text)
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(): try: opts, _ = getopt.getopt(sys.argv[1:], 'l:t:r:a:n:s:OTH', [ 'load_path=', 'test_dir=', 'recursions=', 'adversarial=', 'name=', 'steps=', 'overwrite', 'test_only', 'help', 'stats_freq=', 'summary_freq=', 'img_save_freq=', 'test_freq=', 'model_save_freq=' ]) except getopt.GetoptError: print('Options:') print( '-n/--name= <Subdirectory of ../Data/Save/*/ in which to save output of this run>' ) sys.exit(2) for opt, arg in opts: if opt in ('-n', '--name'): c.set_save_name(arg) root_dir = os.path.join(c.IMG_SAVE_DIR, 'Tests/') for path, dirs, files in os.walk(root_dir): files = [ file for file in files if os.path.splitext(file)[1] == IMGAE_SUFFIX ] names = [(os.path.splitext(file)[0], file) for file in files] names = [ tuple(name.rsplit(sep='_', maxsplit=1)) + (file, ) for name, file in names if '_' in name ] names = [(title, int(nostr), file) for title, nostr, file in names if title and nostr.isdigit()] titles = set([name[0] for name in names]) for title1 in titles: names_of_title1 = [(title, no, file) for title, no, file in names if title == title1] names_of_title1.sort(key=lambda x: x[1]) check_numbers(names_of_title1) input_filenames = [file for _, _, file in names_of_title1] output_filename = title1 + GIF_SUFFIX images_to_gif(path, input_filenames, output_filename)
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)