def one_hot_patch(x, depth):
# workaround by name-name
sparse_labels = tf.reshape(x, [-1, 1])
derived_size = tf.shape(sparse_labels)[0]
indices = tf.reshape(tf.range(0, derived_size, 1), [-1, 1])
concated = tf.concat(axis=1, values=[indices, sparse_labels])
outshape = tf.concat(axis=0, values=[tf.reshape(derived_size, [1]), tf.reshape(depth, [1])])
return tf.sparse_to_dense(concated, outshape, 1.0, 0.0)
评论列表
文章目录