Esempio n. 1
0
 def encode_image(self, inputs):
     conv1 = model_utils.conv2d(inputs,
                                16,
                                3,
                                2,
                                scope='conv1',
                                max_pool=False)
     conv2 = model_utils.conv2d(conv1,
                                32,
                                3,
                                2,
                                scope='conv2',
                                max_pool=False)
     conv3 = model_utils.conv2d(conv2,
                                64,
                                3,
                                2,
                                scope='conv3',
                                max_pool=False)
     conv4 = model_utils.conv2d(conv3,
                                128,
                                3,
                                2,
                                scope='conv4',
                                max_pool=False)
     conv5 = model_utils.conv2d(conv4,
                                256,
                                3,
                                2,
                                scope='conv5',
                                max_pool=False)
     shape = conv5.get_shape().as_list()
     outputs = tf.reshape(conv5, shape=[-1, shape[1] * shape[2] * shape[3]
                                        ])  # b * l, -1
     return outputs
Esempio n. 2
0
    def Model(self, inputs):
        input_depth, input_cmd, input_prev_a, input_goal, input_action = inputs
        # encode depth image
        conv1 = model_utils.conv2d(input_depth,
                                   4,
                                   5,
                                   4,
                                   scope='conv1',
                                   max_pool=False)
        conv2 = model_utils.conv2d(conv1,
                                   16,
                                   5,
                                   4,
                                   scope='conv2',
                                   max_pool=False)
        conv3 = model_utils.conv2d(conv2,
                                   32,
                                   3,
                                   2,
                                   scope='conv3',
                                   max_pool=False)
        shape = conv3.get_shape().as_list()
        depth_vect = tf.reshape(conv3,
                                shape=[-1,
                                       shape[1] * shape[2] * shape[3]])  # b,d
        # encode cmd
        embedding_cmd = tf.get_variable('cmd_embedding',
                                        [self.n_cmd_type, self.dim_emb])
        cmd_vect = tf.reshape(tf.nn.embedding_lookup(embedding_cmd, input_cmd),
                              [-1, self.dim_emb])
        # encode action
        embedding_w_action = tf.get_variable('embedding_w_action',
                                             [self.dim_action, self.dim_emb])
        embedding_b_action = tf.get_variable('embedding_b_action',
                                             [self.dim_emb])
        prev_a_vect = tf.matmul(input_prev_a,
                                embedding_w_action) + embedding_b_action
        action_vect = tf.matmul(
            input_action, embedding_w_action) + embedding_b_action  # b, d
        # encode goal
        embedding_w_goal = tf.get_variable('embedding_w_goal',
                                           [self.dim_action, self.dim_emb])
        embedding_b_goal = tf.get_variable('embedding_b_goal', [self.dim_emb])
        goal_vect = tf.matmul(input_goal, embedding_w_goal) + embedding_b_goal
        input_vect = tf.concat(
            [depth_vect, cmd_vect, prev_a_vect, goal_vect, action_vect],
            axis=1)

        hidden_1 = model_utils.dense_layer(input_vect, self.n_hidden,
                                           'hidden_1')
        hidden_2 = model_utils.dense_layer(hidden_1, self.n_hidden / 2,
                                           'hidden_2')
        q = model_utils.dense_layer(
            hidden_2,
            1,
            'q',
            activation=None,
            w_init=tf.initializers.random_uniform(-0.003, 0.003),
            b_init=tf.initializers.random_uniform(-0.003, 0.003))
        return q
Esempio n. 3
0
    def Model(self, inputs):
        input_depth, input_cmd, input_prev_a, rnn_h_in = inputs
        # encode depth image
        conv1 = model_utils.conv2d(input_depth,
                                   4,
                                   5,
                                   4,
                                   scope='conv1',
                                   max_pool=False)
        conv2 = model_utils.conv2d(conv1,
                                   16,
                                   5,
                                   4,
                                   scope='conv2',
                                   max_pool=False)
        conv3 = model_utils.conv2d(conv2,
                                   32,
                                   3,
                                   2,
                                   scope='conv3',
                                   max_pool=False)
        shape = conv3.get_shape().as_list()
        depth_vect = tf.reshape(conv3,
                                shape=[-1,
                                       shape[1] * shape[2] * shape[3]])  # b,d
        # encode cmd
        embedding_cmd = tf.get_variable('cmd_embedding',
                                        [self.n_cmd_type, self.dim_emb])
        cmd_vect = tf.reshape(tf.nn.embedding_lookup(embedding_cmd, input_cmd),
                              [-1, self.dim_emb])
        # encode prev action
        embedding_w_action = tf.get_variable('embedding_w_action',
                                             [self.dim_action, self.dim_emb])
        embedding_b_action = tf.get_variable('embedding_b_action',
                                             [self.dim_emb])
        prev_a_vect = tf.matmul(input_prev_a,
                                embedding_w_action) + embedding_b_action

        input_vect = tf.concat([depth_vect, cmd_vect, prev_a_vect], axis=1)

        # rnn
        if self.rnn_type == 'lstm':
            rnn_cell = model_utils._lstm_cell(self.n_hidden,
                                              1,
                                              name='rnn_cell')
        else:
            rnn_cell = model_utils._gru_cell(self.n_hidden, 1, name='rnn_cell')
        rnn_output, rnn_h_out = rnn_cell(input_vect, self.rnn_h_in)
        # action
        a_linear = model_utils.dense_layer(
            rnn_output, 1, 'a_linear',
            activation=tf.nn.sigmoid) * self.action_range[0]
        a_angular = model_utils.dense_layer(
            rnn_output, 1, 'a_angular',
            activation=tf.nn.tanh) * self.action_range[1]
        pred_action = tf.concat([a_linear, a_angular], axis=1)

        return pred_action, rnn_h_out
Esempio n. 4
0
 def encode_image(self, inputs, activation=tf.nn.leaky_relu, scope='rgb'):
     trainable = True
     conv1 = model_utils.conv2d(inputs,
                                16,
                                3,
                                2,
                                scope=scope + '/conv1',
                                max_pool=False,
                                trainable=trainable,
                                activation=activation)
     conv2 = model_utils.conv2d(conv1,
                                32,
                                3,
                                2,
                                scope=scope + '/conv2',
                                max_pool=False,
                                trainable=trainable,
                                activation=activation)
     conv3 = model_utils.conv2d(conv2,
                                64,
                                3,
                                2,
                                scope=scope + '/conv3',
                                max_pool=False,
                                trainable=trainable,
                                activation=activation)
     conv4 = model_utils.conv2d(conv3,
                                128,
                                3,
                                2,
                                scope=scope + '/conv4',
                                max_pool=False,
                                trainable=trainable,
                                activation=activation)
     conv5 = model_utils.conv2d(conv4,
                                256,
                                3,
                                2,
                                scope=scope + '/conv5',
                                max_pool=False,
                                trainable=trainable,
                                activation=None)
     shape = conv5.get_shape().as_list()
     outputs = tf.reshape(conv5, shape=[-1, shape[1] * shape[2] * shape[3]
                                        ])  # b*l, dim_img_feat
     return outputs
Esempio n. 5
0
    def Model(self, inputs):
        input_depth, input_cmd, input_prev_a, input_action, gru_h_in, length = inputs
        # encode depth image
        conv1 = model_utils.conv2d(input_depth,
                                   4,
                                   5,
                                   4,
                                   scope='conv1',
                                   max_pool=False)
        conv2 = model_utils.conv2d(conv1,
                                   16,
                                   5,
                                   4,
                                   scope='conv2',
                                   max_pool=False)
        conv3 = model_utils.conv2d(conv2,
                                   32,
                                   3,
                                   2,
                                   scope='conv3',
                                   max_pool=False)
        shape = conv3.get_shape().as_list()
        depth_vect = tf.reshape(conv3,
                                shape=[-1, shape[1] * shape[2] * shape[3]
                                       ])  # b*l,d
        # encode cmd
        embedding_cmd = tf.get_variable('cmd_embedding',
                                        [self.n_cmd_type, self.dim_emb])
        cmd_vect = tf.reshape(tf.nn.embedding_lookup(embedding_cmd, input_cmd),
                              [-1, self.dim_emb])
        # encode prev action and action
        embedding_w_action = tf.get_variable('embedding_w_action',
                                             [self.dim_action, self.dim_emb])
        embedding_b_action = tf.get_variable('embedding_b_action',
                                             [self.dim_emb])
        prev_a_vect = tf.matmul(input_prev_a,
                                embedding_w_action) + embedding_b_action
        action_vect = tf.matmul(input_action,
                                embedding_w_action) + embedding_b_action

        input_vect = tf.concat(
            [depth_vect, cmd_vect, prev_a_vect, action_vect], axis=1)
        rnn_cell = model_utils._gru_cell(self.n_hidden, 1, name='gru_cell')
        shape = input_vect.get_shape().as_list()
        input_vect_reshape = tf.reshape(input_vect,
                                        [-1, self.max_step, shape[-1]])
        rnn_output, _ = tf.nn.dynamic_rnn(rnn_cell,
                                          input_vect_reshape,
                                          sequence_length=length,
                                          dtype=tf.float32)  # b, l, h
        rnn_output_reshape = tf.reshape(rnn_output,
                                        [-1, self.n_hidden])  # b*l, h
        # q
        q = model_utils.dense_layer(
            rnn_output_reshape,
            1,
            'q',
            activation=None,
            w_init=tf.initializers.random_uniform(-0.003, 0.003),
            b_init=tf.initializers.random_uniform(-0.003, 0.003))

        return [q]
Esempio n. 6
0
    def Model(self, inputs):
        input_depth, input_cmd, input_prev_a, gru_h_in, length = inputs
        # encode depth image
        conv1 = model_utils.conv2d(input_depth,
                                   4,
                                   5,
                                   4,
                                   scope='conv1',
                                   max_pool=False)
        conv2 = model_utils.conv2d(conv1,
                                   16,
                                   5,
                                   4,
                                   scope='conv2',
                                   max_pool=False)
        conv3 = model_utils.conv2d(conv2,
                                   32,
                                   3,
                                   2,
                                   scope='conv3',
                                   max_pool=False)
        shape = conv3.get_shape().as_list()
        depth_vect = tf.reshape(conv3,
                                shape=[-1,
                                       shape[1] * shape[2] * shape[3]])  # b,d
        # encode cmd
        embedding_cmd = tf.get_variable('cmd_embedding',
                                        [self.n_cmd_type, self.dim_emb])
        cmd_vect = tf.reshape(tf.nn.embedding_lookup(embedding_cmd, input_cmd),
                              [-1, self.dim_emb])
        # encode prev action
        embedding_w_action = tf.get_variable('embedding_w_action',
                                             [self.dim_action, self.dim_emb])
        embedding_b_action = tf.get_variable('embedding_b_action',
                                             [self.dim_emb])
        prev_a_vect = tf.matmul(input_prev_a,
                                embedding_w_action) + embedding_b_action

        input_vect = tf.concat([depth_vect, cmd_vect, prev_a_vect], axis=1)
        gru_cell = model_utils._gru_cell(self.n_hidden, 1, name='gru_cell')

        # training
        shape = input_vect.get_shape().as_list()
        input_vect_reshape = tf.reshape(input_vect,
                                        [-1, self.max_step, shape[-1]])
        gru_output, _ = tf.nn.dynamic_rnn(gru_cell,
                                          input_vect_reshape,
                                          sequence_length=length,
                                          dtype=tf.float32)  # b, l, h
        gru_output_reshape = tf.reshape(gru_output,
                                        [-1, self.n_hidden])  # b*l, h
        # action
        a_linear = model_utils.dense_layer(
            gru_output_reshape, 1, 'a_linear',
            activation=tf.nn.sigmoid) * self.action_range[0]
        a_angular = model_utils.dense_layer(
            gru_output_reshape, 1, 'a_angular',
            activation=tf.nn.tanh) * self.action_range[1]
        action = tf.concat([a_linear, a_angular], axis=1)

        # testing
        gru_output, gru_h_out = gru_cell(input_vect, gru_h_in)
        # action
        a_linear = model_utils.dense_layer(
            gru_output, 1, 'a_linear',
            activation=tf.nn.sigmoid) * self.action_range[0]
        a_angular = model_utils.dense_layer(
            gru_output, 1, 'a_angular',
            activation=tf.nn.tanh) * self.action_range[1]
        action_test = tf.concat([a_linear, a_angular], axis=1)
        return [action, action_test, gru_h_out]
Esempio n. 7
0
    def Model(self, inputs):
        input_depth, input_cmd, input_prev_a = inputs
        # encode depth image
        conv1 = model_utils.conv2d(input_depth,
                                   4,
                                   5,
                                   4,
                                   scope='conv1',
                                   max_pool=False)
        conv2 = model_utils.conv2d(conv1,
                                   16,
                                   5,
                                   4,
                                   scope='conv2',
                                   max_pool=False)
        conv3 = model_utils.conv2d(conv2,
                                   32,
                                   3,
                                   2,
                                   scope='conv3',
                                   max_pool=False)
        shape = conv3.get_shape().as_list()
        depth_vect = tf.reshape(conv3,
                                shape=[-1,
                                       shape[1] * shape[2] * shape[3]])  # b,d
        # encode cmd
        embedding_cmd = tf.get_variable('cmd_embedding',
                                        [self.n_cmd_type, self.dim_emb])
        cmd_vect = tf.reshape(tf.nn.embedding_lookup(embedding_cmd, input_cmd),
                              [-1, self.dim_emb])
        # encode prev action
        embedding_w_action = tf.get_variable('embedding_w_action',
                                             [self.dim_action, self.dim_emb])
        embedding_b_action = tf.get_variable('embedding_b_action',
                                             [self.dim_emb])
        prev_a_vect = tf.matmul(input_prev_a,
                                embedding_w_action) + embedding_b_action

        input_vect = tf.concat([depth_vect, cmd_vect, prev_a_vect], axis=1)

        hidden_1 = model_utils.dense_layer(input_vect, self.n_hidden,
                                           'hiddent_1')
        hidden_2 = model_utils.dense_layer(input_vect, self.n_hidden / 2,
                                           'hiddent_2')
        a_linear = model_utils.dense_layer(
            hidden_2,
            1,
            'a_linear',
            activation=tf.nn.sigmoid,
            w_init=tf.initializers.random_uniform(-0.003, 0.003),
            b_init=tf.initializers.random_uniform(
                -0.003, 0.003)) * self.action_range[0]
        a_angular = model_utils.dense_layer(
            hidden_2,
            1,
            'a_angular',
            activation=tf.nn.tanh,
            w_init=tf.initializers.random_uniform(-0.003, 0.003),
            b_init=tf.initializers.random_uniform(
                -0.003, 0.003)) * self.action_range[1]
        pred_action = tf.concat([a_linear, a_angular], axis=1)

        return pred_action