Bidirectionnet_lstm.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:image-text-matching 作者: llltttppp 项目源码 文件源码
def sentencenet(self, sentence_emb, reuse=False):
        with tf.variable_scope('sentence_net', reuse=reuse) as scope:
            wd = tf.contrib.layers.l2_regularizer(self.weight_decay)
            lstm_cell = tf.contrib.rnn.BasicLSTMCell(num_units=300)
            lstm_cell = tf.contrib.rnn.DropoutWrapper(lstm_cell,input_keep_prob=self.keep_prob,output_keep_prob=self.keep_prob)
            zero_state = lstm_cell.zero_state(
                batch_size=self.sentence_emb.get_shape()[0], dtype=tf.float32)

            input_list = tf.unstack(self.sentence_emb,axis=1)
            output,_ = tf.contrib.rnn.static_rnn(lstm_cell, inputs=input_list,initial_state=zero_state)
            lstm_output = tf.concat(output[:100:1],axis=1)
            sentence_fc1 =tf.contrib.layers.fully_connected(lstm_output,2048, \
                                                            weights_regularizer=wd, scope='s_fc1') # 20*10*256
            sentence_fc2 = tf.contrib.layers.fully_connected(sentence_fc1, 512,activation_fn=None,normalizer_fn=tf.contrib.layers.batch_norm,\
                                                             normalizer_params={'is_training':self.is_training,'updates_collections':None}, weights_regularizer=wd, scope='s_fc2')
            sentence_fc2 = sentence_fc2/tf.norm(sentence_fc2,axis= -1,keep_dims=True)
        self.endpoint['sentence_lstm'] = lstm_output
        self.endpoint['sentence_fc1'] = sentence_fc1
        self.endpoint['sentence_fc2'] = sentence_fc2
        return sentence_fc2
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号