# coding:utf-8 import tensorflow as tf import numpy as np images1 = [[1,2,3],[2,3,1],[2,3,1],[2,3,1]] images2 = [[1,2,3],[2,3,2],[2,1,2],[5,53,51]] def sparse_tuple_from(sequences, dtype=np.int32): indices = [] values = [] for n, seq in enumerate(sequences): indices.extend(zip([n] * len(seq), range(len(seq)))) values.extend(seq) indices = np.asarray(indices, dtype=np.int64) values = np.asarray(values, dtype=dtype) shape = np.asarray([len(sequences), indices.max(0)[1] + 1], dtype=np.int64) return tf.SparseTensor(indices=indices, values=values, dense_shape=shape) distence = tf.edit_distance(sparse_tuple_from(images1),sparse_tuple_from(images2)) with tf.Session() as sess: distence_ = sess.run([distence]) print(distence_)
tf.edit_distance()函数
最新推荐文章于 2022-06-16 10:00:00 发布