google-deepmind / graph_nets

Build Graph Nets in Tensorflow
https://arxiv.org/abs/1806.01261
Apache License 2.0
5.34k stars 782 forks source link

Setting edges to None yields "You must feed a value for placeholder tensor 'placeholders_from_networkxs/n_edge' with dtype int32 and shape [?]" #70

Closed ferreirafabio closed 5 years ago

ferreirafabio commented 5 years ago

I am trying to run the GN framework on networkx graphs without edges. For this, I have applied the method suggested by @alvarosg from this issue and I use the code suggested from the basics example to set edge attributes to None like this: input_ph = input_ph.replace(edges=None, senders=None, receivers=None, n_edge=input_ph.n_edge * 0)

input_graphs is a single networkx DiGraph and target_graphs is a list of networkx DiGraph's.

When I now try to feed my values in the session, I need to pass an integer for the n_edges. Is there a better way to do this? Can I set n_edge also to None?

Complete code:

create_feed_dict(input_ph, target_ph, input_graph, target_graphs)
    edge_shape_hint_inp = [0 for _ in range(len([input_graphs]))]
    edge_shape_hint_targ = [0 for _ in range(len(target_graphs))]

    input_tuple = utils_np.networkxs_to_graphs_tuple([input_graphs], edge_shape_hint=edge_shape_hint_inp)
    target_tuple = utils_np.networkxs_to_graphs_tuple(target_graphs, edge_shape_hint=edge_shape_hint_targ)

    input_ph = input_ph.replace(edges=None, senders=None, receivers=None, n_edge=input_ph.n_edge * 0)
    input_tuple = input_tuple.replace(edges=None, senders=None, receivers=None, n_edge=input_tuple.n_edge * 0)

    target_ph = target_ph.replace(edges=None, senders=None, receivers=None, n_edge=target_ph.n_edge * 0)
    target_tuple = target_tuple.replace(edges=None, senders=None, receivers=None, n_edge=target_tuple.n_edge * 0)

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

    return input_ph_runnable, target_ph_runnable, {**input_dct, **target_dct}
 input_ph, target_ph, feed_dict = create_feed_dict(input_ph, target_ph)
 data = self.sess.run({"step": step_op, "output_ops_train": output_ops_train, "target": target_ph}, feed_dict=feed_dict)
ferreirafabio commented 5 years ago

Debugging shows me the following feed_dict:

feed-dict

I can also see that output_ops_train contains the NoOp operation assigned by the make_runnable function for receiver, sender and edge attribute. However, the n_edge attribute has a Tensor "mul:0" (same as in screenshot).

ferreirafabio commented 5 years ago

During the function call of utils_tf._build_placeholders_from_specs (called by placeholders_from_networkxs) I see that n_edge is not [0] but [1]. All my graphs have 0 edges (checked with graph.number_of_edges()).

n_edges

vbapst commented 5 years ago

You're probably losing the reference to the n_edge placeholder when you do:

input_ph = input_ph.replace(edges=None, senders=None, receivers=None, n_edge=input_ph.n_edge * 0)

Can you try removing the last assignment in this line?

alvarosg commented 5 years ago

Closing assuming the last answer solved the problem due to inactivity. Please feel free to reopen if the problem persists.