(sess, gan, saver, learning_rate, gilbo_step, z_sample,
                 avg_info, z_pred_dist, train_op, outdir, options)
Run the training process.
Run the training process.
Run the training process .
def _train_gilbo(sess, gan, saver, learning_rate, gilbo_step, z_sample,
                 avg_info, z_pred_dist, train_op, outdir, options):

  """Run the training process."""
  lr_scale = options.get("gilbo_lr_scale", 0.5)
  min_lr = options.get("gilbo_min_lr", 1e-8)
  min_ai_step_scale = options.get("gilbo_min_ai_step_scale", 0.75)
  min_ai_step_value = options.get("gilbo_min_ai_step_value", 0.5)
  max_train_cycles = options.get("gilbo_max_train_cycles", 50)
  train_steps_per_cycle = options.get("gilbo_train_steps_per_cycle", 10000)

  ais = [0.0]  # average gilbos (i is for info)
  min_ai = -2.0
  lr, i = sess.run([learning_rate, gilbo_step])
  for i in range(i, max_train_cycles):
    if lr < min_lr:
      break

    _save_gilbo(saver, sess, learning_rate, gilbo_step, i, lr, outdir)
    ai = 0.0
    for j in range(train_steps_per_cycle):
      if j % (train_steps_per_cycle // 10) == 0:
        tf.logging.info("step:%d, gilbo:%.3f" % (j, ai))
      samp = sess.run(z_sample)

      _, z_info = sess.run(
          [train_op, avg_info],
          feed_dict={gan.z: samp, learning_rate: lr})
      ai += (z_info - ai) / (j + 1)
    tf.logging.info("cycle:%d gilbo:%.3f min next gilbo:%.3f learning rate:%.3f"
                    % (i, ai, min_ai, lr))

    if ai < min_ai:
      lr *= lr_scale
    if lr < min_lr:
      break
    if np.isnan(ai):
      tf.logging.info("NaN GILBO at cycle %d, stopping training early." % i)
      break

    ais.append(ai)

    # min_ai is the minimum next GILBO for the training algorithm to consider
    # that progress is being made. GILBO is a lower bound that we are maximizing
    # so we want it to increase during each training cycle.
    min_ai = max(min_ai,
                 ai + max(0.0,
                          min(min_ai_step_value,
                              (ai - ais[-2]) * min_ai_step_scale)
                         )
                )
  _save_gilbo(saver, sess, learning_rate, gilbo_step, i, lr, outdir)
  _save_z_histograms(gan, z_sample, z_pred_dist, outdir, i)
def _train_gilbo ( sess , gan , saver , learning_rate , gilbo_step , z_sample , avg_info , z_pred_dist , train_op , outdir , options ) : lr_scale = options . get ( "gilbo_lr_scale" , 0.5 ) min_lr = options . get ( "gilbo_min_lr" , 1e-8 ) min_ai_step_scale = options . get ( "gilbo_min_ai_step_scale" , 0.75 ) min_ai_step_value = options . get ( "gilbo_min_ai_step_value" , 0.5 ) max_train_cycles = options . get ( "gilbo_max_train_cycles" , 50 ) train_steps_per_cycle = options . get ( "gilbo_train_steps_per_cycle" , 10000 ) ais = [ 0.0 ] # average gilbos (i is for info) min_ai = - 2.0 lr , i = sess . run ( [ learning_rate , gilbo_step ] ) for i in range ( i , max_train_cycles ) : if lr < min_lr : break _save_gilbo ( saver , sess , learning_rate , gilbo_step , i , lr , outdir ) ai = 0.0 for j in range ( train_steps_per_cycle ) : if j % ( train_steps_per_cycle // 10 ) == 0 : tf . logging . info ( "step:%d, gilbo:%.3f" % ( j , ai ) ) samp = sess . run ( z_sample ) _ , z_info = sess . run ( [ train_op , avg_info ] , feed_dict = { gan . z : samp , learning_rate : lr } ) ai += ( z_info - ai ) / ( j + 1 ) tf . logging . info ( "cycle:%d gilbo:%.3f min next gilbo:%.3f learning rate:%.3f" % ( i , ai , min_ai , lr ) ) if ai < min_ai : lr *= lr_scale if lr < min_lr : break if np . isnan ( ai ) : tf . logging . info ( "NaN GILBO at cycle %d, stopping training early." % i ) break ais . append ( ai ) # min_ai is the minimum next GILBO for the training algorithm to consider # that progress is being made. GILBO is a lower bound that we are maximizing # so we want it to increase during each training cycle. min_ai = max ( min_ai , ai + max ( 0.0 , min ( min_ai_step_value , ( ai - ais [ - 2 ] ) * min_ai_step_scale ) ) ) _save_gilbo ( saver , sess , learning_rate , gilbo_step , i , lr , outdir ) _save_z_histograms ( gan , z_sample , z_pred_dist , outdir , i )