def weak_cross_entropy_2d(y_pred, y_true, num_classes=None, epsilon=0.0001, head=None):
 if (num_classes is None):
  num_classes = y_true.get_shape().as_list()[(-1)]
  assert (num_classes is not None)
 with tf.name_scope('weakCrossEntropy2d'):
  y_pred = tf.reshape(y_pred, ((-1), num_classes))
  y_pred = (y_pred + tf.constant(epsilon, dtype=y_pred.dtype))
  y_true = tf.to_float(tf.reshape(y_true, ((-1), num_classes)))
  softmax = tf.nn.softmax(y_pred)
  if (head is not None):
   cross_entropy = (- tf.reduce_sum(tf.mul((y_true * tf.log(softmax)), head), reduction_indices=[1]))
  else:
   cross_entropy = (- tf.reduce_sum((y_true * tf.log(softmax)), reduction_indices=[1]))
  cross_entropy_mean = tf.reduce_mean(cross_entropy, name='xentropy_mean')
 return cross_entropy_mean

def weak_cross_entropy_2d ( y_pred , y_true , num_classes = None , epsilon = 0.0001 , head = None ) : if ( num_classes is None ) : num_classes = y_true . get_shape ( ) . as_list ( ) [ ( - 1 ) ] assert ( num_classes is not None ) with tf . name_scope ( 'weakCrossEntropy2d' ) : y_pred = tf . reshape ( y_pred , ( ( - 1 ) , num_classes ) ) y_pred = ( y_pred + tf . constant ( epsilon , dtype = y_pred . dtype ) ) y_true = tf . to_float ( tf . reshape ( y_true , ( ( - 1 ) , num_classes ) ) ) softmax = tf . nn . softmax ( y_pred ) if ( head is not None ) : cross_entropy = ( - tf . reduce_sum ( tf . mul ( ( y_true * tf . log ( softmax ) ) , head ) , reduction_indices = [ 1 ] ) ) else : cross_entropy = ( - tf . reduce_sum ( ( y_true * tf . log ( softmax ) ) , reduction_indices = [ 1 ] ) ) cross_entropy_mean = tf . reduce_mean ( cross_entropy , name = 'xentropy_mean' ) return cross_entropy_mean
weak crossentropy 2d .