未验证 提交 9dc83dda 编写于 作者: L liuwei1031 提交者: GitHub

update data feeder API sample, change fluid.layers.data to fluid.data (#20568)

* update data feeder API sample, fluid.layers.data => fluid.data

* update API.spec
上级 9d6ee5eb
...@@ -1135,11 +1135,11 @@ paddle.fluid.ParamAttr ('paddle.fluid.param_attr.ParamAttr', ('document', '7b5bf ...@@ -1135,11 +1135,11 @@ paddle.fluid.ParamAttr ('paddle.fluid.param_attr.ParamAttr', ('document', '7b5bf
paddle.fluid.ParamAttr.__init__ (ArgSpec(args=['self', 'name', 'initializer', 'learning_rate', 'regularizer', 'trainable', 'gradient_clip', 'do_model_average'], varargs=None, keywords=None, defaults=(None, None, 1.0, None, True, None, True)), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.ParamAttr.__init__ (ArgSpec(args=['self', 'name', 'initializer', 'learning_rate', 'regularizer', 'trainable', 'gradient_clip', 'do_model_average'], varargs=None, keywords=None, defaults=(None, None, 1.0, None, True, None, True)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.WeightNormParamAttr ('paddle.fluid.param_attr.WeightNormParamAttr', ('document', 'ea029ec9e0dea75f136211c433154f25')) paddle.fluid.WeightNormParamAttr ('paddle.fluid.param_attr.WeightNormParamAttr', ('document', 'ea029ec9e0dea75f136211c433154f25'))
paddle.fluid.WeightNormParamAttr.__init__ (ArgSpec(args=['self', 'dim', 'name', 'initializer', 'learning_rate', 'regularizer', 'trainable', 'gradient_clip', 'do_model_average'], varargs=None, keywords=None, defaults=(None, None, None, 1.0, None, True, None, False)), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.WeightNormParamAttr.__init__ (ArgSpec(args=['self', 'dim', 'name', 'initializer', 'learning_rate', 'regularizer', 'trainable', 'gradient_clip', 'do_model_average'], varargs=None, keywords=None, defaults=(None, None, None, 1.0, None, True, None, False)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.DataFeeder ('paddle.fluid.data_feeder.DataFeeder', ('document', '9e83e9c52fe5b234df4e29d07f382995')) paddle.fluid.DataFeeder ('paddle.fluid.data_feeder.DataFeeder', ('document', 'ac4eff522fe9929d1d74099cd9ad813e'))
paddle.fluid.DataFeeder.__init__ (ArgSpec(args=['self', 'feed_list', 'place', 'program'], varargs=None, keywords=None, defaults=(None,)), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.DataFeeder.__init__ (ArgSpec(args=['self', 'feed_list', 'place', 'program'], varargs=None, keywords=None, defaults=(None,)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.DataFeeder.decorate_reader (ArgSpec(args=['self', 'reader', 'multi_devices', 'num_places', 'drop_last'], varargs=None, keywords=None, defaults=(None, True)), ('document', '982feeee2611898d312fdf12580409d7')) paddle.fluid.DataFeeder.decorate_reader (ArgSpec(args=['self', 'reader', 'multi_devices', 'num_places', 'drop_last'], varargs=None, keywords=None, defaults=(None, True)), ('document', '7b3363c6ee7565881261e9f4ba7442c9'))
paddle.fluid.DataFeeder.feed (ArgSpec(args=['self', 'iterable'], varargs=None, keywords=None, defaults=None), ('document', '69ee4aeeb5cd8c8e5922560457d318ba')) paddle.fluid.DataFeeder.feed (ArgSpec(args=['self', 'iterable'], varargs=None, keywords=None, defaults=None), ('document', '4db18611f5f865c63c633a5edab71992'))
paddle.fluid.DataFeeder.feed_parallel (ArgSpec(args=['self', 'iterable', 'num_places'], varargs=None, keywords=None, defaults=(None,)), ('document', '19fe07f2e40f938003f66f39798ec7d6')) paddle.fluid.DataFeeder.feed_parallel (ArgSpec(args=['self', 'iterable', 'num_places'], varargs=None, keywords=None, defaults=(None,)), ('document', 'b1ecc829c904d4be2e07e2895ef376a6'))
paddle.fluid.clip.set_gradient_clip (ArgSpec(args=['clip', 'param_list', 'program'], varargs=None, keywords=None, defaults=(None, None)), ('document', '7a0f76a77dd88a74f24485a103a22fc1')) paddle.fluid.clip.set_gradient_clip (ArgSpec(args=['clip', 'param_list', 'program'], varargs=None, keywords=None, defaults=(None, None)), ('document', '7a0f76a77dd88a74f24485a103a22fc1'))
paddle.fluid.clip.ErrorClipByValue ('paddle.fluid.clip.ErrorClipByValue', ('document', '629b07558971a8ab5e954d9a77457656')) paddle.fluid.clip.ErrorClipByValue ('paddle.fluid.clip.ErrorClipByValue', ('document', '629b07558971a8ab5e954d9a77457656'))
paddle.fluid.clip.ErrorClipByValue.__init__ (ArgSpec(args=['self', 'max', 'min'], varargs=None, keywords=None, defaults=(None,)), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.clip.ErrorClipByValue.__init__ (ArgSpec(args=['self', 'max', 'min'], varargs=None, keywords=None, defaults=(None,)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
......
...@@ -173,7 +173,6 @@ class DataFeeder(object): ...@@ -173,7 +173,6 @@ class DataFeeder(object):
Example: Example:
.. code-block:: python .. code-block:: python
import numpy as np import numpy as np
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
...@@ -187,8 +186,8 @@ class DataFeeder(object): ...@@ -187,8 +186,8 @@ class DataFeeder(object):
startup_program = fluid.Program() startup_program = fluid.Program()
with fluid.program_guard(main_program, startup_program): with fluid.program_guard(main_program, startup_program):
data_1 = fluid.layers.data(name='data_1', shape=[-1, 2, 2]) data_1 = fluid.data(name='data_1', shape=[None, 2, 2], dtype='float32')
data_2 = fluid.layers.data(name='data_2', shape=[-1, 1, 3]) data_2 = fluid.data(name='data_2', shape=[None, 1, 3], dtype='float32')
out = fluid.layers.fc(input=[data_1, data_2], size=2) out = fluid.layers.fc(input=[data_1, data_2], size=2)
# ... # ...
feeder = fluid.DataFeeder([data_1, data_2], place) feeder = fluid.DataFeeder([data_1, data_2], place)
...@@ -207,7 +206,6 @@ class DataFeeder(object): ...@@ -207,7 +206,6 @@ class DataFeeder(object):
fetch_list=[out]) fetch_list=[out])
print(outs) print(outs)
""" """
def __init__(self, feed_list, place, program=None): def __init__(self, feed_list, place, program=None):
...@@ -255,9 +253,9 @@ class DataFeeder(object): ...@@ -255,9 +253,9 @@ class DataFeeder(object):
for i in range(1, limit + 1): for i in range(1, limit + 1):
yield np.ones([6]).astype('float32') * i , np.ones([1]).astype('int64') * i, np.random.random([9]).astype('float32') yield np.ones([6]).astype('float32') * i , np.ones([1]).astype('int64') * i, np.random.random([9]).astype('float32')
data_1 = fluid.layers.data(name='data_1', shape=[2, 1, 3]) data_1 = fluid.data(name='data_1', shape=[None, 2, 1, 3])
data_2 = fluid.layers.data(name='data_2', shape=[1], dtype='int64') data_2 = fluid.data(name='data_2', shape=[None, 1], dtype='int64')
data_3 = fluid.layers.data(name='data_3', shape=[3, 3], dtype='float32') data_3 = fluid.data(name='data_3', shape=[None, 3, 3], dtype='float32')
feeder = fluid.DataFeeder(['data_1','data_2', 'data_3'], fluid.CPUPlace()) feeder = fluid.DataFeeder(['data_1','data_2', 'data_3'], fluid.CPUPlace())
...@@ -266,7 +264,6 @@ class DataFeeder(object): ...@@ -266,7 +264,6 @@ class DataFeeder(object):
print(result['data_2']) print(result['data_2'])
print(result['data_3']) print(result['data_3'])
""" """
converter = [] converter = []
for lod_level, shape, dtype in six.moves.zip( for lod_level, shape, dtype in six.moves.zip(
...@@ -313,7 +310,6 @@ class DataFeeder(object): ...@@ -313,7 +310,6 @@ class DataFeeder(object):
Example: Example:
.. code-block:: python .. code-block:: python
import numpy as np import numpy as np
import paddle.fluid as fluid import paddle.fluid as fluid
...@@ -323,8 +319,8 @@ class DataFeeder(object): ...@@ -323,8 +319,8 @@ class DataFeeder(object):
yield np.ones([4]) * factor + base, np.ones([4]) * factor + base + 5 yield np.ones([4]) * factor + base, np.ones([4]) * factor + base + 5
return _reader() return _reader()
x = fluid.layers.data(name='x', shape=[-1, 2, 2]) x = fluid.data(name='x', shape=[None, 2, 2])
y = fluid.layers.data(name='y', shape=[-1, 2, 2], dtype='float32') y = fluid.data(name='y', shape=[None, 2, 2], dtype='float32')
z = fluid.layers.elementwise_add(x, y) z = fluid.layers.elementwise_add(x, y)
...@@ -345,7 +341,6 @@ class DataFeeder(object): ...@@ -345,7 +341,6 @@ class DataFeeder(object):
res = exe.run(program=program, feed=list(feeder.feed_parallel(reader_list, 2)), fetch_list=[z]) res = exe.run(program=program, feed=list(feeder.feed_parallel(reader_list, 2)), fetch_list=[z])
print(res) print(res)
""" """
if isinstance(self.place, core.CUDAPlace): if isinstance(self.place, core.CUDAPlace):
places = [ places = [
...@@ -426,8 +421,8 @@ class DataFeeder(object): ...@@ -426,8 +421,8 @@ class DataFeeder(object):
places = [fluid.CPUPlace() for _ in range(place_num)] places = [fluid.CPUPlace() for _ in range(place_num)]
# a simple network sample # a simple network sample
data = fluid.layers.data(name='data', shape=[-1, 4, 4], dtype='float32') data = fluid.data(name='data', shape=[None, 4, 4], dtype='float32')
label = fluid.layers.data(name='label', shape=[-1, 1], dtype='int64') label = fluid.data(name='label', shape=[None, 1], dtype='int64')
hidden = fluid.layers.fc(input=data, size=10) hidden = fluid.layers.fc(input=data, size=10)
feeder = fluid.DataFeeder(place=places[0], feed_list=[data, label]) feeder = fluid.DataFeeder(place=places[0], feed_list=[data, label])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册