1

我正在使用 Tensorflow 的新图形库将转向卷积应用于一系列网格。在许多情况下,您将拥有一系列大小不同的网格,您必须对较小的网格进行零填充。根据文档,graph_conv.feature_steered_convolution_layer 函数的“大小”参数采用一个 int 张量,该张量由每个网格的非填充元素的数量组成。出于某种原因,当此参数设置为“无”以外的其他值时,我收到一条警告,告诉我“邻居”参数中使用的稀疏数组正在转换为密集矩阵。这导致我的程序运行缓慢。

这个问题似乎与它计算梯度的方式有关。如果优化器被注释掉,错误就不会出现。

我读到了一个类似的问题(下面的链接),该问题的解决方案是使用 tf.dynamic_partition 而不是 tf.gather。但是,在这种情况下,tf.gather 函数位于 graph_convolution 库中。我试图在我的图书馆副本中进行一些编辑,但无济于事。

如何处理 UserWarning:将稀疏的 IndexedSlices 转换为形状未知的密集 Tensor

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from absl.testing import parameterized
import numpy as np
import tensorflow as tf

from tensorflow_graphics.nn.layer import graph_convolution as graph_conv

#Number of meshes
N = 2
#Number of spatial dimensions
d = 2

#################################
#Data consists of the vertices of two meshes.  The first mesh has 5 vertices and the second has 4.
    #Shape of data is (numberOfMeshes,maxNumberofVertices,numberofSpatialDimensions)

#An array containing the actual size of each non-padded mesh
sz = np.array([5,4],dtype=np.int64)
#The maximum number of vertices in a mesh
datav = 5

#Input placeholder for input data (vertices)
V0 = tf.placeholder(dtype=tf.float64,name="V0",shape=(N,datav,d)) 
#Input Placeholder for labels for classification (For now, I'm just using throw-away data as my labels)
L = tf.placeholder(shape=(N,5,1),dtype=tf.float64)
SZ = tf.placeholder(shape=(N),dtype=tf.int64)
#Input placeholder for the sparse array representing the adjacency matrix shape:(numberOfMeshes,datav,datav)
    #The warning is not raised if "SZ" is changed to "None
adj_sp = tf.sparse_placeholder(shape=(SZ.shape[0],datav,datav),dtype=tf.float64,name='SPP')



#The steered graph convolution that is included in Tensorflow's new graphics package
output = graph_conv.feature_steered_convolution_layer(data=V0,neighbors=adj_sp,sizes=SZ,translation_invariant=False,num_weight_matrices=1,num_output_channels=1)

loss = tf.losses.softmax_cross_entropy(L,output, weights=1.0)
optimizer = tf.train.AdamOptimizer(learning_rate=.001).minimize(loss) #Warning not raised if this is commented out

运行上述代码时,我收到以下警告:

C:\Python37\lib\site-packages\tensorflow\python\ops\gradients_impl.py:110: 
UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown 
shape. This may consume a large amount of memory.
  "Converting sparse IndexedSlices to a dense Tensor of unknown shape. "

我开始认为这可能与库本身有关,而不是与这段代码有关。我在 GitHub 中引用了这个,以防它需要对库进行更新(或附加文档)。 https://github.com/tensorflow/graphics/issues/13

4

0 回答 0