def create_cost_soft_min_distance(c, s, k = 2.0):
"""Creates a soft-min distance of the centers to the points"""
c_shape = c.get_shape().as_list();
s_shape = s.get_shape().as_list();
#expand matrices
cc = tf.reshape(c, [c_shape[0], c_shape[1], 1]);
ss = tf.reshape(s, [s_shape[0], s_shape[1], 1]);
ss = tf.transpose(ss, perm = [2,1,0]);
cc = tf.tile(cc, [1, 1, s_shape[0]]);
ss = tf.tile(ss, [c_shape[0], 1, 1]);
#cc = tf.transpose(cc, perm = [2,1,0]);
#cc = tf.tile(cc, [s_shape[0], 1, 1]);
#ss = tf.tile(ss, [1, 1, c_shape[0]]);
#pairwise distances
dist2 = tf.sqrt(tf.reduce_sum(tf.squared_difference(cc,ss), reduction_indices = 1));
#softmin
softmin = tf.reduce_sum(tf.mul(tf.nn.softmax(tf.scalar_mul(tf.constant(-k,"float32"), dist2)), dist2),reduction_indices = 1);
return tf.reduce_mean(softmin);
machine_vision_b.py 文件源码
python
阅读 40
收藏 0
点赞 0
评论 0
评论列表
文章目录