转向卷积层的零填充输入有问题

时间:2019-05-21 00:38:39

标签: python-3.x tensorflow sparse-matrix graph-theory zero-padding

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

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

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

How to deal with UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape

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

0 个答案:

没有答案