Ejemplo n.º 1
0
 def __init__(self, x, ac_space, trainable):
     self.logstd = tf.get_variable(name='logstd',
                                   shape=[1] + list(ac_space.shape),
                                   initializer=tf.zeros_initializer(),
                                   trainable=trainable)
     self.mean = dense_layer(x, ac_space.shape[0], None, True, trainable,
                             'pol_mean', (True and trainable), False, False)
     self.std = tf.exp(self.logstd)
     if trainable:
         variable_summaries(self.logstd, 'pol_logstd')
Ejemplo n.º 2
0
def dense_layer(input_layer,
                nn_num,
                act,
                use_bias,
                trainable,
                scope,
                monitor_weight=False,
                monitor_bias=False,
                monitor_output=False):
    size = input_layer.shape[-1]
    with tf.variable_scope(scope, reuse=False):
        w = weight_variable(size, nn_num, trainable)
        if monitor_weight:
            variable_summaries(w, 'weights')
        mul = tf.matmul(input_layer, w)
        if use_bias:
            b = bias_variable(nn_num, trainable)
            if monitor_bias:
                variable_summaries(b, 'bias')
            with tf.name_scope('pre_active'):
                preactive = tf.add(mul, b)
        else:
            with tf.name_scope('pre_active'):
                preactive = mul
        with tf.name_scope('activation'):
            if (act != None):
                activation = act(preactive)
            else:
                activation = preactive
        if monitor_output:
            variable_summaries(activation, 'activated')
    return activation
Ejemplo n.º 3
0
def fc(input_layer,
       nn_num,
       use_bias,
       trainable,
       scope,
       monitor_weight=False,
       monitor_bias=False,
       monitor_output=False):
    size = input_layer.shape[-1]
    with tf.variable_scope(scope, reuse=False):
        w = weight_variable(size, nn_num, trainable)
        if monitor_weight:
            variable_summaries(w, 'weights')
        mul = tf.matmul(input_layer, w)
        if use_bias:
            b = bias_variable(nn_num, trainable)
            if monitor_bias:
                variable_summaries(b, 'bias')
            with tf.name_scope('pre_active'):
                preactive = tf.add(mul, b)
        else:
            with tf.name_scope('pre_active'):
                preactive = mul
        if monitor_output:
            variable_summaries(preactive, 'preactive')
    return preactive