-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[xdoctest][task 331] reformat example code with google style in python/paddle/base/data_feeder.py #57138
[xdoctest][task 331] reformat example code with google style in python/paddle/base/data_feeder.py #57138
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -350,40 +350,40 @@ class DataFeeder: | |
:code:`ValueError` - If some Variables are not in this Program. | ||
|
||
Example: | ||
.. code-block:: python | ||
.. code-block:: python | ||
|
||
import numpy as np | ||
import paddle | ||
import paddle.base as base | ||
>>> import numpy as np | ||
>>> import paddle | ||
>>> import paddle.base as base | ||
|
||
place = base.CPUPlace() | ||
def reader(): | ||
for _ in range(4): | ||
yield np.random.random([4]).astype('float32'), np.random.random([3]).astype('float32'), | ||
>>> place = base.CPUPlace() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 尽可能不要用 base(原 fluid)
DataFeeder 不用改,没有对应的 API There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 请问下“DataFeeder 不用改,没有对应的 API”是说这个文件不用改代码示例了吗? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
是说 |
||
>>> def reader(): | ||
... for _ in range(4): | ||
... yield np.random.random([4]).astype('float32'), np.random.random([3]).astype('float32'), | ||
... | ||
>>> main_program = base.Program() | ||
>>> startup_program = base.Program() | ||
|
||
main_program = base.Program() | ||
startup_program = base.Program() | ||
>>> with base.program_guard(main_program, startup_program): | ||
... data_1 = paddle.static.data(name='data_1', shape=[None, 2, 2], dtype='float32') | ||
... data_2 = paddle.static.data(name='data_2', shape=[None, 1, 3], dtype='float32') | ||
... out = paddle.static.nn.fc(x=[data_1, data_2], size=2) | ||
... # ... | ||
>>> feeder = base.DataFeeder([data_1, data_2], place) | ||
|
||
with base.program_guard(main_program, startup_program): | ||
data_1 = paddle.static.data(name='data_1', shape=[None, 2, 2], dtype='float32') | ||
data_2 = paddle.static.data(name='data_2', shape=[None, 1, 3], dtype='float32') | ||
out = paddle.static.nn.fc(x=[data_1, data_2], size=2) | ||
# ... | ||
feeder = base.DataFeeder([data_1, data_2], place) | ||
>>> exe = base.Executor(place) | ||
>>> exe.run(startup_program) | ||
|
||
exe = base.Executor(place) | ||
exe.run(startup_program) | ||
>>> feed_data = feeder.feed(reader()) | ||
|
||
feed_data = feeder.feed(reader()) | ||
>>> # print feed_data to view feed results | ||
>>> # print(feed_data['data_1']) | ||
>>> # print(feed_data['data_2']) | ||
|
||
# print feed_data to view feed results | ||
# print(feed_data['data_1']) | ||
# print(feed_data['data_2']) | ||
|
||
outs = exe.run(program=main_program, | ||
feed=feed_data, | ||
fetch_list=[out]) | ||
print(outs) | ||
>>> outs = exe.run(program=main_program, | ||
... feed=feed_data, | ||
... fetch_list=[out]) | ||
>>> print(outs) | ||
|
||
""" | ||
|
||
|
@@ -418,30 +418,30 @@ def feed(self, iterable): | |
:code:`dict`: a :code:`dict` that contains (variable name - converted tensor) pairs | ||
|
||
Example: | ||
.. code-block:: python | ||
|
||
# In this example, reader - generator will return a list of ndarray of 3 elements | ||
# feed API will convert each ndarray input into a tensor | ||
# the return result is a dict with keys: data_1, data_2, data_3 | ||
# result['data_1'] a LoD-Tensor with shape of [5, 2, 1, 3]. 5 is batch size, and [2, 1, 3] is the real shape of data_1. | ||
# result['data_2'], result['data_3'] are similar. | ||
import numpy as np | ||
import paddle.base as base | ||
|
||
def reader(limit=5): | ||
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') | ||
|
||
data_1 = paddle.static.data(name='data_1', shape=[None, 2, 1, 3]) | ||
data_2 = paddle.static.data(name='data_2', shape=[None, 1], dtype='int64') | ||
data_3 = paddle.static.data(name='data_3', shape=[None, 3, 3], dtype='float32') | ||
feeder = base.DataFeeder(['data_1','data_2', 'data_3'], base.CPUPlace()) | ||
|
||
|
||
result = feeder.feed(reader()) | ||
print(result['data_1']) | ||
print(result['data_2']) | ||
print(result['data_3']) | ||
.. code-block:: python | ||
|
||
>>> # In this example, reader - generator will return a list of ndarray of 3 elements | ||
>>> # feed API will convert each ndarray input into a tensor | ||
>>> # the return result is a dict with keys: data_1, data_2, data_3 | ||
>>> # result['data_1'] a LoD-Tensor with shape of [5, 2, 1, 3]. 5 is batch size, and [2, 1, 3] is the real shape of data_1. | ||
>>> # result['data_2'], result['data_3'] are similar. | ||
>>> import numpy as np | ||
>>> import paddle.base as base | ||
|
||
>>> def reader(limit=5): | ||
... 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') | ||
... | ||
>>> data_1 = paddle.static.data(name='data_1', shape=[None, 2, 1, 3]) | ||
>>> data_2 = paddle.static.data(name='data_2', shape=[None, 1], dtype='int64') | ||
>>> data_3 = paddle.static.data(name='data_3', shape=[None, 3, 3], dtype='float32') | ||
>>> feeder = base.DataFeeder(['data_1','data_2', 'data_3'], base.CPUPlace()) | ||
|
||
|
||
>>> result = feeder.feed(reader()) | ||
>>> print(result['data_1']) | ||
>>> print(result['data_2']) | ||
>>> print(result['data_3']) | ||
|
||
""" | ||
converter = [] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些静态图示例代码需要添加
paddle.enable_static()
才能跑