def test(): trainer = algos.algos_factory.gen_tranier(FLAGS.algo) input_app = InputApp.InputApp() sess = input_app.sess = tf.InteractiveSession() input_results = input_app.gen_input() #--------train image_name, image_feature, text, text_str = input_results[ input_app.input_train_name] #--------train neg neg_text, neg_text_str = input_results[input_app.input_train_neg_name] loss = trainer.build_train_graph(image_feature, text, neg_text) eval_names = ['loss'] print('eval_names:', eval_names) test_flow([loss], names=eval_names, gen_feed_dict=input_app.gen_feed_dict, model_dir=FLAGS.model_dir, num_interval_steps=FLAGS.num_interval_steps, num_epochs=FLAGS.num_epochs, eval_times=FLAGS.eval_times, sess=sess)
def test(): trainer = algos_factory.gen_tranier(FLAGS.algo) input_app = InputApp.InputApp() sess = input_app.sess = tf.InteractiveSession() #init_op = tf.group(tf.global_variables_initializer(), # tf.local_variables_initializer()) #sess.run(init_op) input_results = input_app.gen_input() #--------train image_name, image_feature, text, text_str, input_text, input_text_str = input_results[ input_app.input_valid_name] #How to get ride of main scope, not use it ? use make_template to make auto share with tf.variable_scope(FLAGS.main_scope): loss = trainer.build_train_graph(image_feature, input_text, text) eval_names = ['loss'] print('eval_names:', eval_names) ops = [loss] test_flow(ops, names=eval_names, model_dir=FLAGS.model_dir, num_interval_steps=FLAGS.num_interval_steps, num_epochs=FLAGS.num_epochs, eval_times=FLAGS.eval_times, sess=sess)
def train(): with tf.Session() as sess: input_app = InputApp.InputApp() input_results = input_app.gen_input(train_only=True) query, query_str, text, text_str = input_results[ input_app.input_train_name] neg_text, neg_text_str = input_results[input_app.input_train_neg_name] #print input_results[input_app.input_train_neg_name] init = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer()) sess.run(init) coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(sess=sess, coord=coord) step = 0 try: while not coord.should_stop(): start_time = time.time() step = step + 1 #a,b,c,d,e,f = sess.run([query_str[0],text_str[0],neg_text_str[0],query[0],text[0],neg_text[0]]) a,b,c,d,e,f,g,h,i,j,k,l = sess.run([query_str[0],text_str[0],query_str[1],text_str[1], \ query_str[2],text_str[2],query_str[3],text_str[3], \ query_str[4],text_str[4],query_str[5],text_str[5] ]) print a print b print c print d print e print f print g print h print i print j print k print l print '-----------------------' duration = time.time() - start_time #if step%10 == 0: #saver.save(sess, os.path.join(FLAGS.model, 'model_%d.ckpt'%step)) except: traceback.print_exc() pass finally: # When done, ask the threads to stop. coord.request_stop() # Wait for threads to finish. coord.join(threads) sess.close()
def test(): trainer, predictor = algos_factory.gen_trainer_and_predictor(FLAGS.algo) trainer.is_training = False input_app = InputApp.InputApp() sess = input_app.sess = tf.InteractiveSession() input_results = input_app.gen_input() with tf.variable_scope(FLAGS.main_scope) as scope: eval_image_name, eval_text, eval_text_str, eval_input_text, eval_input_text_str = input_results[ input_app.input_valid_name] eval_loss = trainer.build_train_graph(eval_input_text, eval_text) scope.reuse_variables() gen_predict_graph(predictor) print('---------------', tf.get_collection('scores')) eval_scores = tf.get_collection('scores')[-1] eval_names = ['loss'] print('eval_names:', eval_names) print('gen_validate-------------------------', tf.get_collection('scores')) eval_ops = [eval_loss] eval_ops, deal_eval_results = \ gen_evalulate( input_app, input_results, predictor, eval_ops, eval_scores) test_flow(eval_ops, names=eval_names, gen_feed_dict=None, deal_results=deal_eval_results, model_dir=FLAGS.model_dir, num_interval_steps=FLAGS.num_interval_steps, num_epochs=FLAGS.num_epochs, eval_times=FLAGS.eval_times, sess=sess)
def test(): trainer = algos_factory.gen_tranier(FLAGS.algo) input_app = InputApp.InputApp() sess = input_app.sess = tf.InteractiveSession() #init_op = tf.group(tf.global_variables_initializer(), # tf.local_variables_initializer()) #sess.run(init_op) input_results = input_app.gen_input() #--------train image_name, image_feature, text, text_str, input_text, input_text_str = input_results[ input_app.input_valid_name] #How to get ride of main scope, not use it ? use make_template to make auto share with tf.variable_scope(FLAGS.main_scope): loss = trainer.build_train_graph(image_feature, input_text, text) melt.flow.tf_flow(read_once, num_steps=1)