当前位置: 首页>>代码示例>>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;未经允许,请勿转载。