@@ -71,25 +71,21 @@ def done(self):
71
71
72
72
class DataFeeder (object ):
73
73
"""
74
- DataFeeder converts the data that returned by paddle. reader into a
75
- data structure of Arguments which is defined in the API . The paddle. reader
74
+ DataFeeder converts the data that returned by a reader into a data
75
+ structure that can feed into Executor and ParallelExecutor . The reader
76
76
usually returns a list of mini-batch data entries. Each data entry in
77
- the list is one sample. Each sample is a list or a tuple with one feature
78
- or multiple features. DataFeeder converts this mini-batch data entries
79
- into Arguments in order to feed it to C++ interface.
77
+ the list is one sample. Each sample is a list or a tuple with one
78
+ feature or multiple features.
80
79
81
80
The simple usage shows below:
82
81
83
82
.. code-block:: python
84
83
85
84
place = fluid.CPUPlace()
86
- data = fluid.layers.data(
87
- name='data', shape=[1], dtype='int64', lod_level=2)
85
+ img = fluid.layers.data(name='image', shape=[1, 28, 28])
88
86
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
89
- feeder = fluid.DataFeeder([data, label], place)
90
-
91
- result = feeder.feed(
92
- [([[1, 2, 3], [4, 5]], [1]), ([[6, 7, 8, 9]], [1])])
87
+ feeder = fluid.DataFeeder([img, label], fluid.CPUPlace())
88
+ result = feeder.feed([([0] * 784, [9]), ([1] * 784, [1])])
93
89
94
90
95
91
If you want to feed data into GPU side separately in advance when you
@@ -105,12 +101,15 @@ class DataFeeder(object):
105
101
Args:
106
102
feed_list(list): The Variables or Variables'name that will
107
103
feed into model.
108
- place(Place): fluid.CPUPlace() or fluid.CUDAPlace(i).
104
+ place(Place): place indicates feed data into CPU or GPU, if you want to
105
+ feed data into GPU, please using `fluid.CUDAPlace(i)` (`i` represents
106
+ the GPU id), or if you want to feed data into CPU, please using
107
+ `fluid.CPUPlace()`.
109
108
program(Program): The Program that will feed data into, if program
110
109
is None, it will use default_main_program(). Default None.
111
110
112
111
Raises:
113
- ValueError: If the some Variable is not in the Program.
112
+ ValueError: If some Variable is not in this Program.
114
113
115
114
Examples:
116
115
.. code-block:: python
@@ -119,7 +118,7 @@ class DataFeeder(object):
119
118
place = fluid.CPUPlace()
120
119
feed_list = [
121
120
main_program.global_block().var(var_name) for var_name in feed_vars_name
122
- ]
121
+ ] # feed_vars_name is a list of variables' name.
123
122
feeder = fluid.DataFeeder(feed_list, place)
124
123
for data in reader():
125
124
outs = exe.run(program=main_program,
@@ -156,8 +155,8 @@ def __init__(self, feed_list, place, program=None):
156
155
157
156
def feed (self , iterable ):
158
157
"""
159
- According to feed_list and iterable converter the input data
160
- into a dictionary that can feed into Executor or ParallelExecutor.
158
+ According to feed_list and iterable, converters the input into
159
+ a data structure that can feed into Executor and ParallelExecutor.
161
160
162
161
Args:
163
162
iterable(list|tuple): the input data.
@@ -189,11 +188,11 @@ def feed(self, iterable):
189
188
def feed_parallel (self , iterable , num_places = None ):
190
189
"""
191
190
Takes multiple mini-batches. Each mini-batch will be feed on each
192
- device.
191
+ device in advance .
193
192
194
193
Args:
195
194
iterable(list|tuple): the input data.
196
- num_places(int): the number of places . Default None.
195
+ num_places(int): the number of devices . Default None.
197
196
198
197
Returns:
199
198
dict: the result of conversion.
0 commit comments