最近我正在实施" FC4:具有置信度加权池的完全卷积颜色稳定性"张量流中的纸张。在论文中,角度损失定义为"角度损失= arccos(cosine_distance(vector1,vector2))"。但是,我尝试了几种方法来实现这种损失功能,但在训练中它们几乎没有减少。相关代码如下所示,任何帮助和建议都表示赞赏。
def build_model(self):
self.learning_rate = tf.placeholder(tf.float32)
self.input = tf.placeholder(tf.float32, [self.batch_size, None, None, 3])
self.target = tf.placeholder(tf.float32, [self.batch_size, 3])
#the shape of result_vec is [self.batch_size, 3]
self.result_vec = self.build_network(self.input, 'color_net')
cos_dist = tf.losses.cosine_distance(self.target, self.result_vec, dim=1)
cos_dist_list,acos_list = tf.unstack(cos_dist), []
for dist in cos_dist_list:
acos_list.append(tf.acos(dist))
stack_loss = tf.stack(acos_list)
self.angular_loss = tf.reduce_mean(stack_loss)
var_list = tf.trainable_variables()
self.optim = tf.train.AdamOptimizer(learning_rate = self.learning_rate)\
.minimize(self.angular_loss, var_list = var_list)