Git Product home page Git Product logo

Comments (5)

alvarosg avatar alvarosg commented on June 11, 2024

Thanks for your message!

There are two options here and hopefully at least one of them would work for you:

  • Option 1: if the graphs change structure over time, define the input as a sequence of graphs tuples as you mention. Then you can use this method to get a signature as in the TF demo, but instead of getting a single signature, you can get getting a signature for each graph in the sequence, and passing this list of signatures as the input_signature to the tf.function, because specs passed to tf.function can be arbitrarily nested this should work.
  • Option 2: If all graphs in the sequence share the same structure (nodes and edges), you can make any node features and edge features have shape [total_num_nodes/edges, sequence_length, feature_size], and just give a single GraphsTuple as the input to your update function. Then inside your update function you can do something like this to build graphs at each step:
def update_fn(input_graph_sequence, ...)

  def loop_body(step_i,...):
     graph_step_i = input_graph_sequence.replace(
        nodes=input_graph_sequence.nodes[:, step_i], 
        edges=input_graph_sequence.edges[:, step_i])

  num_steps = input_graph_sequence.nodes.shape.as_list()[1]
  tf.scan(loop_body, tf.range(num_steps), ...)  
 ...

Hope this helps!

from graph_nets.

robertswil avatar robertswil commented on June 11, 2024

This worked. Thanks @alvarosg !

from graph_nets.

robertswil avatar robertswil commented on June 11, 2024

Follow-on issue:

I am passing batches to the model during training like so:

outputs = tf.convert_to_tensor([model(graphs_tuple) for graphs_tuple in inputs])

As a reminder, each batch is an iterable of GaphsTuples, and each GraphsTuple represents a sequence of graphs for one training data point.

The GraphIndependent object of the encoder block (EncodeProcessDecode) throws the error: AttributeError: 'GraphsTuple' object has no attribute 'replace'. Location of the error according to the stack trace is here in modules.GraphIndependent``._build().

Any ideas on how to solve?

from graph_nets.

alvarosg avatar alvarosg commented on June 11, 2024

Could you check the type of the object being passed to the model?

My guess is that the GraphsTuple input that your are passing is not actually a graphs.GraphsTuple, but some serialization library or something like that has transformed it into a namedtuple that looks the same, but is not actually the same class, and does not have the extra methods

A simple fix to get the right type just do:

graphs_tuple = graphs.GraphsTuple(*graphs_tuple) before passing it to EncodeProcessDecode, but it may be good to understand where the type gets messed up.

from graph_nets.

robertswil avatar robertswil commented on June 11, 2024

Your hunch was correct! It was being transformed into collections.GraphsTuple during the list comprehension:

outputs = tf.convert_to_tensor([model(inputs) for inputs in inputs_train])

Is that^^ the preferred way to feed a batch of graph sequences during the update step? Wondering if it isn't, since when run graphs.GraphsTuple(*inputs) during training, I receive the following error:

OperatorNotAllowedInGraphError: iterating over 'tf.Tensor' is not allowed: AutGraph did convert this function. This might indicate you are trying to use an unsupported feature.

Checking a bit more, type(inputs) when this error is thrown is a symbolic tensor, not a GraphsTuple, which I guess means this happens before the backend actually runs the first batch through the model.

from graph_nets.

Related Issues (20)

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.