paddle中train函数的参数feeding
收藏
看了paddle的训练的参数定义如下:
def train(self, reader, num_passes=1, event_handler=None, feeding=None)
其中feeding这个怎么理解,看代码好像是为了兼容样本的输入格式,能不能举个具体的例子说下,看demo中有些没有加这些参数,有些加了。
譬如样本格式分别如下:
1.([1,2,3,],[4,5,],[4,5,6,7])来自nmt的样本,不加feeding
2.([1.0, 2.0, 3.0, ...], 5) 来自text-calassfication的样本,加feeding
def train(self, reader, num_passes=1, event_handler=None, feeding=None)
其中feeding这个怎么理解,看代码好像是为了兼容样本的输入格式,能不能举个具体的例子说下,看demo中有些没有加这些参数,有些加了。
譬如样本格式分别如下:
1.([1,2,3,],[4,5,],[4,5,6,7])来自nmt的样本,不加feeding
2.([1.0, 2.0, 3.0, ...], 5) 来自text-calassfication的样本,加feeding
0
收藏
请登录后评论
可以参考注释:
Paddle/python/paddle/v2/data_feeder.py
Lines 28 to 84 in 5008020
class DataFeeder(DataProviderConverter):
"""
DataFeeder converts the data returned by paddle.reader into a data structure
of Arguments which is defined in the API. The paddle.reader usually returns
a list of mini-batch data entries. Each data entry in the list is one sample.
Each sample is a list or a tuple with one feature or multiple features.
DataFeeder converts this mini-batch data entries into Arguments in order
to feed it to C++ interface.
The simple usage shows below
.. code-block:: python
feeding = ['image', 'label']
data_types = enumerate_data_types_of_data_layers(topology)
feeder = DataFeeder(data_types=data_types, feeding=feeding)
minibatch_data = [([1.0, 2.0, 3.0, ...], 5)]
arg = feeder(minibatch_data)
If mini-batch data and data layers are not one to one mapping, we
could pass a dictionary to feeding parameter to represent the mapping
relationship.
.. code-block:: python
data_types = [('image', paddle.data_type.dense_vector(784)),
('label', paddle.data_type.integer_value(10))]
feeding = {'image':0, 'label':1}
feeder = DataFeeder(data_types=data_types, feeding=feeding)
minibatch_data = [
( [1.0,2.0,3.0,4.0], 5, [6,7,8] ), # first sample
( [1.0,2.0,3.0,4.0], 5, [6,7,8] ) # second sample
]
# or minibatch_data = [
# [ [1.0,2.0,3.0,4.0], 5, [6,7,8] ], # first sample
# [ [1.0,2.0,3.0,4.0], 5, [6,7,8] ] # second sample
# ]
arg = feeder.convert(minibatch_data)
.. note::
This module is for internal use only. Users should use the `reader`
interface.
:param data_types: A list to specify data name and type. Each item is
a tuple of (data_name, data_type).
:type data_types: list
:param feeding: A dictionary or a sequence to specify the position of each
data in the input data.
:type feeding: dict|collections.Sequence|None
简单来说,feeding是一个字典,“If mini-batch data and data layers are not one to one mapping, we could pass a dictionary to feeding parameter to represent the mapping relationship.” 正常情况下,是按顺序排列的。