Comments (8)
Thanks for opening the issue. That seems to be taken form the usage example:
import graph_nets as gn
import sonnet as snt
# Provide your own functions to generate graph-structured data.
input_graphs = get_graphs()
In that example get_graphs()
is assumed to be a function provided by the user (see comment) that returns a graphs.GraphsTuple
. You can find more information on how to build those in the demos.
from graph_nets.
As a newbie, I am confused about the data format of Graph Nets input. I don't understand how Graph Nets works. I hope you can provide some simple styles of data. Thank you
from graph_nets.
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
from graph_nets.
Hi, you are feeding numpy data into your graph.
You should do
input_graphs = utils_tf.data_dicts_to_graphs_tuple([data_dic])
from graph_nets.
@vbapst yep, you are right. utils_tf.data_dicts_to_graphs_tuple([data_dic])
fix the no as_list
error well.
And for more information, I should also change my np dtype from int32 to float, for an example,
G.add_node(node_index, features=np.array([node_index]))
should change to
G.add_node(node_index, features=np.array([node_index], dtype=np.float))
from graph_nets.
Run "graph nets basics demo" in browser
The new "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. It should contain most of the answers to these questions.
Hope this helps.
from graph_nets.
Leaving this here as a note to others who might end up here because googling the error has this as a top result. This same error happens if you mistakenly use utils_np.data_dicts_to_graphs_tuple instead of utils_tf.data_dicts_to_graphs_tuple. So ensure you are using the tf version if you are passing the resultant object into tensorflow.
from graph_nets.
NameError: name 'get_graphs' is not defined
from graph_nets.
Related Issues (20)
- Support Apple Silicon HOT 6
- Error while importing sonnet about gast HOT 1
- AttributeError: module 'sonnet' has no attribute 'AbstractModule' HOT 3
- issue with passing *_model_kwargs parameter HOT 2
- how to build an heterogeneous graph network? HOT 3
- Question about repeat implementation HOT 2
- Inference - shortest path demo HOT 1
- What's the difference between graph_nets and jraph? HOT 3
- Performance issue in /graph_nets/tests (by P3) HOT 2
- Error when calling trained model: "AttributeError: tuple object has no attribute "as_list" HOT 3
- Performance issue HOT 9
- Training on batches of GraphsTuples? HOT 5
- Is this project still live? HOT 2
- Error while using the placeholder function from utils_tf HOT 1
- ZeroDivsion error? HOT 2
- no output from processor HOT 6
- Issue with understanding HOT 2
- TensorFlow 1 is not supported in Google Colab HOT 1
- Problem with plot_compare_graphs function HOT 1
- ดูสยองขวัญหนัง เทอม 3 (2024) เต็มเรื่อง เทอม 3 พากย์ไทย FHD1440p
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graph_nets.