當前位置: 首頁>>代碼示例>>Python>>正文


Python fluid.DataFeeder方法代碼示例

本文整理匯總了Python中paddle.fluid.DataFeeder方法的典型用法代碼示例。如果您正苦於以下問題:Python fluid.DataFeeder方法的具體用法?Python fluid.DataFeeder怎麽用?Python fluid.DataFeeder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在paddle.fluid的用法示例。


在下文中一共展示了fluid.DataFeeder方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: train

# 需要導入模塊: from paddle import fluid [as 別名]
# 或者: from paddle.fluid import DataFeeder [as 別名]
def train(save_dirname):
    x = fluid.layers.data(name='x', shape=[13], dtype='float32')
    y = fluid.layers.data(name='y', shape=[1], dtype='float32')
    y_predict, avg_cost = net(x, y)
    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):
            total_loss_pass = 0
            for data in train_reader():
                avg_loss_value, = exe.run(
                    main_program, feed=feeder.feed(data), fetch_list=[avg_cost])
                total_loss_pass += avg_loss_value
                if avg_loss_value < 5.0:
                    if save_dirname is not None:
                        fluid.io.save_inference_model(
                            save_dirname, ['x'], [y_predict], exe)
                    return
            print("Pass %d, total avg cost = %f" % (pass_id, total_loss_pass))

    train_loop(fluid.default_main_program())


# Infer by using provided test data. 
開發者ID:yeyupiaoling,項目名稱:LearnPaddle2,代碼行數:36,代碼來源:test_paddle.py

示例2: evaluation

# 需要導入模塊: from paddle import fluid [as 別名]
# 或者: from paddle.fluid import DataFeeder [as 別名]
def evaluation(program, reader, fetch_list, place):
    feed_var_list = [
        program.global_block().var('pixel'), program.global_block().var('label')
    ]
    feeder_test = fluid.DataFeeder(feed_list=feed_var_list, place=place)
    test_exe = fluid.Executor(place)
    losses, accuracies = AverageMeter(), AverageMeter()
    for tid, test_data in enumerate(reader()):
        loss, acc = test_exe.run(program=program,
                                 feed=feeder_test.feed(test_data),
                                 fetch_list=fetch_list)
        losses.update(float(loss), len(test_data))
        accuracies.update(float(acc) * 100, len(test_data))
    return losses.avg, accuracies.avg 
開發者ID:PaddlePaddle,項目名稱:AutoDL,代碼行數:16,代碼來源:train_cifar.py


注:本文中的paddle.fluid.DataFeeder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。