Tensorflow の新しいグラフィックス ライブラリを使用して、ステアリングされた畳み込みを一連のメッシュに適用しています。多くの場合、同じサイズではない一連のメッシュがあり、小さいメッシュをゼロ パディングする必要があります。ドキュメントによると、graph_conv.feature_steered_convolution_layer 関数の「サイズ」引数は、各メッシュのパディングされていない要素の数で構成される int テンソルを受け取ります。何らかの理由で、この引数が「None」以外に設定されていると、「neighbors」引数で使用されている疎配列が密行列に変換されているという警告が表示されます。これにより、プログラムの実行速度が非常に遅くなります。
この問題は、勾配の計算方法に関連しているようです。オプティマイザがコメント アウトされている場合、エラーは発生しません。
問題の解決策がtf.gatherではなくtf.dynamic_partitionを使用することであった同様の問題(以下のリンク)について読みました。ただし、この場合の 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