Easy to learn

PaddlePaddle provides multitudes of tools and tutorials; Become a deep learning developer in no time.

Ease of use

PaddlePaddle provides an intuitive and flexible interface for loading data and specifying model structures; Bring your creativity to reality.

Security

PaddlePaddle is backed by Baidu’s AI technology and business practices. The framework is safe and stable. Focus your works and not worries.

Efficiency

It also provides extremely optimized operations, memory, and network communication. Kick start your projects in no time with the latest Baidu business models.

Install

Get PaddlePaddle up and running quick after installing the newest version of pip

$

pip install paddlepaddle

Get Started

                                
# Include libraries.
import paddle
import paddle.fluid as fluid
import numpy

                                
# Configure the neural network and train.
def train(save_dirname):
    x = fluid.layers.data(name='x', shape=[13], dtype='float32')
    y_predict = fluid.layers.fc(input=x, size=1, act=None)
    y = fluid.layers.data(name='y', shape=[1], dtype='float32')
    cost = fluid.layers.square_error_cost(input=y_predict, label=y)
    avg_cost = fluid.layers.mean(cost)
    sgd_optimizer = fluid.optimizer.SGD(learning_rate=0.001)
    sgd_optimizer.minimize(avg_cost)
    train_reader = paddle.batch(
        paddle.reader.shuffle(paddle.dataset.uci_housing.train(), buf_size=500),
        batch_size=20)
    place = fluid.CPUPlace()
    exe = fluid.Executor(place)

    def train_loop(main_program):
        feeder = fluid.DataFeeder(place=place, feed_list=[x, y])
        exe.run(fluid.default_startup_program())

        PASS_NUM = 1000
        for pass_id in range(PASS_NUM):
            for data in train_reader():
                avg_loss_value, = exe.run(
                    main_program, feed=feeder.feed(data), fetch_list=[avg_cost])
                print(avg_loss_value)
                if avg_loss_value[0] < 5.0:
                    if save_dirname is not None:
                        fluid.io.save_inference_model(
                            save_dirname, ['x'], [y_predict], exe)
                    return

    train_loop(fluid.default_main_program())

                                
# Infer using provided test data.
def infer(save_dirname=None):
    place = fluid.CPUPlace()
    exe = fluid.Executor(place)
    inference_scope = fluid.core.Scope()
    with fluid.scope_guard(inference_scope):
        [inference_program, feed_target_names, fetch_targets] = (
            fluid.io.load_inference_model(save_dirname, exe))
        test_reader = paddle.batch(paddle.dataset.uci_housing.test(), batch_size=20)

        test_data = test_reader().next()
        test_feat = numpy.array([data[0] for data in test_data]).astype("float32")
        test_label = numpy.array([data[1] for data in test_data]).astype("float32")

        results = exe.run(inference_program,
                          feed={feed_target_names[0]: numpy.array(test_feat)},
                          fetch_list=fetch_targets)
        print("infer results: ", results[0])
        print("ground truth: ", test_label)


save_dirname = "fit_a_line.inference.model"

train(save_dirname)
infer(save_dirname)
                            

Build powerful applications with PaddlePaddle

models-word2vec

Word2Vec

Express words as real vectors to calculate similarities between them.

models-rs

Recommender System

Recommend potentially interesting information or commodities to users based on their features.

models-sentiment

Understand Sentiment

Predict the emotion expressed in a piece of text as positive or negative.

models-imageclassification

Image Classification

Classify images based on their semantic information.

models-translation

Machine Translation

Translate between different languages via deep learning.

models-ssd2

SSD Object Detection

Use the SSD model in PaddlePaddle for object detection.