How to use the pgl.utils.paddle_helper.constant function in pgl

To help you get started, we’ve selected a few pgl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PaddlePaddle / PGL / pgl / graph_wrapper.py View on Github external
def __create_graph_node_feat(self, node_feat, collector):
        """Convert node features into paddlepaddle tensor.
        """
        for node_feat_name, node_feat_value in node_feat.items():
            node_feat_shape = node_feat_value.shape
            node_feat_dtype = node_feat_value.dtype
            self._node_feat_tensor_dict[
                node_feat_name], init = paddle_helper.constant(
                    name=self.__data_name_prefix + '/node_feat/' +
                    node_feat_name,
                    dtype=node_feat_dtype,
                    value=node_feat_value)
            collector.append(init)
github PaddlePaddle / PGL / examples / static_gcn / train.py View on Github external
train_loss_t = fluid.layers.softmax_with_cross_entropy(
            logits=pred, label=train_node_label)
        train_loss_t = fluid.layers.reduce_mean(train_loss_t)

        adam = fluid.optimizer.Adam(
            learning_rate=1e-2,
            regularization=fluid.regularizer.L2DecayRegularizer(
                regularization_coeff=0.0005))
        adam.minimize(train_loss_t)

    with fluid.program_guard(val_program, startup_program):
        val_node_index, init = paddle_helper.constant(
            "val_node_index", dtype="int64", value=val_index)
        initializer.append(init)

        val_node_label, init = paddle_helper.constant(
            "val_node_label", dtype="int64", value=val_label)
        initializer.append(init)

        pred = fluid.layers.gather(output, val_node_index)
        val_loss_t, pred = fluid.layers.softmax_with_cross_entropy(
            logits=pred, label=val_node_label, return_softmax=True)
        val_acc_t = fluid.layers.accuracy(
            input=pred, label=val_node_label, k=1)
        val_loss_t = fluid.layers.reduce_mean(val_loss_t)

    with fluid.program_guard(test_program, startup_program):
        test_node_index, init = paddle_helper.constant(
            "test_node_index", dtype="int64", value=test_index)
        initializer.append(init)

        test_node_label, init = paddle_helper.constant(
github PaddlePaddle / PGL / pgl / graph_wrapper.py View on Github external
edge_feat = {}

        for key, value in graph.edge_feat.items():
            edge_feat[key] = value[eid]
        node_feat = graph.node_feat

        self.__create_graph_node_feat(node_feat, self._initializers)
        self.__create_graph_edge_feat(edge_feat, self._initializers)

        self._edges_src, init = paddle_helper.constant(
            dtype="int64",
            value=src,
            name=self.__data_name_prefix + '/edges_src')
        self._initializers.append(init)

        self._edges_dst, init = paddle_helper.constant(
            dtype="int64",
            value=dst,
            name=self.__data_name_prefix + '/edges_dst')
        self._initializers.append(init)

        self._num_nodes, init = paddle_helper.constant(
            dtype="int64",
            hide_batch_size=False,
            value=np.array([graph.num_nodes]),
            name=self.__data_name_prefix + '/num_nodes')
        self._initializers.append(init)

        self._edge_uniq_dst, init = paddle_helper.constant(
            name=self.__data_name_prefix + "/uniq_dst",
            dtype="int64",
            value=uniq_dst)
github PaddlePaddle / PGL / examples / static_gcn / train.py View on Github external
"val_node_index", dtype="int64", value=val_index)
        initializer.append(init)

        val_node_label, init = paddle_helper.constant(
            "val_node_label", dtype="int64", value=val_label)
        initializer.append(init)

        pred = fluid.layers.gather(output, val_node_index)
        val_loss_t, pred = fluid.layers.softmax_with_cross_entropy(
            logits=pred, label=val_node_label, return_softmax=True)
        val_acc_t = fluid.layers.accuracy(
            input=pred, label=val_node_label, k=1)
        val_loss_t = fluid.layers.reduce_mean(val_loss_t)

    with fluid.program_guard(test_program, startup_program):
        test_node_index, init = paddle_helper.constant(
            "test_node_index", dtype="int64", value=test_index)
        initializer.append(init)

        test_node_label, init = paddle_helper.constant(
            "test_node_label", dtype="int64", value=test_label)
        initializer.append(init)

        pred = fluid.layers.gather(output, test_node_index)
        test_loss_t, pred = fluid.layers.softmax_with_cross_entropy(
            logits=pred, label=test_node_label, return_softmax=True)
        test_acc_t = fluid.layers.accuracy(
            input=pred, label=test_node_label, k=1)
        test_loss_t = fluid.layers.reduce_mean(test_loss_t)

    exe = fluid.Executor(place)
    exe.run(startup_program)
github PaddlePaddle / PGL / pgl / graph_wrapper.py View on Github external
self.__create_graph_node_feat(node_feat, self._initializers)
        self.__create_graph_edge_feat(edge_feat, self._initializers)

        self._edges_src, init = paddle_helper.constant(
            dtype="int64",
            value=src,
            name=self.__data_name_prefix + '/edges_src')
        self._initializers.append(init)

        self._edges_dst, init = paddle_helper.constant(
            dtype="int64",
            value=dst,
            name=self.__data_name_prefix + '/edges_dst')
        self._initializers.append(init)

        self._num_nodes, init = paddle_helper.constant(
            dtype="int64",
            hide_batch_size=False,
            value=np.array([graph.num_nodes]),
            name=self.__data_name_prefix + '/num_nodes')
        self._initializers.append(init)

        self._edge_uniq_dst, init = paddle_helper.constant(
            name=self.__data_name_prefix + "/uniq_dst",
            dtype="int64",
            value=uniq_dst)
        self._initializers.append(init)

        self._edge_uniq_dst_count, init = paddle_helper.constant(
            name=self.__data_name_prefix + "/uniq_dst_count",
            dtype="int32",
            value=uniq_dst_count)
github PaddlePaddle / PGL / pgl / graph_wrapper.py View on Github external
def __create_graph_edge_feat(self, edge_feat, collector):
        """Convert edge features into paddlepaddle tensor.
        """
        for edge_feat_name, edge_feat_value in edge_feat.items():
            edge_feat_shape = edge_feat_value.shape
            edge_feat_dtype = edge_feat_value.dtype
            self._edge_feat_tensor_dict[
                edge_feat_name], init = paddle_helper.constant(
                    name=self.__data_name_prefix + '/edge_feat/' +
                    edge_feat_name,
                    dtype=edge_feat_dtype,
                    value=edge_feat_value)
            collector.append(init)