5

Has anyone tried using Sparse Tensors for Text Analysis with TensorFlow with success? Everything is ready and I manage to feed feed_dict in tf.Session for a Softmax layer with numpy arrays, but I am unable to feed the dictionary with SparseTensorValues.

I have not found either documentation about using sparse matrices to train a model ( softmax for example ) with Tensor Flow, which is strange, as classes SparseTensor and SparseTensorValues or TensorFlow.sparse_to_dense methods are ready for it, but there is no documentation about how to feed the feed_dict dictionary of values in the session.run(fetches,feed_dict=None) method.

Thanks a lot,

4

1 回答 1

2

我找到了一种将稀疏图像放入 tensorflow 的方法,包括批处理(如果有帮助的话)。

我在字典中创建了一个 4-d 稀疏矩阵,其中维度是 batchSize、xLen、ylen、zLen(例如,zLen 是 3 表示颜色)。以下伪代码适用于一批 50 个 32x96 像素的 3 色图像。值是每个像素的强度。在下面的片段中,我显示了第一批的前 2 个像素正在初始化......

shape = [50, 32, 96, 3]
indices = [[0, 20, 31, 0],[0, 22, 33, 1], etc...]
values = [12, 24, etc...]
batch = {"indices": indices, "values": values, "shape": shape}

在设置计算图时,我创建了一个正确尺寸的稀疏占位符

images = tf.sparse_placeholder(tf.float32, shape=[None, 32, 96, 3])

使用“无”,因此我可以改变批量大小。

当我第一次想使用图像时,例如输入批量卷积时,我将它们转换回密集张量:

images = tf.sparse_tensor_to_dense(batch) 

然后当我准备好运行一个会话时,例如训练,我将批处理的 3 个组件传递到字典中,以便它们将被 sparse_placeholder 拾取:

train_dict = {images: (batch['indices'], batch['values'], batch['shape']), etc...}
sess.run(train_step, feed_dict=train_dict)                

如果您不需要进行批处理,只需离开第一个维度并从占位符形状中删除“无”。

我找不到任何将图像作为稀疏矩阵数组批量传递的方法。它只有在我创建第四维时才有效。我很想知道替代方案。

虽然这并不能准确回答您的问题,但我希望它是有用的,因为我一直在努力解决类似的问题。

于 2017-04-04T01:56:36.113 回答