【问题标题】:tensoflow sparse tensor efficient batchingtensorflow 稀疏张量高效批处理
【发布时间】:2018-05-07 20:46:40
【问题描述】:

我有一个从 tensorflow SparseTensorValue 获取批次的方法(如下所示)。但是,这种方法相当慢(批量大小为 32 的批次需要 10-20 秒),这是有问题的,因为它被调用了数千次。

def get_batch(index, tensors, batch_size, nItems):
    xs, ys = tensors
    begin = (index * batch_size)
    end = min((index+1)*batch_size, nItems)
    y_b = ys[begin:end]

    (inds, vals, dsize) = xs
    nInds = [[ind[0] - begin, ind[1]] for ind in inds if begin <= ind[0] < end]
    nInds = np.array(nInds)
    nVals = vals[:nInds.shape[0]]
    nDsize = (end - begin, dsize[1])
    x_b = tf.SparseTensorValue(nInds, nVals, nDsize)
    return (x_b, y_b)

有没有办法让这种方法更高效?

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    我建议您改为使用 tf.data 编写输入管道,然后如果有任何事情,您可以将此重新批处理卸载到另一个核心,而不会阻塞您的主线程。

    【讨论】:

      猜你喜欢
      • 2018-07-19
      • 2017-02-11
      • 2017-05-02
      • 2012-01-03
      • 1970-01-01
      • 2017-12-03
      • 2020-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多