def evaluate(hps, logdir, traindir, subset='valid', return_val=False):
 hps.batch_size = 100
 with tf.Graph().as_default():
  with tf.device('/cpu:0'):
   with tf.variable_scope('model') as var_scope:
    eval_model = RealNVP(hps)
    summary_writer = tf.summary.FileWriter(logdir)
    var_scope.reuse_variables()
   saver = tf.train.Saver()
   sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True))
   tf.train.start_queue_runners(sess)
   previous_global_step = 0
   with sess.as_default():
    while True:
     ckpt_state = tf.train.get_checkpoint_state(traindir)
     if (not (ckpt_state and ckpt_state.model_checkpoint_path)):
      print ('No model to eval yet at %s' % traindir)
      time.sleep(30)
      continue
     print ('Loading file %s' % ckpt_state.model_checkpoint_path)
     saver.restore(sess, ckpt_state.model_checkpoint_path)
     current_step = tf.train.global_step(sess, eval_model.step)
     if (current_step == previous_global_step):
      print 'Waiting for the checkpoint to be updated.'
      time.sleep(30)
      continue
     previous_global_step = current_step
     print 'Evaluating...'
     bit_per_dim = eval_model.eval_epoch(hps)
     print ('Epoch: %d, %s -> %.3f bits/dim' % (current_step, subset, bit_per_dim))
     print 'Writing summary...'
     summary = tf.Summary()
     summary.value.extend([tf.Summary.Value(tag='bit_per_dim', simple_value=bit_per_dim)])
     summary_writer.add_summary(summary, current_step)
     if return_val:
      return (current_step, bit_per_dim)

def evaluate ( hps , logdir , traindir , subset = 'valid' , return_val = False ) : hps . batch_size = 100 with tf . Graph ( ) . as_default ( ) : with tf . device ( '/cpu:0' ) : with tf . variable_scope ( 'model' ) as var_scope : eval_model = RealNVP ( hps ) summary_writer = tf . summary . FileWriter ( logdir ) var_scope . reuse_variables ( ) saver = tf . train . Saver ( ) sess = tf . Session ( config = tf . ConfigProto ( allow_soft_placement = True , log_device_placement = True ) ) tf . train . start_queue_runners ( sess ) previous_global_step = 0 with sess . as_default ( ) : while True : ckpt_state = tf . train . get_checkpoint_state ( traindir ) if ( not ( ckpt_state and ckpt_state . model_checkpoint_path ) ) : print ( 'No model to eval yet at %s' % traindir ) time . sleep ( 30 ) continue print ( 'Loading file %s' % ckpt_state . model_checkpoint_path ) saver . restore ( sess , ckpt_state . model_checkpoint_path ) current_step = tf . train . global_step ( sess , eval_model . step ) if ( current_step == previous_global_step ) : print 'Waiting for the checkpoint to be updated.' time . sleep ( 30 ) continue previous_global_step = current_step print 'Evaluating...' bit_per_dim = eval_model . eval_epoch ( hps ) print ( 'Epoch: %d, %s -> %.3f bits/dim' % ( current_step , subset , bit_per_dim ) ) print 'Writing summary...' summary = tf . Summary ( ) summary . value . extend ( [ tf . Summary . Value ( tag = 'bit_per_dim' , simple_value = bit_per_dim ) ] ) summary_writer . add_summary ( summary , current_step ) if return_val : return ( current_step , bit_per_dim )
x: a theano variable y: a theano variable expr: a theano expression involving x and y x_value: a numpy value y_value: a numpy value returns the value of expr when x_value is substituted for x and y_value is substituted for y .