def signature(self): """ This property computes the signature of the dataset, which can be passed to `spektral.data.utils.to_tf_signature(signature)` to compute the TensorFlow signature. You can safely ignore this property unless you are creating a custom `Loader`. A signature consist of the TensorFlow TypeSpec, shape, and dtype of all characteristic matrices of the graphs in the Dataset. This is returned as a dictionary of dictionaries, with keys `x`, `a`, `e`, and `y` for the four main data matrices. Each sub-dictionary will have keys `spec`, `shape` and `dtype`. """ if len(self.graphs) == 0: return None signature = {} graph = self.graphs[0] # This is always non-empty if graph.x is not None: signature["x"] = dict() signature["x"]["spec"] = get_spec(graph.x) signature["x"]["shape"] = (None, self.n_node_features) signature["x"]["dtype"] = tf.as_dtype(graph.x.dtype) if graph.a is not None: signature["a"] = dict() signature["a"]["spec"] = get_spec(graph.a) signature["a"]["shape"] = (None, None) signature["a"]["dtype"] = tf.as_dtype(graph.a.dtype) if graph.e is not None: signature["e"] = dict() signature["e"]["spec"] = get_spec(graph.e) signature["e"]["shape"] = (None, self.n_edge_features) signature["e"]["dtype"] = tf.as_dtype(graph.e.dtype) if graph.y is not None: signature["y"] = dict() signature["y"]["spec"] = get_spec(graph.y) signature["y"]["shape"] = (self.n_labels, ) signature["y"]["dtype"] = tf.as_dtype(np.array(graph.y).dtype) return signature
def tf_signature(self): """ Adjacency matrix has shape [n_nodes, n_nodes] Node features have shape [batch, n_nodes, n_node_features] Edge features have shape [batch, n_edges, n_edge_features] Targets have shape [batch, ..., n_labels] """ signature = self.dataset.signature for k in ["x", "e", "y"]: if k in signature: signature[k]["shape"] = prepend_none(signature[k]["shape"]) signature["a"] = dict() signature["a"]["spec"] = get_spec(self.dataset.a) signature["a"]["shape"] = (None, None) signature["a"]["dtype"] = tf.as_dtype(self.dataset.a.dtype) return to_tf_signature(signature)