Пример #1
0
    def set_model(self, input_figs, z, batch_size, is_training = True, reuse = False):
        assert(self.en_channels[0] == input_figs.get_shape().as_list()[3])
        
        # reshape z
        with tf.variable_scope(self.name_scopes[0], reuse = reuse):
            h = linear('_r', z, get_dim(input_figs))
            h = batch_norm('reshape', h, decay_rate= 0.99,
                           is_training = is_training)
            h = tf.nn.relu(h)
        height = input_figs.get_shape().as_list()[1]
        width = input_figs.get_shape().as_list()[2]        
        h = tf.reshape(h, [-1, height, width, self.en_channels[0]])
        h = tf.concat([h, input_figs], 3)
        
        # convolution
        encoded_list = []
        
        # encode
        with tf.variable_scope(self.name_scopes[1], reuse = reuse):
            for i, out_dim in enumerate(self.en_channels[1:]):
                h = conv(i, h, out_dim, 4, 4, 2)
                if i == 0:
                    encoded_list.append(h)
                    h = lrelu(h)
                else:
                    h = batch_norm(i, h, 0.99, is_training)
                    encoded_list.append(h)
                    h = lrelu(h)
                    
        # deconvolution
        encoded_list.pop()
        h = tf.nn.relu(h)
        
        with tf.variable_scope(self.name_scopes[2], reuse = reuse):
            for i, out_chan in enumerate(self.dec_channels[:-1]):
                # get out shape
                h_shape = h.get_shape().as_list()
                out_width = 2 * h_shape[2] 
                out_height = 2 * h_shape[1]
                out_shape = [batch_size, out_height, out_width, out_chan]
                
                # deconvolution
                deconved = deconv(i, h, out_shape, 4, 4, 2)

                # batch normalization
                h = batch_norm(i, deconved, 0.99, is_training)
                if i <= 2:
                    h = tf.nn.dropout(h, 0.5)
                h = tf.concat([h, encoded_list.pop()], 3)
                # activation
                h = tf.nn.relu(h)
            height = 2 * h.get_shape().as_list()[1]
            width = 2 * h.get_shape().as_list()[1]
            out_shape = [batch_size, height, width, self.dec_channels[-1]]
            h = deconv(i + 1, h, out_shape, 4, 4, 2)
        return tf.nn.tanh(h)
Пример #2
0
 def apply_nonlin(x):
     if nonlin_type == 'lrelu':
         return tf_util.lrelu(x, leak=.01) # openai/imitation nn.py:233
     elif nonlin_type == 'tanh':
         return tf.tanh(x)
     else:
         raise NotImplementedError(nonlin_type)
Пример #3
0
 def apply_nonlin(x):
     if nonlin_type == 'lrelu':
         return tf_util.lrelu(x, leak=.01)  # openai/imitation nn.py:233
     elif nonlin_type == 'tanh':
         return tf.tanh(x)
     else:
         raise NotImplementedError(nonlin_type)
Пример #4
0
def apply_nonlin(x, nonlin_type):
    if nonlin_type == 'lrelu':
        return tf_util.lrelu(x, leak=.01)
    elif nonlin_type == 'tanh':
        return tf.tanh(x)
    else:
        return NotImplementedError(nonlin_type)
Пример #5
0
    def __call__(self, inputs, is_training = True):
        
        h  = inputs

        h = self['fc1'](h, is_training)
        h = lrelu(h)
        h = self['bn1'](h, is_training)
        h = self['fc2'](h, is_training)
        return h
Пример #6
0
 def set_model(self, inputs,  is_training = True, reuse = False):
     
     h  = inputs
     
     # fully connect
     with tf.variable_scope(self.name_scopes[0], reuse = reuse):
         for i, s in enumerate(self.layer_channels):
             lin = linear(i, h, s)
             h = lrelu(lin)
     return lin
Пример #7
0
 def apply_nonlin(x):
     '''
     Apply the nonlinear activation function such as leack relu, tanh
     '''
     if nonlin_type == 'lrelu':
         return tf_util.lrelu(x, leak=.01) # openai/imitation nn.py:233
     elif nonlin_type == 'tanh':
         return tf.tanh(x)
     else:
         raise NotImplementedError(nonlin_type)
Пример #8
0
 def set_model(self, input_img,  is_training = True, reuse = False):
     
     assert(self.layer_channels[0] == input_img.get_shape().as_list()[-1])
     h  = input_img
     
     # convolution
     with tf.variable_scope(self.name_scopes[0], reuse = reuse):
         for i, out_chan in enumerate(self.layer_channels[1:]):
             h = conv(i, h, out_chan, 5, 5, 2)
             h = lrelu(h)
             
     # fully connect
     h = flatten(h)
     with tf.variable_scope(self.name_scopes[1], reuse = reuse):
         h =  linear('disc_fc', h, 1)
         
     return h
Пример #9
0
    def set_model(self, inputs, batch_size, is_training = True, reuse = False):
        assert(self.layer_channels[0] == inputs.get_shape().as_list()[-1])
        
        h = inputs

        # convolution
        with tf.variable_scope(self.name_scopes[0], reuse = reuse):
            for i, out_chan in enumerate(self.layer_channels[1:]):
                # convolution
                conved = conv(i, h, out_chan, 5, 5, 2)

                # batch normalization
                bn_conved = batch_norm(i, conved, 0.99, is_training)

                # activation
                h = lrelu(bn_conved)
                
        # fully connect
        with tf.variable_scope(self.name_scopes[1], reuse = reuse):
            encoded = linear('fc', flatten(h), self.out_dim)
            
        return encoded
    # Keep track of input and output dims (i.e. observation and action dims) for the user

    def build_policy(obs_bo):
        def read_layer(l):
            assert list(l.keys()) == ['AffineLayer']
            assert sorted(l['AffineLayer'].keys()) == ['W', 'b']
            return l['AffineLayer']['W'].astype(np.float32), l['AffineLayer']['b'].astype(np.float32)

        def apply_nonlin(x):
<<<<<<< HEAD
            print("non-linearity:", nonlin_type)
=======
>>>>>>> e82c0ba0166126de9dfb8be3bc5a2670e178714d
            if nonlin_type == 'lrelu':
                return tf_util.lrelu(x, leak=.01) # openai/imitation nn.py:233
            elif nonlin_type == 'tanh':
                return tf.tanh(x)
            else:
                raise NotImplementedError(nonlin_type)

        # Build the policy. First, observation normalization.
        assert list(policy_params['obsnorm'].keys()) == ['Standardizer']
        obsnorm_mean = policy_params['obsnorm']['Standardizer']['mean_1_D']
        obsnorm_meansq = policy_params['obsnorm']['Standardizer']['meansq_1_D']
        obsnorm_stdev = np.sqrt(np.maximum(0, obsnorm_meansq - np.square(obsnorm_mean)))
        print('obs', obsnorm_mean.shape, obsnorm_stdev.shape)
        normedobs_bo = (obs_bo - obsnorm_mean) / (obsnorm_stdev + 1e-6) # 1e-6 constant from Standardizer class in nn.py:409 in openai/imitation

        curr_activations_bd = normedobs_bo