def predict(self, predict_data=None, return_logits=True): if not self.model: raise RuntimeError( 'You must compile your model before training/testing/predicting. Use `trainer.build()`.' ) cache = self.cache cfg = self.cfg.predict cfg.return_logits = return_logits if predict_data is None: predict_data = np.arange(self.graph.num_nodes) if not isinstance(predict_data, Sequence): predict_data = gf.asarray(predict_data) predict_data = self.predict_sequence(predict_data) cache.predict_data = predict_data logits = self.predict_step(predict_data) if not return_logits: logits = softmax(logits) return logits.squeeze()
def predict(self, predict_data=None, return_prob=True): """ Predict the output probability for the input data. Note: ---------- You must compile your model before training/testing/predicting. Use `model.build()`. Parameters: ---------- predict_data: Numpy 1D array, optional. The indices of objects to predict. if None, predict the all objects. return_prob: bool. whether to return the probability of prediction. Return: ---------- The predicted probability of each class for each object, for node classification task, it has shape (num_nodes, num_node_classes). """ if not self.model: raise RuntimeError( 'You must compile your model before training/testing/predicting. Use `model.build()`.' ) if predict_data is None: predict_data = np.arange(self.graph.num_nodes, dtype=gg.intx()) if not isinstance(predict_data, Sequence): predict_data = self.predict_sequence(predict_data) self.predict_data = predict_data logit = self.predict_step(predict_data) if return_prob: logit = softmax(logit) return logit
def predict(self, index=None, return_prob=True): """ Predict the output probability for the input node index. Note: ---------- You must compile your model before training/testing/predicting. Use `model.build()`. Parameters: ---------- index: Numpy 1D array, optional. The indices of nodes to predict. if None, predict the all nodes. return_prob: bool. whether to return the probability of prediction. Return: ---------- The predicted probability of each class for each node, shape (n_nodes, n_classes). """ if not self.model: raise RuntimeError( 'You must compile your model before training/testing/predicting. Use `model.build()`.' ) if index is None: index = np.arange(self.graph.n_nodes, dtype=intx()) else: index = asintarr(index) sequence = self.predict_sequence(index) logit = self.predict_step(sequence) if return_prob: logit = softmax(logit) return logit