def runAgent(x_train, x_test): # checkpoint run model folder ckpt_dir_run = FLAGS.ckpt_dir + 'model_' + FLAGS.model log_dir_run = FLAGS.logging_dir + 'model_' + FLAGS.model if not (tf.gfile.Exists(ckpt_dir_run)): tf.gfile.MakeDirs(ckpt_dir_run) if not (tf.gfile.Exists(log_dir_run)): tf.gfile.MakeDirs(log_dir_run) with tf.Session() as sess: if FLAGS.do_training: # create new model instance nnet = NNet( lr=FLAGS.learning_rate, optimizer=FLAGS.optimizer, nonlinearity=FLAGS.nonlinearity, n_hidden=FLAGS.n_hidden, n_latent=FLAGS.n_latent, beta=FLAGS.beta, ) # initialize all variables nnet.init_graph_vars(sess, log_dir=log_dir_run) # tell researcher what's going on ... print("{} Now training my model, LR: {} , EPs: {}, BS: {}".format( datetime.now().strftime('%Y-%m-%d %H:%M:%S'), FLAGS.learning_rate, FLAGS.n_training_episodes, FLAGS.batch_size)) # .. and begin with training results = trainModel(sess, nnet, x_train, x_test, n_episodes=FLAGS.n_training_episodes, n_batches=FLAGS.n_training_batches, batch_size=FLAGS.batch_size, model_dir=ckpt_dir_run) evalModel(sess, nnet, x_train) else: nnet = myModel(is_trained=True) print("Now evaluating my model") ops = loadMyModel(sess, ['nnet', 'input'], ckpt_dir_run) print(ops) nnet.session = sess nnet.y_hat = ops[0] nnet.x = ops[1] results = evalModel(sess, nnet, x_train) return results
def runAgent(data_train,data_test): # checkpoint run model folder ckpt_dir_run = FLAGS.ckpt_dir log_dir_run = FLAGS.log_dir if not(tf.gfile.Exists(ckpt_dir_run)): tf.gfile.MakeDirs(ckpt_dir_run) if not(tf.gfile.Exists(log_dir_run)): tf.gfile.MakeDirs(log_dir_run) with tf.Session() as sess: if FLAGS.do_training: # import graph from trained model # ckpt = tf.train.get_checkpoint_state(FLAGS.import_dir) # if ckpt and ckpt.model_checkpoint_path: # saver = tf.train.import_meta_graph(ckpt.model_checkpoint_path + '.meta') # myGraph = tf.get_default_graph() myGraph = importModelGraph(FLAGS.import_dir) for ii in myGraph.get_operations(): print(ii.name) nnet = myModel(lr = FLAGS.learning_rate, optimizer = FLAGS.optimizer, nonlinearity = FLAGS.nonlinearity, imported_graph = myGraph ) print("Now training the Trees Agent, " + FLAGS.model + ', ' + FLAGS.exp_curriculum + ', ' + FLAGS.exp_boundary + ', ' + FLAGS.exp_taskorder + ', ' + FLAGS.exp_rewards) # initialize all variables nnet.init_graph_vars(sess,log_dir=log_dir_run) # train model results = trainModel(sess,nnet,data_train,data_test, model_dir = ckpt_dir_run) else: nnet = myModel(is_trained=True) print("Now evaluating Trees Agent") ops = loadMyModel(sess,['nnet','input'],ckpt_dir_run) print(ops) nnet.session = sess nnet.y_hat = ops[0] nnet.x = ops[1] results = evalModel(sess,nnet) return results
def runCAE(x_train, x_test): # checkpoint run model folder ckpt_dir_run = FLAGS.ckpt_dir + 'model_' + FLAGS.model log_dir_run = FLAGS.log_dir + 'model_' + FLAGS.model if not (tf.gfile.Exists(ckpt_dir_run)): tf.gfile.MakeDirs(ckpt_dir_run) if not (tf.gfile.Exists(log_dir_run)): tf.gfile.MakeDirs(log_dir_run) with tf.Session() as sess: if FLAGS.do_training: nnet = myModel( lr=FLAGS.learning_rate, optimizer=FLAGS.optimizer, nonlinearity=FLAGS.nonlinearity, ) print( "{} Now training Convolutional Autoencoder, LR: {} , EPs: {}, BS: {}" .format(datetime.now().strftime('%Y-%m-%d %H:%M:%S'), FLAGS.learning_rate, FLAGS.n_training_episodes, FLAGS.batch_size)) # initialize all variables nnet.init_graph_vars(sess, log_dir=log_dir_run) # train model results = trainModel(sess, nnet, x_train, x_test, n_episodes=FLAGS.n_training_episodes, n_batches=FLAGS.n_training_batches, batch_size=FLAGS.batch_size, model_dir=ckpt_dir_run) evalModel(sess, nnet, x_train) else: nnet = myModel(is_trained=True) print("Now evaluating Convolutional Autoencoder") ops = loadMyModel(sess, ['nnet'], ckpt_dir_run) print(ops) nnet.y_hat = ops[0] results = evalModel(sess, nnet, x_train) return results
def runAgent(data_train, data_test): # checkpoint run model folder ckpt_dir_run = FLAGS.ckpt_dir log_dir_run = FLAGS.log_dir if not (tf.gfile.Exists(ckpt_dir_run)): tf.gfile.MakeDirs(ckpt_dir_run) if not (tf.gfile.Exists(log_dir_run)): tf.gfile.MakeDirs(log_dir_run) with tf.Session() as sess: if FLAGS.do_training: nnet = myModel( lr=FLAGS.learning_rate, optimizer=FLAGS.optimizer, nonlinearity=FLAGS.nonlinearity, ) print("Now training the Trees Agent, " + FLAGS.model + ', ' + FLAGS.exp_curriculum + ', ' + FLAGS.exp_boundary + ', ' + FLAGS.exp_taskorder + ', ' + FLAGS.exp_rewards) # initialize all variables nnet.init_graph_vars(sess, log_dir=log_dir_run) # train model results = trainModel(sess, nnet, data_train, data_test, model_dir=ckpt_dir_run) else: nnet = myModel(is_trained=True) print("Now evaluating Trees Agent") ops = loadMyModel(sess, ['nnet', 'input'], ckpt_dir_run) print(ops) nnet.session = sess nnet.y_hat = ops[0] nnet.x = ops[1] results = evalModel(sess, nnet) return results