Package: dgcnn
DGCNN [TensorFlow]TensorFlow 2 implementation ofAn end-to-end deep learning architecture for graph classificationbased on work byM. Zhang et al., 2018.Moreover, we offer an attention based modification of the above by utilising graph attention(Veličković et al., 2017)to learn edge weights.InstallationSimply runpip install dgcnn. The only dependency istensorflow>=2.0.0.UsageThe core data structure is thegraph signal. If we have N nodes in a graph each having C observed features then the graph signal is the tensor with shape (batch, N, C) corresponding to the data produced by all nodes. Often we have sequences of graph signals in a time series. We will call themtemporalgraph signals and assume a shape of (batch, time steps, N, C).
For each graph signal we also need to have the corresponding adjacency matrices of shape (batch, N, N) or (batch, timesteps, N, N) for temporal and non-temporal data, respectively. While DGCNNs can operate on graphs with different node-counts, C should always be the same and each batch should only contain graphs with the same number of nodes.TheDeepGraphConvolutionLayerThis adaptable layer contains the whole DGCNN architecture and operates on both temporal and non-temporal data. It takes the graph signals and their corresponding adjacency matrices and performs the following steps (as described in the paper):We initialize the layer by providing. The layer has many optional parameters that are described in the table below.It iteratively appliesGraphConvolutionlayers h times with variable hidden feature dimensions.After that, it concatenates all the outputs of the graph convolutions into one tensor which has the shape (..., N,).Finally it appliesSortPoolingas described in the paper to obtain the output tensor of shape (..., k,).Import this layer withfrom gdcnn.components import DeepGraphConvolution.Initiated it with the following parameters:ParameterFunctionhidden_conv_units(required)List of the hidden feature dimensions used in the graph convolutions.in the paper.k(required)Number of nodes to be kept after SortPooling.flatten_signals(default: False)IfTrue, flattens the last 2 dimensions of the output tensor into 1attention_heads(default: None)If given, then instead of usingas the transition matrix inside the graph convolutions, we will use an attention based transition matrix. Utilizingdgcnn.attention.AttentionMechanismas the internal attention mechanism. This sets the number of attention heads used.attention_units(default: None)Also needs to be provided ifattention_headsis set. This is the size of the internal embedding used by the attention mechanism.use_sortpooling(default: True)Whether or not to apply sortpooling at the end of the procedure. If False, we will simply return the concatinated graph convolution outputs.Thus, if we have non-temporal graph signals with 10 nodes and 5 features each and we would like to apply a DGCNN containing 3 graph convolutions with hidden feature dimensions of 10, 5 and 2 and SortPooling that keeps the 5 most relevant nodes. Then we would runfromdgcnn.componentsimportDeepGraphConvolutionfromtensorflow.keras.layersimportInputfromtensorflow.kerasimportModel# generating random graph signals as test datagraph_signal=np.random.normal(size=(100,10,5)# corresponding fully connected adjacency matricesadjacency=np.ones((100,10,10))# inputs to the DGCNNX=Input(shape=(10,5),name="graph_signal")E=Input(shape=(10,10),name="adjacency")# DGCNN# Note that we pass the signals and adjacencies as a tuple.# The graph signal always goes first!output=DeepGraphConvolution([10,5,2],k=5)((X,E))# defining modelmodel=Model(inputs=[X,E],outputs=output)Further layers and featuresThedocumentationcontains information on how to use the internalSortPooling,GraphConvolutionandAttentionMechanismlayers and also describes more optional parameters like regularisers, initialisers and constrains that can be used.ContributeBug reports, fixes and additional features are always welcome! Make sure to run the tests withpython setup.py testand write your own for new features. Thanks.