(self, x, labels)
Logits layer to further produce softmax.
Logits layer to further produce softmax.
Logits layer to further produce softmax .
def logits_layer(self, x, labels):
    ''' Logits layer to further produce softmax. '''
    if labels is None:
      # serving export mode, no need for logits
      return x

    output_num = self.taskconf['classes']['num']
    logits_type = self.netconf['logits_type']
    logits_shape = [x.shape[-1].value, output_num]

    with tf.variable_scope('logits'):
      init_type = self.netconf['logits_weight_init']['type']
      if init_type == 'truncated_normal':
        stddev = self.netconf['logits_weight_init']['stddev']
        init = tf.truncated_normal_initializer(stddev=stddev)
      elif init_type == 'xavier_uniform':
        init = tf.initializers.glorot_uniform()
      elif init_type == 'xavier_norm':
        init = tf.initializers.glorot_normal()
      else:
        raise ValueError('Unsupported weight init type: %s' % (init_type))

      weights = tf.get_variable(
          name='weights', shape=logits_shape, initializer=init)

      if logits_type == 'linear':
        bias = tf.get_variable(
            name='bias',
            shape=logits_shape[1],
            initializer=tf.constant_initializer(0.0))
        return tf.matmul(x, weights) + bias
      elif logits_type == 'linear_no_bias':
        return tf.matmul(x, weights)
      elif logits_type == 'arcface':
        return self.arcface_layer(x, labels, output_num, weights)
def logits_layer ( self , x , labels ) : if labels is None : # serving export mode, no need for logits return x output_num = self . taskconf [ 'classes' ] [ 'num' ] logits_type = self . netconf [ 'logits_type' ] logits_shape = [ x . shape [ - 1 ] . value , output_num ] with tf . variable_scope ( 'logits' ) : init_type = self . netconf [ 'logits_weight_init' ] [ 'type' ] if init_type == 'truncated_normal' : stddev = self . netconf [ 'logits_weight_init' ] [ 'stddev' ] init = tf . truncated_normal_initializer ( stddev = stddev ) elif init_type == 'xavier_uniform' : init = tf . initializers . glorot_uniform ( ) elif init_type == 'xavier_norm' : init = tf . initializers . glorot_normal ( ) else : raise ValueError ( 'Unsupported weight init type: %s' % ( init_type ) ) weights = tf . get_variable ( name = 'weights' , shape = logits_shape , initializer = init ) if logits_type == 'linear' : bias = tf . get_variable ( name = 'bias' , shape = logits_shape [ 1 ] , initializer = tf . constant_initializer ( 0.0 ) ) return tf . matmul ( x , weights ) + bias elif logits_type == 'linear_no_bias' : return tf . matmul ( x , weights ) elif logits_type == 'arcface' : return self . arcface_layer ( x , labels , output_num , weights )