小编Ale*_*x H的帖子

Tensorflow 中的动态时间扭曲实现

我已经将动态时间扭曲实现从普通 python 重写为 Tensorflow。但它确实很慢——比预先计算距离并将其作为数据加载到 Tensorflow 中慢得多。我不明白为什么它很慢或如何改进它。

我还尝试使用签名转换其他 DTW 实现,但没有成功。有什么建议么?

def tfDTW(s1, s2):
  r = tf.cast(tf.shape(s1)[0], tf.int32)
  c = tf.cast(tf.shape(s2)[0], tf.int32)
  window = tf.math.reduce_max([r,c])
  max_step = max_dist = 1e7
  penalty = psi = tf.constant(0, dtype=tf.float64)
  length =  tf.math.reduce_min([c + 1, tf.math.abs(r - c) + 2 * (window - 1) + 1 + 1 + 1])
  indices = [0,-1]
  dtw = tf.one_hot(indices, depth = length,
             on_value=0.0, off_value=1e7,
             axis=-1)  # output: [2,length]
  dtw=tf.cast(dtw, tf.float64)
  last_under_max_dist = tf.constant(0)
  skip = tf.constant(0)
  i0 …
Run Code Online (Sandbox Code Playgroud)

python tensorflow dtw

5
推荐指数
1
解决办法
2267
查看次数

标签 统计

dtw ×1

python ×1

tensorflow ×1