Git Product home page Git Product logo

graph_nets's Introduction

Graph Nets DeepMind shortest path

Graph Nets library

Graph Nets is DeepMind's library for building graph networks in Tensorflow and Sonnet.

Contact [email protected] for comments and questions.

What are graph networks?

A graph network takes a graph as input and returns a graph as output. The input graph has edge- (E ), node- (V ), and global-level (u) attributes. The output graph has the same structure, but updated attributes. Graph networks are part of the broader family of "graph neural networks" (Scarselli et al., 2009).

To learn more about graph networks, see our arXiv paper: Relational inductive biases, deep learning, and graph networks.

Graph network

Installation

The Graph Nets library can be installed from pip.

This installation is compatible with Linux/Mac OS X, and Python 2.7 and 3.4+.

The library will work with both the CPU and GPU version of TensorFlow, but to allow for that it does not list Tensorflow as a requirement, so you need to install Tensorflow separately if you haven't already done so.

To install the Graph Nets library and use it with TensorFlow 1 and Sonnet 1, run:

(CPU)

$ pip install graph_nets "tensorflow>=1.15,<2" "dm-sonnet<2" "tensorflow_probability<0.9"

(GPU)

$ pip install graph_nets "tensorflow_gpu>=1.15,<2" "dm-sonnet<2" "tensorflow_probability<0.9"

To install the Graph Nets library and use it with TensorFlow 2 and Sonnet 2, run:

(CPU)

$ pip install graph_nets "tensorflow>=2.1.0-rc1" "dm-sonnet>=2.0.0b0" tensorflow_probability

(GPU)

$ pip install graph_nets "tensorflow_gpu>=2.1.0-rc1" "dm-sonnet>=2.0.0b0" tensorflow_probability

The latest version of the library requires TensorFlow >=1.15. For compatibility with earlier versions of TensorFlow, please install v1.0.4 of the Graph Nets library.

Usage example

The following code constructs a simple graph net module and connects it to data.

import graph_nets as gn
import sonnet as snt

# Provide your own functions to generate graph-structured data.
input_graphs = get_graphs()

# Create the graph network.
graph_net_module = gn.modules.GraphNetwork(
    edge_model_fn=lambda: snt.nets.MLP([32, 32]),
    node_model_fn=lambda: snt.nets.MLP([32, 32]),
    global_model_fn=lambda: snt.nets.MLP([32, 32]))

# Pass the input graphs to the graph network, and return the output graphs.
output_graphs = graph_net_module(input_graphs)

Demo Jupyter notebooks

The library includes demos which show how to create, manipulate, and train graph networks to reason about graph-structured data, on a shortest path-finding task, a sorting task, and a physical prediction task. Each demo uses the same graph network architecture, which highlights the flexibility of the approach.

Try the demos in your browser in Colaboratory

To try out the demos without installing anything locally, you can run the demos in your browser (even on your phone) via a cloud Colaboratory backend. Click a demo link below, and follow the instructions in the notebook.


The "shortest path demo" creates random graphs, and trains a graph network to label the nodes and edges on the shortest path between any two nodes. Over a sequence of message-passing steps (as depicted by each step's plot), the model refines its prediction of the shortest path.

Shortest path


The "sort demo" creates lists of random numbers, and trains a graph network to sort the list. After a sequence of message-passing steps, the model makes an accurate prediction of which elements (columns in the figure) come next after each other (rows).

Sort


The "physics demo" creates random mass-spring physical systems, and trains a graph network to predict the state of the system on the next timestep. The model's next-step predictions can be fed back in as input to create a rollout of a future trajectory. Each subplot below shows the true and predicted mass-spring system states over 50 steps. This is similar to the model and experiments in Battaglia et al. (2016)'s "interaction networks".

Physics


The "graph nets basics demo" is a tutorial containing step by step examples about how to create and manipulate graphs, how to feed them into graph networks and how to build custom graph network modules.


Run the demos on your local machine

To install the necessary dependencies, run:

$ pip install jupyter matplotlib scipy

To try the demos, run:

$ cd <path-to-graph-nets-library>/demos
$ jupyter notebook

then open a demo through the Jupyter notebook interface.

Other graph neural network libraries

Check out these high-quality open-source libraries for graph neural networks:

graph_nets's People

Contributors

alvarosg avatar anirudhdagar avatar caiodadauto avatar cool-rr avatar derpson avatar fadel avatar matwilso avatar mistobaan avatar msamogh avatar n-kats avatar pbattaglia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graph_nets's Issues

Predict Graph edges value

Hi
I want to create a simple prediction(like house price prediction), can show an example for it?

tf global variables initializer

In the demos we can see that tf.global_variables_initializer() is called before every model execution. Since one might be interested in batch-wise computation, it would be good to know whether there's a work around to this requirement.

Specifically, not calling the initialization line before running EncodeProcessDecode model yields:

FailedPreconditionError (see above for traceback): Attempting to use uninitialized value EncodeProcessDecode/graph_independent/edge_model/edge_output/b

Is there a more efficient way to run the model on the input / target placeholders?

Using TFRecords for Data loading

I have been trying to make TFRecords work with GraphNets but I haven't been able to make it work. All the code for this relies on generating graphs on the fly to numpy arrays - I need to load my data from disk (hence I want the speed that TFRecords give). Is there any way to do this, or do I have to write a new data loader for this?

GraphsTuple placeholders in graph_nets_basics not working

I've tried to run the GraphsTuple placeholders cell in the graph_nets_basics notebook and I keep getting the following error.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-24-69f1d6059dc3> in <module>()
     10       graphs_tuple_ph, utils_np.data_dicts_to_graphs_tuple(graph_dicts[1:]))
     11 
---> 12   graphs_tuple_np = sess.run(graphs_tuple_ph, feed_dict)
     13 
     14 plot_graphs_tuple_np(graphs_tuple_np)

C:\Users\user\AppData\Local\Continuum\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
    875     try:
    876       result = self._run(None, fetches, feed_dict, options_ptr,
--> 877                          run_metadata_ptr)
    878       if run_metadata:
    879         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

C:\Users\user\AppData\Local\Continuum\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1074                              'which has shape %r' %
   1075                              (np_val.shape, subfeed_t.name,
-> 1076                               str(subfeed_t.get_shape())))
   1077           if not self.graph.is_feedable(subfeed_t):
   1078             raise ValueError('Tensor %s may not be fed.' % subfeed_t)

ValueError: Cannot feed value of shape (3,) for Tensor 'placeholders_from_data_dicts/n_node:0', which has shape '(1,)'

If I inspect graphs_tuple_ph, everything except n_node and n_edge have a shape of (?, _) -- should n_node and n_edge have a shape of (?, _) too since these are placeholders?

# print(graphs_tuple_ph)

GraphsTuple(nodes=<tf.Tensor 'placeholders_from_data_dicts/nodes:0' shape=(?, 5) dtype=float32>, edges=<tf.Tensor 'placeholders_from_data_dicts/edges:0' shape=(?, 6) dtype=float32>, receivers=<tf.Tensor 'placeholders_from_data_dicts/receivers:0' shape=(?,) dtype=int32>, senders=<tf.Tensor 'placeholders_from_data_dicts/senders:0' shape=(?,) dtype=int32>, globals=<tf.Tensor 'placeholders_from_data_dicts/globals:0' shape=(?, 4) dtype=float32>, n_node=<tf.Tensor 'placeholders_from_data_dicts/n_node:0' shape=(1,) dtype=int32>, n_edge=<tf.Tensor 'placeholders_from_data_dicts/n_edge:0' shape=(1,) dtype=int32>)

For the record, I'm using Python 3.6.8 (Anaconda distribution) with TensorFlow 1.10.0.

None Types and Operations in feed_dict

Hello,

I am attempting to use the InteractionNetwork with no global attributes. As mentioned in #22, I have set global_model_fn=None for the GraphIndependent block for encoding and decoding. My input placeholder graph tuple looks like this

GraphsTuple(
nodes=<tf.Tensor 'input_graph_placeholder/nodes:0' shape=(?, 6) dtype=float64>, 
edges=<tf.Tensor 'input_graph_placeholder/edges:0' shape=(?, 2) dtype=float64>,
receivers=<tf.Tensor 'input_graph_placeholder/receivers:0' shape=(?,) dtype=int32>, 
senders=<tf.Tensor 'input_graph_placeholder/senders:0' shape=(?,) dtype=int32>, 
globals=None, 
n_node=<tf.Tensor 'input_graph_placeholder/n_node:0' shape=(?,) dtype=int32>, 
n_edge=<tf.Tensor 'input_graph_placeholder/n_edge:0' shape=(?,) dtype=int32>
)

As expected globals = None, I then use the make_all_runnable_in_session as defined in the demos. This yields

GraphsTuple(
nodes=<tf.Tensor 'input_graph_placeholder/nodes:0' shape=(?, 6) dtype=float64>,
edges=<tf.Tensor 'input_graph_placeholder/edges:0' shape=(?, 2) dtype=float64>, 
receivers=<tf.Tensor 'input_graph_placeholder/receivers:0' shape=(?,) dtype=int32>,
senders=<tf.Tensor 'input_graph_placeholder/senders:0' shape=(?,) dtype=int32>, 
globals=<tf.Operation 'make_graph_runnable_in_session/NoOp' type=NoOp>,
n_node=<tf.Tensor 'input_graph_placeholder/n_node:0' shape=(?,) dtype=int32>, 
n_edge=<tf.Tensor 'input_graph_placeholder/n_edge:0' shape=(?,) dtype=int32>
)

As expected, this converts the None into a Tensorflow no_op. But when I try to run the session, I run into this error

TypeError                                 Traceback (most recent call last)
<ipython-input-6-ca8c0124fd42> in <module>()
     21       "loss": loss_op_tr,
     22       "outputs": output_ops_tr
---> 23   }, feed_dict=feed_dict)
     24 
     25 

/home/david/.local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in run(self, fetches, feed_dict, options, run_metadata)
    927     try:
    928       result = self._run(None, fetches, feed_dict, options_ptr,
--> 929                          run_metadata_ptr)
    930       if run_metadata:
    931         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

/home/david/.local/lib/python2.7/site-packages/tensorflow/python/client/session.pyc in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1093           except Exception as e:
   1094             raise TypeError(
-> 1095                 'Cannot interpret feed_dict key as Tensor: ' + e.args[0])
   1096 
   1097           if isinstance(subfeed_val, ops.Tensor):

TypeError: Cannot interpret feed_dict key as Tensor: Can not convert a Operation into a Tensor.

The TensorFlow documentation seems to indicate Operations cannot be keys of feed_dict. Is this how None types are suppose to be handled?

I am running Tensorflow version 1.12.0 with python 2.7 on Ubuntu 18.04

Thank you!

Run utils_tf_test.py Failed

$python utils_tf_test.py
...
======================================================================
FAIL: test_fill_edge_state_edge size 0 (__main__.GraphsCompletionTests)
test_fill_edge_state_edge size 0 (__main__.GraphsCompletionTests)
test_fill_edge_state_edge size 0(0)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/absl/testing/parameterized.py", line 258, in bound_param_test
    test_method(self, *testcase_params)
  File "utils_tf_test.py", line 612, in test_fill_edge_state
    graphs_tuple.edges.get_shape().as_list())
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/test_util.py", line 1381, in assertAllEqual
    np.testing.assert_array_equal(a, b, err_msg=msg)
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/numpy/testing/nose_tools/utils.py", line 855, in assert_array_equal
    verbose=verbose, header='Arrays are not equal')
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/numpy/testing/nose_tools/utils.py", line 779, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Arrays are not equal

(mismatch 50.0%)
 x: array([6, 0])
 y: array([None, 0], dtype=object)

======================================================================
FAIL: test_fill_edge_state_edge size 1 (__main__.GraphsCompletionTests)
test_fill_edge_state_edge size 1 (__main__.GraphsCompletionTests)
test_fill_edge_state_edge size 1(1)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/absl/testing/parameterized.py", line 258, in bound_param_test
    test_method(self, *testcase_params)
  File "utils_tf_test.py", line 612, in test_fill_edge_state
    graphs_tuple.edges.get_shape().as_list())
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/test_util.py", line 1381, in assertAllEqual
    np.testing.assert_array_equal(a, b, err_msg=msg)
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/numpy/testing/nose_tools/utils.py", line 855, in assert_array_equal
    verbose=verbose, header='Arrays are not equal')
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/numpy/testing/nose_tools/utils.py", line 779, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Arrays are not equal

(mismatch 50.0%)
 x: array([6, 1])
 y: array([None, 1], dtype=object)

======================================================================
FAIL: test_fill_node_state_node size 0 (__main__.GraphsCompletionTests)
test_fill_node_state_node size 0 (__main__.GraphsCompletionTests)
test_fill_node_state_node size 0(0)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/absl/testing/parameterized.py", line 258, in bound_param_test
    test_method(self, *testcase_params)
  File "utils_tf_test.py", line 667, in test_fill_node_state
    graphs_tuple.nodes.get_shape().as_list())
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/test_util.py", line 1381, in assertAllEqual
    np.testing.assert_array_equal(a, b, err_msg=msg)
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/numpy/testing/nose_tools/utils.py", line 855, in assert_array_equal
    verbose=verbose, header='Arrays are not equal')
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/numpy/testing/nose_tools/utils.py", line 779, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Arrays are not equal

(mismatch 50.0%)
 x: array([9, 0])
 y: array([None, 0], dtype=object)

======================================================================
FAIL: test_fill_node_state_node size 1 (__main__.GraphsCompletionTests)
test_fill_node_state_node size 1 (__main__.GraphsCompletionTests)
test_fill_node_state_node size 1(1)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/absl/testing/parameterized.py", line 258, in bound_param_test
    test_method(self, *testcase_params)
  File "utils_tf_test.py", line 667, in test_fill_node_state
    graphs_tuple.nodes.get_shape().as_list())
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/test_util.py", line 1381, in assertAllEqual
    np.testing.assert_array_equal(a, b, err_msg=msg)
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/numpy/testing/nose_tools/utils.py", line 855, in assert_array_equal
    verbose=verbose, header='Arrays are not equal')
  File "/home/jinze/anaconda3/lib/python3.6/site-packages/numpy/testing/nose_tools/utils.py", line 779, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Arrays are not equal

(mismatch 50.0%)
 x: array([9, 1])
 y: array([None, 1], dtype=object)

----------------------------------------------------------------------
Ran 98 tests in 8.310s

FAILED (failures=4)

EncodeProcessDecode model documentation

Hi,
I've been trying to understand the EncodeProcessDecode model parameters, however, the documentation is a little scarce on the parameters (edge_output_size, node_output_size, global_output_size) in this case.

In the code I found the following comment # Transforms the outputs into the appropriate shapes. but that doesn't clarify the exact reshaping. Can anybody clarify?

Thanks a lot!

Replace for loop in _build() with tf.while_loop for EncodeProcessDecode class

I'm trying to transfer the _build() function of EncodeProcessDecode into a tf.while_loop variant for variable-sized num_processing_steps that I now feed as a placeholder value at every build() call.
So far, I'm struggling to concatenate the decoded_op in a list because I can only come up with a version using shape_invariants which in turn requires to know shapes of GraphTuple. However, calls like tf.shape(output_op) won't work, nor does tf.concat accept values other than Tensors. To my knowledge, a variant not requiring shape_invariants must rely on tf.TensorShape() which is only defined for TensorFlow primitive data types.

Can someone give me a hint how to use tf.while_loop for replacing the _build() Python for loop? Can one use utils_tf.concat for the while_loop iterations instead of tf.concat? How should its output be further processed or how can the concatenated GraphTuple elements be accessed for constructing the loss function again? An example would very handy! Here's my approach so far:

def _build(self, input_op, input_ctrl_ph, num_processing_steps, is_training):
        latent = self._encoder(input_op, is_training)
    
        latent_global = self._encoder_globals(input_op, is_training)
        latent_init = latent.replace(globals=latent_global.globals)
    
        global_T = self._encoder_globals(input_ctrl_ph, is_training).globals

        i = tf.constant(0)
        output_ops = tf.Variable([])
    
        def iter(i, *args):
            return i < num_processing_steps

        def body(i, output_ops, latent):
            global_t = tf.gather(global_T, i)
            global_t = tf.expand_dims(global_t, 0)
            latent = latent.replace(globals=global_t)
        
            latent = self._core(latent)
        
            decoded_op = self._decoder(latent, is_training)
            return i+1, tf.concat([output_ops, decoded_op], axis=0), latent

        i, outputs, latent = tf.while_loop(iter, body, [i, output_ops, latent_init], 
                             shape_invariants=[i.get_shape(), 
                                               tf.TensorShape([None]), 
                                               tf.TensorShape([None])])

physics demo loss function

The calculation of the loss function, why is the difference between the nodes' output of the model and the velocity dimension's feature, that is, why the output of the node is linearly transformed into two-dimensional.

install issue, gpu ,tensorflow1.12

GPU install tensorflow 1.12, following the instruction on README:

"pip install graph_nets tensorflow_gpu tensorflow_probability_gpu"

find below error,

Traceback (most recent call last):
File "Node_Apply_GCN_symptom_deepmind.py", line 1, in
import sonnet as snt
File "/usr/local/lib/python2.7/dist-packages/sonnet/init.py", line 39, in
from sonnet.python import custom_getters
File "/usr/local/lib/python2.7/dist-packages/sonnet/python/custom_getters/init.py", line 21, in
from sonnet.python.custom_getters import bayes_by_backprop
File "/usr/local/lib/python2.7/dist-packages/sonnet/python/custom_getters/bayes_by_backprop.py", line 97, in
_OK_PZATION_TYPE = tf.contrib.distributions.FULLY_REPARAMETERIZED
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/util/lazy_loader.py", line 53, in getattr
module = self._load()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/util/lazy_loader.py", line 42, in _load
module = importlib.import_module(self.name)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/init.py", line 48, in
from tensorflow.contrib import distribute
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/distribute/init.py", line 34, in
from tensorflow.contrib.distribute.python.tpu_strategy import TPUStrategy
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/distribute/python/tpu_strategy.py", line 27, in
from tensorflow.contrib.tpu.python.ops import tpu_ops
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/tpu/init.py", line 73, in
from tensorflow.contrib.tpu.python.tpu.keras_support import tpu_model as keras_to_tpu_model
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/tpu/python/tpu/keras_support.py", line 71, in
from tensorflow.python.estimator import model_fn as model_fn_lib
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/init.py", line 25, in
import tensorflow.python.estimator.estimator_lib
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator_lib.py", line 42, in
from tensorflow.python.estimator.keras import model_to_estimator
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/keras.py", line 27, in
from tensorflow.python.estimator import estimator as estimator_lib
ImportError: cannot import name estimator

Error in multi feature using for target nodes

I want to add multiple features to target nodes like below in shortest path example:

    input_node_fields = ("solution", "ComId")
    input_edge_fields = ("solution", "ComId")
    target_node_fields = ("solution", "ComId")
    target_edge_fields = ("solution",)

when I want to run my code, rise below error:

Traceback (most recent call last):
  File "C:/Users/Farshid/PycharmProjects/CommunityDetection/Main.py", line 104, in <module>
    num_nodes_min_max_tr, theta)
  File "C:\Users\Farshid\PycharmProjects\CommunityDetection\Helper.py", line 234, in create_placeholders
    rand, batch_size, num_nodes_min_max, theta)
  File "C:\Users\Farshid\PycharmProjects\CommunityDetection\Helper.py", line 209, in generate_networkx_graphs
    input_graph, target_graph = graph_to_input_target(graph)
  File "C:\Users\Farshid\PycharmProjects\CommunityDetection\Helper.py", line 168, in graph_to_input_target
    target_node = to_one_hot(create_feature(node_feature, target_node_fields).astype(int), 2)[0]
  File "C:\Users\Farshid\PycharmProjects\CommunityDetection\Helper.py", line 28, in to_one_hot
    one_hot = np.eye(max_value)[indices]
IndexError: index 2 is out of bounds for axis 0 with size 2

Can someone help me?
@mateuszmalinowski
@pbattaglia

Changing edges in the model

Hello,
I want to solve my task using the library. In my problem, the source graph and target graph has the same nodes but some edges are different. And I want to predict the changes. As I understood, the only manipulation with edges, nodes and global features is supported. Am I right?
Thank you in advance!

Install tensorflow_probability_gpu always crush all tensorflow

I'm using ubuntu 18.04 with cuda 9.2.
And I can easily install tensorflow-gpu using conda as well as install graph-nets using pip. And
after install all library works fine with my gpu. (cuda9.2 + nvidia_diver 396)
However, once I installed tensoflow-probability-gpu, everything just crushed.
I got the following error for importing any tensorflow related library.

ImportError: lincublas.so.9.0: cannot open shared object file: No such file or directory.

It seems tensorflow-probability-gpu library doesn't support cuda9.2.

Any idea for installing this library?

Thanks.

Use a CNN instead of an MLP in EncodeProcessDecode class

In order to process my node features of shape [batch_size, feature_length] with 1D convolutions, I want to use as the node_model_fn in the MLPGraphIndependent (encoder part) a function make_cnn_model(), replacing the previously used function make_mlp_model() from the examples. Because 1D convs typically operate over a depth channel, I added an additional channel dimension to the node features, yielding the shape [?, feature_length, 1].

In the sonnet library there does exist a ConvNet2D class but unfortunately no implementation for ConvNet1D is available. I have tried to build my own ConvNet1D module with snt.Sequential and a stack of multiple snt.python.modules.conv.Conv1D but failed with the following error:

ValueError: Shape must be rank 2 but is rank 3 for 'EncodeProcessDecode_1/MLPGraphNetwork/graph_network/edge_block/concat' (op: 'ConcatV2') with input shapes: [?,64], [?,268812,128], [?,268812,128], [?,256], []

I assume I must reduce the initially expanded dimension again but can't infer the correct procedure from neither the sonnet nor the graph_nets documentation. I believe the question is better raised here than in the sonnet repo since it seems to be an issue with the subsequent processing of the core or decoder in the EncoderProcessDecode implementation.

no module name tensorflow_probability

import graph_nets as gp
Traceback (most recent call last):
File "", line 1, in
File "/home/bhanuteja/anaconda3/lib/python3.6/site-packages/graph_nets/init.py", line 21, in
from graph_nets import blocks
File "/home/desktopname/anaconda3/lib/python3.6/site-packages/graph_nets/blocks.py", line 38, in
import sonnet as snt
File "/home/desktopname /anaconda3/lib/python3.6/site-packages/sonnet/init.py", line 42, in
from sonnet.python import custom_getters
File "/home/desktopname/anaconda3/lib/python3.6/site-packages/sonnet/python/custom_getters/init.py", line 21, in
from sonnet.python.custom_getters import bayes_by_backprop
File "/home/desktopname/anaconda3/lib/python3.6/site-packages/sonnet/python/custom_getters/bayes_by_backprop.py", line 94, in
import tensorflow_probability as tfp

global features

Is there any document or demo showing how to use "global features"? Particularly, how to use it in a loss function such as:

def create_loss_ops(target_op, output_ops):
  loss_ops = [
      tf.losses.softmax_cross_entropy(target_op.nodes, output_op.nodes) +
      tf.losses.softmax_cross_entropy(target_op.edges, output_op.edges)
      for output_op in output_ops
  ]
  return loss_ops

How to test model with new data?

after training model with Networkx geo random graphs, now I want to test my model with real data. I created a graph from that real data. Now I don't know I must add solution feature and other features to my graph nodes or no? because in shortest path example, testing and training both use same method create_feed_dict

Is it ok,the sge is very low(run the sort demo)

I got this:

09655, T 2719.7, Ltr 0.0125, Lge 0.0431, Ctr 1.0000, Str 1.0000, Cge 0.9911, Sge 0.2200

09742, T 2739.8, Ltr 0.0158, Lge 0.0410, Ctr 1.0000, Str 1.0000, Cge 0.9922, Sge 0.2200

09830, T 2760.2, Ltr 0.0126, Lge 0.0522, Ctr 1.0000, Str 1.0000, Cge 0.9905, Sge 0.2700

09915, T 2780.0, Ltr 0.0128, Lge 0.0478, Ctr 1.0000, Str 1.0000, Cge 0.9906, Sge 0.3100

Motivation for concatenation of states in EncodeProcessDecode's core

Hi, what is the motivation behind concatenating the encoder's output with the previous output of the core in the EncodeProcessDecode model given in the examples?

Neither in the graph nets paper I can find this information nor in the respective comment block in the code this information is given:

    - ...
    - A "Core" graph net, which performs N rounds of processing (message-passing)
    steps. The input to the Core is the concatenation of the Encoder's output
    and the previous output of the Core (labeled "Hidden(t)" below, where "t" is
    the processing step).
    - ...

                      Hidden(t)   Hidden(t+1)
                         |            ^
            *---------*  |  *------*  |  *---------*
            |         |  |  |      |  |  |         |
  Input --->| Encoder |  *->| Core |--*->| Decoder |---> Output(t)
            |         |---->|      |     |         |
            *---------*     *------*     *---------*
    """

Error occurred when converting a `graphs.GraphsTuple` to a sequence of networkx graphs

An error occurred when I converted a GraphsTuple to a sequence of networkx graphs.The graphsTuple was produced by utils_tf.data_dicts_to_graphs_tuple(). And I used utils_np.graphs_tuple_to_networkxs() to convert the GraphsTuple which produced by utils_tf , because I can't find graphs_tuple_to_networkxs() in utils_tf.

the error:
AttributeError Traceback (most recent call last)
in ()
----> 7 graph_nx = utils_np.graphs_tuple_to_networkxs(num_elements_value)
AttributeError: 'list' object has no attribute 'n_node'

print the GraphTuple:
print(num_elements_value)
[GraphsTuple(nodes=array([[0.8761827 ],
[0.7522148 ],
[0.6269338 ],
[0.21133077],
[0.9824985 ],
[0.60169387],
[0.63267815]], dtype=float32), edges=None, receivers=array([0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0,
1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1,
2, 3, 4, 5, 6], dtype=int32), senders=array([0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3,
3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6,
6, 6, 6, 6, 6], dtype=int32), globals=None, n_node=array([7], dtype=int32), n_edge=array([49], dtype=int32))]

There‘s a n_node in the GraphTuple.

ImportError: No module named tensorflow_probability

Hi, I run into a problem about some environmental problem ...
I could not run your demo either on Colab on my local pc. All of them reports ModuleNotFoundError with respect to 'tensorflow_probability'.
For Colab of shortest_path.ipynb, change the install setting to be install_graph_nets_library = "yes", it just reports error like:

ImportErrorTraceback (most recent call last)
<ipython-input-5-c414b43b0fe0> in <module>()
      8 import time
      9 
---> 10 from graph_nets import graphs
     11 from graph_nets import utils_np
     12 from graph_nets import utils_tf

/usr/local/lib/python2.7/dist-packages/graph_nets/__init__.py in <module>()
     19 from __future__ import print_function
     20 
---> 21 from graph_nets import blocks
     22 from graph_nets import graphs
     23 from graph_nets import modules

/usr/local/lib/python2.7/dist-packages/graph_nets/blocks.py in <module>()
     36 from graph_nets import graphs
     37 from graph_nets import utils_tf
---> 38 import sonnet as snt
     39 import tensorflow as tf
     40 

/usr/local/lib/python2.7/dist-packages/sonnet/__init__.py in <module>()
     40 import semantic_version
     41 
---> 42 from sonnet.python import custom_getters
     43 from sonnet.python.modules import experimental
     44 from sonnet.python.modules import nets

/usr/local/lib/python2.7/dist-packages/sonnet/python/custom_getters/__init__.py in <module>()
     19 from __future__ import print_function
     20 
---> 21 from sonnet.python.custom_getters import bayes_by_backprop
     22 from sonnet.python.custom_getters.context import Context
     23 from sonnet.python.custom_getters.non_trainable import non_trainable

/usr/local/lib/python2.7/dist-packages/sonnet/python/custom_getters/bayes_by_backprop.py in <module>()
     92 
     93 import tensorflow as tf
---> 94 import tensorflow_probability as tfp
     95 
     96 _DEFAULT_SCALE_TRANSFORM = tf.nn.softplus

ImportError: No module named tensorflow_probability

Similar error is witnessed locally.

Thank you for you help!

speed considerations for unrolling nodes and edges in the batch dimension?

Most other libraries that have implemented message-passing neural networks (or other graph-network style approaches), pad the input graphs in batches according to something like
node_features: (batch_size, max_nodes, node_features)
edge_features: (batch_size, max_edges, edge_features)

This mirrors the typical approach in recurrent neural networks, where inputs of variable length are zero-padded to give a consistent batch size dimension.

In this library, the batch size is overloaded with the variable node and edge lengths; s.t. the inputs would be
node_features: (total_nodes_in_batch, node_features)
edge_features: (total_edges_in_batch, edge_features)
where the total nodes and edges in each individual batch are subject to change. Are there any implementation-specific performance considerations to having the batch size changing on each iteration? I.e., are these models able to be effectively processed on GPUs, or is there a performance penalty to having to reallocate memory each gradient update?

On a related note, when I look at the device mapping of some of these models on GPUs, I notice that utils_tf.repeat typically gets allocated to the CPU, since there isn't a cumsum gpu optimization in tensorflow. Might be related to tensorflow/tensorflow#19570?

Cannot interpret feed_dict as Tensor

Hi! I'm trying to run a model that predicts node attributes based on global and edge inputs.
I've been largely following the shortest_path.ipynb demo to write my code, and my code at the moment looks as follows (happy to include more if need be!):

# train_input, train_target, test_input etc. are all lists containing nxgraphs

train_input_ph, train_target_ph = create_placeholders(train_input, train_target)
test_input_ph, test_target_ph = create_placeholders(test_input, test_target)

output_train_graphs = graph_net_module(train_input_ph)
output_test_graphs = graph_net_module(test_input_ph)

loss_train = create_loss_ops(train_target_ph, output_train_graphs)
loss_test = create_loss_ops(test_target_ph, output_test_graphs)
....

train_input_ph, train_target_ph, output_train_graphs, output_test_graphs = make_all_runnable_in_session(train_input_ph, train_target_ph, output_train_graphs, output_test_graphs)

In the running training section of code, I then have:

for iteration in range(last_iteration, num_training_iterations):
    last_iteration = iteration
    train_values = sess.run({
        "step": step_op,
        "target": train_target_ph,
        "train_loss": loss_train,
        "outputs": output_train_graphs
    },
    feed_dict={train_input_ph: gn.utils_np.networkxs_to_graphs_tuple(train_input),
               train_target_ph: gn.utils_np.networkxs_to_graphs_tuple(train_target)}
    )

However, when I try to run the second set of code, I get the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/miniconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1091             subfeed_t = self.graph.as_graph_element(
-> 1092                 subfeed, allow_tensor=True, allow_operation=False)
   1093           except Exception as e:

/miniconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in as_graph_element(self, obj, allow_tensor, allow_operation)
   3477     with self._lock:
-> 3478       return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
   3479 

/miniconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in _as_graph_element_locked(self, obj, allow_tensor, allow_operation)
   3566       raise TypeError("Can not convert a %s into a %s." % (type(obj).__name__,
-> 3567                                                            types_str))
   3568 

TypeError: Can not convert a Operation into a Tensor.

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-1103-fddee2f34548> in <module>
     16     },
     17     feed_dict={train_input_ph: gn.utils_np.networkxs_to_graphs_tuple(train_input),
---> 18                train_target_ph: gn.utils_np.networkxs_to_graphs_tuple(train_target)}
     19     )
     20     the_time = time.time()

/miniconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
    927     try:
    928       result = self._run(None, fetches, feed_dict, options_ptr,
--> 929                          run_metadata_ptr)
    930       if run_metadata:
    931         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

/miniconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1093           except Exception as e:
   1094             raise TypeError(
-> 1095                 'Cannot interpret feed_dict key as Tensor: ' + e.args[0])
   1096 
   1097           if isinstance(subfeed_val, ops.Tensor):

TypeError: Cannot interpret feed_dict key as Tensor: Can not convert a Operation into a Tensor.

I notice this is a similar thing to #24 but when I tried the solution there of reducing make_all_runnable_in_session to only act on output_train_graphs and output_test_graphs, I get the following error instead:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/miniconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1091             subfeed_t = self.graph.as_graph_element(
-> 1092                 subfeed, allow_tensor=True, allow_operation=False)
   1093           except Exception as e:

/miniconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in as_graph_element(self, obj, allow_tensor, allow_operation)
   3477     with self._lock:
-> 3478       return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
   3479 

/miniconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in _as_graph_element_locked(self, obj, allow_tensor, allow_operation)
   3566       raise TypeError("Can not convert a %s into a %s." % (type(obj).__name__,
-> 3567                                                            types_str))
   3568 

TypeError: Can not convert a NoneType into a Tensor.

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-1106-fddee2f34548> in <module>
     16     },
     17     feed_dict={train_input_ph: gn.utils_np.networkxs_to_graphs_tuple(train_input),
---> 18                train_target_ph: gn.utils_np.networkxs_to_graphs_tuple(train_target)}
     19     )
     20     the_time = time.time()

/miniconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
    927     try:
    928       result = self._run(None, fetches, feed_dict, options_ptr,
--> 929                          run_metadata_ptr)
    930       if run_metadata:
    931         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

/miniconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
   1093           except Exception as e:
   1094             raise TypeError(
-> 1095                 'Cannot interpret feed_dict key as Tensor: ' + e.args[0])
   1096 
   1097           if isinstance(subfeed_val, ops.Tensor):

TypeError: Cannot interpret feed_dict key as Tensor: Can not convert a NoneType into a Tensor.

What can I do with the feed_dict and session variables to make this all work?

How to get and set the weights of neural networks in GNN

Such as this. How to get the weights of edge_model_fn after training or creation?

import graph_nets as gn
import sonnet as snt

# Provide your own functions to generate graph-structured data.
input_graphs = get_graphs()

# Create the graph network.
graph_net_module = gn.modules.GraphNetwork(
    edge_model_fn=lambda: snt.nets.MLP([32, 32]),
    node_model_fn=lambda: snt.nets.MLP([32, 32]),
    global_model_fn=lambda: snt.nets.MLP([32, 32]))

# Pass the input graphs to the graph network, and return the output graphs.
output_graphs = graph_net_module(input_graphs)

Memory leak running in eager mode

In eager execution mode, running or training GN models results in a memory leak.

Simple code to reproduce issue:

import tensorflow as tf
import numpy as np
import graph_nets
import networkx as nx
from graph_nets.demos.models import EncodeProcessDecode

# Enable eager exec
tf.enable_eager_execution()

# Create some dummy graphs and fill with random data
graphs = []
for gi in range(50):
    g = nx.geographical_threshold_graph(20, 30)
    g.graph['features'] = np.zeros([1], dtype=float)
    for node_index, node_feature in g.nodes(data=True):
        g.add_node(node_index, features=np.random.rand(3))
    for s,t,f in g.edges(data=True):
        g.add_edge(s,t, features=np.random.rand(3))
    
    graphs.append(g)

xs = graph_nets.utils_np.networkxs_to_graphs_tuple(graphs)

# network needs tensors, not numpy
xs = xs.map(lambda a: tf.constant(a), fields=graph_nets.graphs.ALL_FIELDS)


model = EncodeProcessDecode(edge_output_size=3, node_output_size=3)

# execution loop, reusing the same model and same data
# with each iteration, the memory usage increases and is never collected
for i in range(1000):
    if i % 10 == 0: print("step:", i)
    model(xs, num_processing_steps=2)

In graph execution mode the memory leak doesn't happen.

Relevant package versions:

tensorflow-gpu==1.12.0
tensorflow-probability-gpu==0.4.0
dm-sonnet==1.23
graph-nets==1.0.2

I create my own graphs with the code as

def get_ordered_multi_digraph():
  G = nx.OrderedMultiDiGraph()
  # 定义图的节点
  for node_index in range(10):    
    # add_node 接受attr_dict=None, **attr. 
    # graph_nets的networkx_to_data_dict方法需要graph具有一个feature属性,
    # feature属性表示的是节点的特征
    G.add_node(node_index, features=np.array([node_index]))
  
  # 定义 receivers和senders 
  senders = [1,1,2,2,3,4,5,3]
  receivers = [2,3,4,5,6,8,8,7]
  # 定义边
  for edge_index, (receiver, sender) in enumerate(zip(receivers, senders)):
    # Removing the "index" key makes this test fail 100%.
    edge_data = {"features": np.array([edge_index]), "index": edge_index}
    G.add_edge(sender, receiver, **edge_data)
  G.graph["features"] = np.array([0.])
  #H = nx.path_graph(10)  # 生成10个节点,由0-9表示,由10-1条边线性连接
  #G.add_nodes_from(H) # 把10个节点加入到图里
  #G.add_edges_from([(1,2),(1,3),(2,4),(2,5),(3,6),(4,8),(5,8),(3,7)], weight=3) # 把指定的节点连接起来
  print(list(G.nodes(data=True)))
  return G  

When I run the sample as

nxs = get_ordered_multi_digraph()
show_graph(nxs)
input_graphs = utils_np.networkxs_to_graphs_tuple([nxs])
# input_graphs = utils_np.data_dicts_to_graphs_tuple([data_dic])
# Create the graph network module.
graph_net_module = gn.modules.GraphNetwork(
    edge_model_fn=lambda: snt.nets.MLP([32, 32]),
    node_model_fn=lambda: snt.nets.MLP([32, 32]),
    global_model_fn=lambda: snt.nets.MLP([32, 32]))

# Pass the input graphs to the graph network, and return the output graphs.
output_graphs = graph_net_module(input_graphs)
res = utils_np.graphs_tuple_to_networkxs(output_graphs)

I got an error as

/usr/local/lib/python3.6/dist-packages/graph_nets/utils_tf.py in repeat(tensor, repeats, axis, name)
    535     repeated_tensor = _inside_to_axis(repeated_shifted_tensor, axis)
    536 
--> 537     shape = tensor.shape.as_list()
    538     shape[axis] = None
    539     repeated_tensor.set_shape(shape)

AttributeError: 'tuple' object has no attribute 'as_list'

originally defined at:
  File "<ipython-input-8-a4b8bd9ccc0d>", line 11, in <module>
    global_model_fn=lambda: snt.nets.MLP([32, 32]))
  File "/usr/local/lib/python3.6/dist-packages/graph_nets/modules.py", line 282, in __init__
    edge_model_fn=edge_model_fn, **edge_block_opt)
  File "/usr/local/lib/python3.6/dist-packages/graph_nets/blocks.py", line 403, in __init__
    super(EdgeBlock, self).__init__(name=name)
  File "/usr/local/lib/python3.6/dist-packages/sonnet/python/modules/base.py", line 215, in __init__
    custom_getter_=self._custom_getter)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/template.py", line 154, in make_template
    **kwargs)

I use tfp-nightly-0.6.0 and dm-sonnet-1.23, graph-nets-1.0.2

Originally posted by @jcsh4326 in #6 (comment)

Failed to run optimizer ArithmeticOptimizer, stage RemoveStackStridedSliceSameAxis.

Getting this error when I run blocks_test.py, modules_test.py, and utils_tf_test.py.

2018-10-22 14:07:06.293160: W ./tensorflow/core/grappler/optimizers/graph_optimizer_stage.h:241] Failed to run optimizer ArithmeticOptimizer, stage RemoveStackStridedSliceSameAxis. Error: Pack node (data_dicts_to_graphs_tuple/stack) axis attribute is out of bounds: 0

Was using tensorflow version 1.13.0-dev20181022.

Large numbers of message passing steps

Hi, I am trying to adapt a model, similar to the shortest path problem, to a use case with large graphs (~5000 nodes), and needing to propagate information across the full width of the graph. From what I understand, I need to use a number of message passing steps >= the longest path in the graph to guarantee this. I only need the output graph of the decoder after the final step. The Encode-process-decode architecture unrolls the core for all n processing steps - this creates an enormous graph for large numbers of processing steps.

  1. Is it possible to use the Encode-process-decode architecture for very large numbers of message passing steps?
  2. If not, is there an architecture that will handle this case? I think the solution I need is a Recurrent GN architecture, but I'm having a hard time understanding the difference in implementation from the "Relational inductive biases..." paper.

Cheers,
Chris

"shortest path demo" example

if multiple shortest path(with the same distance) exist in the graph I want to add those solutions to graph and train. how can I do add multiple solutions to graph detect prediction in output?

Nodes without feature

My nodes haven't feature in my problem and I used None for that purpose but I get below error when running my code:
AttributeError: 'NoneType' object has no attribute 'get_shape'

when I added popery to feature I can run it.

tnx

Passing a training flag into EncodeProcessDecode model

So far I have failed to adapt the EncodeProcessDecode module s.t. training and testing phases can be distinguished (e.g. for the purpose of deactivating the adding of noise on latent reps during test time).

This is mainly due to the fact that a "is_training" boolean flag is typically passed when encoder, core and decoder have been already initialized (but not built) and I want to have the same EncodeProcessDecode model for train/test (i.e. no two separate train/test model objects but rather two train test tf ops). Therefore my understanding is that I somehow must be able to pass this flag into EncodeProcessDecode's _build() function. However, this function calls modules.GraphIndependent and here the number of arguments passed is pre-defined (naimly inputs and num_processing_steps)

Since this seems like a common use case to me, I was wondering how folks at DeepMind deal with this. Of course I could change the sonnet interface of GraphIndependent but that does not seem like a scalable solution to me. I could also not find a particular example for this in the documentation. Could you perhaps provide a minimum working example for this use case or provide some ideas how to do this?

Thank you!

I executed Usage example is error

launchx@launchx-System-Product-Name:~$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import graph_nets as gn
import sonnet as snt
input_graphs = get_graphs()
Traceback (most recent call last):
File "", line 1, in
NameError: name 'get_graphs' is not defined
graph_net_module = gn.modules.GraphNetwork(
... edge_model_fn=lambda: snt.nets.MLP([32, 32]),
... node_model_fn=lambda: snt.nets.MLP([32, 32]),
... global_model_fn=lambda: snt.nets.MLP([32, 32]))
output_graphs = graph_net_module(input_graphs)
Traceback (most recent call last):
File "", line 1, in
NameError: name 'input_graphs' is not defined

error

SMALL_GRAPH_1 = {
"globals": [-1.1, -1.2, -1.3],
#"nodes": [[-10.1, -10.2], [-20.1, -20.2], [-30.1, -30.2]],
"nodes": np.zeros((3,4,4,4), dtype=np.float32),
"edges": [[-101., -102., -103., -104.]],
"senders": [1,],
"receivers": [2,],
}
input_graphs = utils_tf.data_dicts_to_graphs_tuple(
[SMALL_GRAPH_1])
graph_net_module = gn.modules.GraphNetwork(
edge_model_fn=lambda: snt.nets.MLP([32, 32]),
node_model_fn=functools.partial(snt.Conv2D, output_channels=10, kernel_shape=[3, 3]), padding='VALID')),
global_model_fn=lambda: snt.nets.MLP([32, 32])
)
output_graphs = graph_net_module(input_graphs)

When i run the code ,there ara an error(Shape must be rank 2 but is rank 4 for 'graph_network_9_1)
I"d like to konw wheather only snt.nets.MLP() function can be use

Understand Some Physics Demo Constants

I'm working through the demos to inform my approach to a graph problem, but there are two constants in the physics example that I don't understand. I was hoping you could provide a bit of context.

Both are in the base_graph function.

I can't find any physical analog to this constant number 5.

nodes = np.zeros((n, 5), dtype=np.float32)

Or for this globals 0.

return {
    "globals": [0., -10.],
    ...
}

Batch processing with list of lists of input and ground truth graphs

Hi,
to my best knowledge, the graph net examples don’t show how to process list of lists of graphs as batches. Here's an example to provide more details:

I have created lists of GraphsTuple that have shape:

input_graph: (1,)
target_graphs: (10,)

If I stack these single examples (say batch_size=20), I get the following:

input_graphs: (20, 1)
target_graphs: (20, 10)

Batch processing is possible for a list of graphs (I've been using this so far with utils_tf.placeholders_from_networkxs() that takes lists [but not nested lists] as input). How can batch processing now be done with list of lists?
Using utils_tf.placeholders_from_networkxs() for every single example will yield placeholders with duplicate names as far as I know? This in turn makes it impossible to assemble the feed_dict for the sess.run() since the uniqueness of names is not given and the dict will collapse to a single example.

To illustrate this, here's a code example for the single sample case (shapes input_graphs (1,), target_grpahs (10,)):

input_ph = utils_tf.placeholders_from_networkxs(input_graphs, force_dynamic_num_graphs=True)
target_ph = utils_tf.placeholders_from_networkxs(target_graphs[0], force_dynamic_num_graphs=True)

input_tuple = utils_np.networkxs_to_graphs_tuple([input_graphs])
target_tuple = utils_np.networkxs_to_graphs_tuple(target_graphs) <--- how to deal with list of lists?

input_dct = utils_tf.get_feed_dict(input_ph, input_tuple)
target_dct = utils_tf.get_feed_dict(target_ph, target_tuple)

return {**input_dct, **target_dct}

Is there something I am missing? Thank you.

Organizing the set of input nodes into a hierarchy with additional nodes?

Can the current version of Graph Nets library be used to train a graph neural network that takes a set of nodes as an input and outputs graph that organizes the input nodes into a hierarchy?

This naturally presents the additional challenge of generating additional nodes to group together the input nodes.

Such tasks are necessary, for example, for modelling how natural language, images, lines and arrows work together in diagrams, as exemplified by the Allen Institute for Artificial Intelligence Diagrams (AI2D) dataset: https://allenai.org/plato/diagram-understanding/

Below is an example from AI2D dataset, which shows the layout segmentation that provides the initial nodes for the graph.

Initial data. The blue elements are text blocks, green polygons stand for lines, whereas orange polygons indicate images.
segmentation_0
Input. In addition to the diagram elements, the initial set of of nodes includes an additional node, I0, which is the root node for the entire diagram.
layout_0
Output. According to the annotation schema, labels and lines should be grouped together. This necessitates the creation of grouping nodes (identified by the prefix G), which are then connected to the root node, along with other independent elements (such as the label T3 and the illustration B0).
layout_0

what is for the 'to_one_hot' method in "shortest path demo" example?

Can you explain it? I pass a list of to element and that rise below error:

one_hot = np.eye(max_value)[indices]
IndexError: index 2 is out of bounds for axis 0 with size 2

I know that why rise(target_node_fields = ("solution", "ComId") because this variable has two element). I need to ComId this to distinct my model results.
I'm apreciate for your answer.

error in "networkx_to_data_dict" method

Why below error raise:

Traceback (most recent call last):
  File "C:/Users/Farshid/PycharmProjects/CommunityDetection/Main.py", line 104, in <module>
    num_nodes_min_max_tr, theta)
  File "C:\Users\Farshid\PycharmProjects\CommunityDetection\Helper.py", line 234, in create_placeholders
    input_graphs, force_dynamic_num_graphs=True)
  File "C:\Users\Farshid\AppData\Local\Programs\Python\Python35\lib\site-packages\graph_nets\utils_tf.py", line 327, in placeholders_from_networkxs
    data_type_hint.as_numpy_dtype())
  File "C:\Users\Farshid\AppData\Local\Programs\Python\Python35\lib\site-packages\graph_nets\utils_np.py", line 337, in networkxs_to_graphs_tuple
    edge_shape_hint, data_type_hint)
  File "C:\Users\Farshid\AppData\Local\Programs\Python\Python35\lib\site-packages\graph_nets\utils_np.py", line 200, in networkx_to_data_dict
    for x in edge_attr_dicts
  File "C:\Users\Farshid\AppData\Local\Programs\Python\Python35\lib\site-packages\graph_nets\utils_np.py", line 201, in <listcomp>
    if x[GRAPH_NX_FEATURES_KEY] is not None
KeyError: 'features'

Compute Accuracy

Is compute_accuracy method is general for all problems or that is specific just shortest_path example?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.