def _project_features(self, features):
with tf.variable_scope('level1/project_features'):
# features_proj --> proj_ctx
# todo: features_proj = tf.matmul(features_flat, w) + b
w1_ = np.transpose(self.model_load['/core/context_proj1/weight'][:], (1, 0))
b1_ = self.model_load['/core/context_proj1/bias'][:]
w2_ = np.transpose(self.model_load['/core/context_proj2/weight'][:], (1, 0))
b2_ = self.model_load['/core/context_proj2/bias'][:]
w1 = tf.get_variable('w1', initializer=w1_)
b1 = tf.get_variable('b1', initializer=b1_)
w2 = tf.get_variable('w2', initializer=w2_)
b2 = tf.get_variable('b2', initializer=b2_)
features_flat = tf.reshape(features, [-1, self.D])
features_proj1 = tf.nn.tanh(tf.matmul(features_flat, w1) + b1)
features_proj = tf.matmul(features_proj1, w2) + b2
features_proj = tf.reshape(features_proj, [-1, self.L, self.D])
return features_proj
评论列表
文章目录