def optimize_clones(clones, optimizer, regularization_losses=None, **kwargs):
 grads_and_vars = []
 clones_losses = []
 num_clones = len(clones)
 if (regularization_losses is None):
  regularization_losses = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)
 for clone in clones:
  with tf.name_scope(clone.scope):
   (clone_loss, clone_grad) = _optimize_clone(optimizer, clone, num_clones, regularization_losses, **kwargs)
   if (clone_loss is not None):
    clones_losses.append(clone_loss)
    grads_and_vars.append(clone_grad)
   regularization_losses = None
 total_loss = tf.add_n(clones_losses, name='total_loss')
 grads_and_vars = _sum_clones_gradients(grads_and_vars)
 return (total_loss, grads_and_vars)

def optimize_clones ( clones , optimizer , regularization_losses = None , ** kwargs ) : grads_and_vars = [ ] clones_losses = [ ] num_clones = len ( clones ) if ( regularization_losses is None ) : regularization_losses = tf . get_collection ( tf . GraphKeys . REGULARIZATION_LOSSES ) for clone in clones : with tf . name_scope ( clone . scope ) : ( clone_loss , clone_grad ) = _optimize_clone ( optimizer , clone , num_clones , regularization_losses , ** kwargs ) if ( clone_loss is not None ) : clones_losses . append ( clone_loss ) grads_and_vars . append ( clone_grad ) regularization_losses = None total_loss = tf . add_n ( clones_losses , name = 'total_loss' ) grads_and_vars = _sum_clones_gradients ( grads_and_vars ) return ( total_loss , grads_and_vars )
compute clone losses and gradients for the given list of clones .