未验证 提交 47e2ef38 编写于 作者: X xsrobin 提交者: GitHub

add "import paddle.fluid as fluid" to examples lack of it

上级 92ecb305
此差异已折叠。
...@@ -625,6 +625,7 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -625,6 +625,7 @@ All parameter, weight, gradient are variables in Paddle.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
# create tensor from a scope and set value to it. # create tensor from a scope and set value to it.
param = scope.var('Param').get_tensor() param = scope.var('Param').get_tensor()
param_array = np.full((height, row_numel), 5.0).astype("float32") param_array = np.full((height, row_numel), 5.0).astype("float32")
...@@ -781,6 +782,7 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -781,6 +782,7 @@ All parameter, weight, gradient are variables in Paddle.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
gpu_place = fluid.CUDAPlace(0) gpu_place = fluid.CUDAPlace(0)
)DOC") )DOC")
...@@ -839,6 +841,7 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -839,6 +841,7 @@ All parameter, weight, gradient are variables in Paddle.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
cpu_place = fluid.CPUPlace() cpu_place = fluid.CPUPlace()
)DOC") )DOC")
...@@ -858,6 +861,7 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -858,6 +861,7 @@ All parameter, weight, gradient are variables in Paddle.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
place = fluid.CUDAPinnedPlace() place = fluid.CUDAPinnedPlace()
)DOC") )DOC")
...@@ -1156,6 +1160,7 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -1156,6 +1160,7 @@ All parameter, weight, gradient are variables in Paddle.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
x = fluid.layers.data(name='x', shape=[13], dtype='float32') x = fluid.layers.data(name='x', shape=[13], dtype='float32')
y = fluid.layers.data(name='y', shape=[1], dtype='float32') y = fluid.layers.data(name='y', shape=[1], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, act=None) y_predict = fluid.layers.fc(input=x, size=1, act=None)
......
...@@ -49,6 +49,7 @@ class WeightedAverage(object): ...@@ -49,6 +49,7 @@ class WeightedAverage(object):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
avg = fluid.average.WeightedAverage() avg = fluid.average.WeightedAverage()
avg.add(value=2.0, weight=1) avg.add(value=2.0, weight=1)
avg.add(value=4.0, weight=2) avg.add(value=4.0, weight=2)
......
...@@ -489,6 +489,7 @@ def append_backward(loss, parameter_list=None, no_grad_set=None, ...@@ -489,6 +489,7 @@ def append_backward(loss, parameter_list=None, no_grad_set=None,
# network configuration code # network configuration code
# loss from ... # loss from ...
import paddle.fluid as fluid
x = fluid.layers.data(name='x', shape=[13], dtype='float32') x = fluid.layers.data(name='x', shape=[13], dtype='float32')
y = fluid.layers.data(name='y', shape=[1], dtype='float32') y = fluid.layers.data(name='y', shape=[1], dtype='float32')
......
...@@ -31,6 +31,7 @@ class DataFeedDesc(object): ...@@ -31,6 +31,7 @@ class DataFeedDesc(object):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
f = open("data.proto", "w") f = open("data.proto", "w")
print >> f, 'name: "MultiSlotDataFeed"' print >> f, 'name: "MultiSlotDataFeed"'
print >> f, 'batch_size: 2' print >> f, 'batch_size: 2'
...@@ -61,6 +62,7 @@ class DataFeedDesc(object): ...@@ -61,6 +62,7 @@ class DataFeedDesc(object):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
data_feed = fluid.DataFeedDesc('data.proto') data_feed = fluid.DataFeedDesc('data.proto')
data_feed.set_batch_size(128) data_feed.set_batch_size(128)
data_feed.set_dense_slots('wd') # The slot named 'wd' will be dense data_feed.set_dense_slots('wd') # The slot named 'wd' will be dense
...@@ -95,6 +97,7 @@ class DataFeedDesc(object): ...@@ -95,6 +97,7 @@ class DataFeedDesc(object):
Example: Example:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
f = open("data.proto", "w") f = open("data.proto", "w")
print >> f, 'name: "MultiSlotDataFeed"' print >> f, 'name: "MultiSlotDataFeed"'
print >> f, 'batch_size: 2' print >> f, 'batch_size: 2'
...@@ -131,6 +134,7 @@ class DataFeedDesc(object): ...@@ -131,6 +134,7 @@ class DataFeedDesc(object):
Example: Example:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
f = open("data.proto", "w") f = open("data.proto", "w")
print >> f, 'name: "MultiSlotDataFeed"' print >> f, 'name: "MultiSlotDataFeed"'
print >> f, 'batch_size: 2' print >> f, 'batch_size: 2'
...@@ -175,6 +179,7 @@ class DataFeedDesc(object): ...@@ -175,6 +179,7 @@ class DataFeedDesc(object):
Example: Example:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
f = open("data.proto", "w") f = open("data.proto", "w")
print >> f, 'name: "MultiSlotDataFeed"' print >> f, 'name: "MultiSlotDataFeed"'
print >> f, 'batch_size: 2' print >> f, 'batch_size: 2'
...@@ -217,6 +222,7 @@ class DataFeedDesc(object): ...@@ -217,6 +222,7 @@ class DataFeedDesc(object):
Example: Example:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
f = open("data.proto", "w") f = open("data.proto", "w")
print >> f, 'name: "MultiSlotDataFeed"' print >> f, 'name: "MultiSlotDataFeed"'
print >> f, 'batch_size: 2' print >> f, 'batch_size: 2'
......
...@@ -72,6 +72,7 @@ def scope_guard(scope): ...@@ -72,6 +72,7 @@ def scope_guard(scope):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import numpy import numpy
new_scope = fluid.Scope() new_scope = fluid.Scope()
......
...@@ -67,6 +67,7 @@ def in_dygraph_mode(): ...@@ -67,6 +67,7 @@ def in_dygraph_mode():
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
if fluid.in_dygraph_mode(): if fluid.in_dygraph_mode():
pass pass
...@@ -143,6 +144,7 @@ def cuda_places(device_ids=None): ...@@ -143,6 +144,7 @@ def cuda_places(device_ids=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
cuda_places = fluid.cuda_places() cuda_places = fluid.cuda_places()
""" """
...@@ -173,6 +175,7 @@ def cpu_places(device_count=None): ...@@ -173,6 +175,7 @@ def cpu_places(device_count=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
cpu_places = fluid.cpu_places() cpu_places = fluid.cpu_places()
""" """
...@@ -199,6 +202,7 @@ def cuda_pinned_places(device_count=None): ...@@ -199,6 +202,7 @@ def cuda_pinned_places(device_count=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
cuda_pinned_places_cpu_num = fluid.cuda_pinned_places() cuda_pinned_places_cpu_num = fluid.cuda_pinned_places()
# or # or
cuda_pinned_places = fluid.cuda_pinned_places(1) cuda_pinned_places = fluid.cuda_pinned_places(1)
...@@ -251,6 +255,7 @@ def name_scope(prefix=None): ...@@ -251,6 +255,7 @@ def name_scope(prefix=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
with fluid.name_scope("s1"): with fluid.name_scope("s1"):
a = fluid.layers.data(name='data', shape=[1], dtype='int32') a = fluid.layers.data(name='data', shape=[1], dtype='int32')
b = a + 1 b = a + 1
...@@ -412,6 +417,7 @@ class Variable(object): ...@@ -412,6 +417,7 @@ class Variable(object):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
cur_program = Program() cur_program = Program()
cur_block = cur_program.current_block() cur_block = cur_program.current_block()
new_variable = cur_block.create_var(name="X", new_variable = cur_block.create_var(name="X",
...@@ -1011,6 +1017,7 @@ class Operator(object): ...@@ -1011,6 +1017,7 @@ class Operator(object):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
cur_program = Program() cur_program = Program()
cur_block = cur_program.current_block() cur_block = cur_program.current_block()
# var1 += var2 + var3 # var1 += var2 + var3
...@@ -2918,6 +2925,7 @@ class Program(object): ...@@ -2918,6 +2925,7 @@ class Program(object):
Examples: Examples:
>>> import paddle.fluid as fluid
>>> p, g = backward(...) >>> p, g = backward(...)
>>> with program._optimized_guard([p,g]): >>> with program._optimized_guard([p,g]):
>>> p = p - 0.001 * g >>> p = p - 0.001 * g
...@@ -2951,6 +2959,7 @@ class Program(object): ...@@ -2951,6 +2959,7 @@ class Program(object):
Examples: Examples:
>>> import paddle.fluid as fluid
>>> p, g = backward(...) >>> p, g = backward(...)
>>> with program.lr_schedule_guard(): >>> with program.lr_schedule_guard():
>>> lr = lr * decay >>> lr = lr * decay
......
...@@ -42,7 +42,8 @@ def force_init_on_cpu(): ...@@ -42,7 +42,8 @@ def force_init_on_cpu():
.. code-block:: python .. code-block:: python
if fluid.initializer.force_init_on_cpu(): import paddle.fluid as fluid
if fluid.initializer.force_init_on_cpu():
step = fluid.layers.create_global_var( step = fluid.layers.create_global_var(
shape=[2,3], value=1.0, dtype='float32') shape=[2,3], value=1.0, dtype='float32')
...@@ -58,7 +59,8 @@ def init_on_cpu(): ...@@ -58,7 +59,8 @@ def init_on_cpu():
Examples: Examples:
.. code-block:: python .. code-block:: python
with fluid.initializer.init_on_cpu(): import paddle.fluid as fluid
with fluid.initializer.init_on_cpu():
step = fluid.layers.create_global_var( step = fluid.layers.create_global_var(
shape=[2,3], value=1.0, dtype='float32') shape=[2,3], value=1.0, dtype='float32')
...@@ -133,7 +135,8 @@ class ConstantInitializer(Initializer): ...@@ -133,7 +135,8 @@ class ConstantInitializer(Initializer):
Examples: Examples:
.. code-block:: python .. code-block:: python
x = fluid.layers.data(name="data", shape=[32, 32], dtype="float32") import paddle.fluid as fluid
x = fluid.layers.data(name="data", shape=[32, 32], dtype="float32")
fc = fluid.layers.fc(input=x, size=10, fc = fluid.layers.fc(input=x, size=10,
param_attr=fluid.initializer.Constant(value=2.0)) param_attr=fluid.initializer.Constant(value=2.0))
...@@ -292,7 +295,8 @@ class NormalInitializer(Initializer): ...@@ -292,7 +295,8 @@ class NormalInitializer(Initializer):
Examples: Examples:
.. code-block:: python .. code-block:: python
x = fluid.layers.data(name="data", shape=[32, 32], dtype="float32") import paddle.fluid as fluid
x = fluid.layers.data(name="data", shape=[32, 32], dtype="float32")
fc = fluid.layers.fc(input=x, size=10, fc = fluid.layers.fc(input=x, size=10,
param_attr=fluid.initializer.Normal(loc=0.0, scale=2.0)) param_attr=fluid.initializer.Normal(loc=0.0, scale=2.0))
...@@ -608,7 +612,8 @@ class MSRAInitializer(Initializer): ...@@ -608,7 +612,8 @@ class MSRAInitializer(Initializer):
Examples: Examples:
.. code-block:: python .. code-block:: python
x = fluid.layers.data(name="data", shape=[32, 32], dtype="float32") import paddle.fluid as fluid
x = fluid.layers.data(name="data", shape=[32, 32], dtype="float32")
fc = fluid.layers.fc(input=x, size=10, fc = fluid.layers.fc(input=x, size=10,
param_attr=fluid.initializer.MSRA(uniform=False)) param_attr=fluid.initializer.MSRA(uniform=False))
...@@ -710,7 +715,8 @@ class BilinearInitializer(Initializer): ...@@ -710,7 +715,8 @@ class BilinearInitializer(Initializer):
.. code-block:: python .. code-block:: python
factor = 2 import paddle.fluid as fluid
factor = 2
C = 2 C = 2
w_attr = fluid.param_attr.ParamAttr( w_attr = fluid.param_attr.ParamAttr(
learning_rate=0., learning_rate=0.,
...@@ -836,6 +842,7 @@ class NumpyArrayInitializer(Initializer): ...@@ -836,6 +842,7 @@ class NumpyArrayInitializer(Initializer):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
x = fluid.layers.data(name="x", shape=[5], dtype='float32') x = fluid.layers.data(name="x", shape=[5], dtype='float32')
fc = fluid.layers.fc(input=x, size=10, fc = fluid.layers.fc(input=x, size=10,
param_attr=fluid.initializer.NumpyArrayInitializer(numpy.array([1,2]))) param_attr=fluid.initializer.NumpyArrayInitializer(numpy.array([1,2])))
......
...@@ -54,6 +54,7 @@ def is_parameter(var): ...@@ -54,6 +54,7 @@ def is_parameter(var):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
param = fluid.default_main_program().global_block().var('fc.w') param = fluid.default_main_program().global_block().var('fc.w')
res = fluid.io.is_parameter(param) res = fluid.io.is_parameter(param)
""" """
...@@ -74,6 +75,7 @@ def is_persistable(var): ...@@ -74,6 +75,7 @@ def is_persistable(var):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
param = fluid.default_main_program().global_block().var('fc.b') param = fluid.default_main_program().global_block().var('fc.b')
res = fluid.io.is_persistable(param) res = fluid.io.is_persistable(param)
""" """
...@@ -311,6 +313,7 @@ def _save_distributed_persistables(executor, dirname, main_program): ...@@ -311,6 +313,7 @@ def _save_distributed_persistables(executor, dirname, main_program):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
exe = fluid.Executor(fluid.CPUPlace()) exe = fluid.Executor(fluid.CPUPlace())
param_path = "./my_paddle_model" param_path = "./my_paddle_model"
t = distribute_transpiler.DistributeTranspiler() t = distribute_transpiler.DistributeTranspiler()
...@@ -693,6 +696,7 @@ def load_params(executor, dirname, main_program=None, filename=None): ...@@ -693,6 +696,7 @@ def load_params(executor, dirname, main_program=None, filename=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
exe = fluid.Executor(fluid.CPUPlace()) exe = fluid.Executor(fluid.CPUPlace())
param_path = "./my_paddle_model" param_path = "./my_paddle_model"
prog = fluid.default_main_program() prog = fluid.default_main_program()
...@@ -735,6 +739,7 @@ def load_persistables(executor, dirname, main_program=None, filename=None): ...@@ -735,6 +739,7 @@ def load_persistables(executor, dirname, main_program=None, filename=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
exe = fluid.Executor(fluid.CPUPlace()) exe = fluid.Executor(fluid.CPUPlace())
param_path = "./my_paddle_model" param_path = "./my_paddle_model"
prog = fluid.default_main_program() prog = fluid.default_main_program()
...@@ -772,6 +777,7 @@ def _load_distributed_persistables(executor, dirname, main_program=None): ...@@ -772,6 +777,7 @@ def _load_distributed_persistables(executor, dirname, main_program=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
exe = fluid.Executor(fluid.CPUPlace()) exe = fluid.Executor(fluid.CPUPlace())
param_path = "./my_paddle_model" param_path = "./my_paddle_model"
t = distribute_transpiler.DistributeTranspiler() t = distribute_transpiler.DistributeTranspiler()
...@@ -1242,6 +1248,7 @@ def get_parameter_value(para, executor): ...@@ -1242,6 +1248,7 @@ def get_parameter_value(para, executor):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
exe = fluid.Executor(fluid.CPUPlace()) exe = fluid.Executor(fluid.CPUPlace())
param = fluid.default_main_program().global_block().var('fc.w') param = fluid.default_main_program().global_block().var('fc.w')
p = fluid.io.get_parameter_value(param, exe) p = fluid.io.get_parameter_value(param, exe)
...@@ -1279,6 +1286,7 @@ def get_parameter_value_by_name(name, executor, program=None): ...@@ -1279,6 +1286,7 @@ def get_parameter_value_by_name(name, executor, program=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
exe = fluid.Executor(fluid.CPUPlace()) exe = fluid.Executor(fluid.CPUPlace())
p = fluid.io.get_parameter_value('fc.w', exe) p = fluid.io.get_parameter_value('fc.w', exe)
""" """
......
...@@ -58,6 +58,7 @@ def split_lod_tensor(input, mask, level=0): ...@@ -58,6 +58,7 @@ def split_lod_tensor(input, mask, level=0):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
x = fluid.layers.data(name='x', shape=[1]) x = fluid.layers.data(name='x', shape=[1])
x.persistable = True x.persistable = True
...@@ -107,6 +108,7 @@ def merge_lod_tensor(in_true, in_false, x, mask, level=0): ...@@ -107,6 +108,7 @@ def merge_lod_tensor(in_true, in_false, x, mask, level=0):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
x = layers.data( x = layers.data(
name='x', shape=[1], dtype='float32', stop_gradient=False) name='x', shape=[1], dtype='float32', stop_gradient=False)
y = layers.data( y = layers.data(
...@@ -757,6 +759,7 @@ def lod_rank_table(x, level=0): ...@@ -757,6 +759,7 @@ def lod_rank_table(x, level=0):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
x = fluid.layers.data(name='x', shape=[10], x = fluid.layers.data(name='x', shape=[10],
dtype='float32', lod_level=1) dtype='float32', lod_level=1)
out = layers.lod_rank_table(x=x, level=0) out = layers.lod_rank_table(x=x, level=0)
...@@ -823,6 +826,7 @@ def lod_tensor_to_array(x, table): ...@@ -823,6 +826,7 @@ def lod_tensor_to_array(x, table):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
x = fluid.layers.data(name='x', shape=[10]) x = fluid.layers.data(name='x', shape=[10])
table = fluid.layers.lod_rank_table(x, level=0) table = fluid.layers.lod_rank_table(x, level=0)
array = fluid.layers.lod_tensor_to_array(x, table) array = fluid.layers.lod_tensor_to_array(x, table)
...@@ -856,6 +860,7 @@ def array_to_lod_tensor(x, table): ...@@ -856,6 +860,7 @@ def array_to_lod_tensor(x, table):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
x = fluid.layers.data(name='x', shape=[10]) x = fluid.layers.data(name='x', shape=[10])
table = fluid.layers.lod_rank_table(x, level=0) table = fluid.layers.lod_rank_table(x, level=0)
array = fluid.layers.lod_tensor_to_array(x, table) array = fluid.layers.lod_tensor_to_array(x, table)
...@@ -965,6 +970,7 @@ def create_array(dtype): ...@@ -965,6 +970,7 @@ def create_array(dtype):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
data = fluid.layers.create_array(dtype='float32') data = fluid.layers.create_array(dtype='float32')
""" """
...@@ -992,6 +998,7 @@ def less_than(x, y, force_cpu=None, cond=None): ...@@ -992,6 +998,7 @@ def less_than(x, y, force_cpu=None, cond=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
label = fluid.layers.data(name='y', shape=[1], dtype='int64') label = fluid.layers.data(name='y', shape=[1], dtype='int64')
limit = fluid.layers.fill_constant(shape=[1], dtype='int64', value=5) limit = fluid.layers.fill_constant(shape=[1], dtype='int64', value=5)
cond = fluid.layers.less_than(x=label, y=limit) cond = fluid.layers.less_than(x=label, y=limit)
...@@ -1357,6 +1364,7 @@ class ConditionalBlock(object): ...@@ -1357,6 +1364,7 @@ class ConditionalBlock(object):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
cond = layers.less_than(x=label, y=limit) cond = layers.less_than(x=label, y=limit)
true_image, false_image = layers.split_lod_tensor( true_image, false_image = layers.split_lod_tensor(
input=image, mask=cond) input=image, mask=cond)
......
...@@ -680,6 +680,7 @@ def box_coder(prior_box, ...@@ -680,6 +680,7 @@ def box_coder(prior_box,
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
prior_box = fluid.layers.data(name='prior_box', prior_box = fluid.layers.data(name='prior_box',
shape=[512, 4], shape=[512, 4],
dtype='float32', dtype='float32',
...@@ -811,6 +812,7 @@ def yolov3_loss(x, ...@@ -811,6 +812,7 @@ def yolov3_loss(x,
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
x = fluid.layers.data(name='x', shape=[255, 13, 13], dtype='float32') x = fluid.layers.data(name='x', shape=[255, 13, 13], dtype='float32')
gt_box = fluid.layers.data(name='gt_box', shape=[6, 4], dtype='float32') gt_box = fluid.layers.data(name='gt_box', shape=[6, 4], dtype='float32')
gt_label = fluid.layers.data(name='gt_label', shape=[6], dtype='int32') gt_label = fluid.layers.data(name='gt_label', shape=[6], dtype='int32')
...@@ -1001,6 +1003,7 @@ def detection_map(detect_res, ...@@ -1001,6 +1003,7 @@ def detection_map(detect_res,
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
from fluid.layers import detection from fluid.layers import detection
detect_res = fluid.layers.data( detect_res = fluid.layers.data(
name='detect_res', name='detect_res',
...@@ -1119,6 +1122,7 @@ def bipartite_match(dist_matrix, ...@@ -1119,6 +1122,7 @@ def bipartite_match(dist_matrix,
Examples: Examples:
>>> import paddle.fluid as fluid
>>> x = fluid.layers.data(name='x', shape=[4], dtype='float32') >>> x = fluid.layers.data(name='x', shape=[4], dtype='float32')
>>> y = fluid.layers.data(name='y', shape=[4], dtype='float32') >>> y = fluid.layers.data(name='y', shape=[4], dtype='float32')
>>> iou = fluid.layers.iou_similarity(x=x, y=y) >>> iou = fluid.layers.iou_similarity(x=x, y=y)
...@@ -1340,6 +1344,7 @@ def ssd_loss(location, ...@@ -1340,6 +1344,7 @@ def ssd_loss(location,
type of `max_negative`. type of `max_negative`.
Examples: Examples:
>>> import paddle.fluid as fluid
>>> pb = fluid.layers.data( >>> pb = fluid.layers.data(
>>> name='prior_box', >>> name='prior_box',
>>> shape=[10, 4], >>> shape=[10, 4],
...@@ -1542,6 +1547,7 @@ def prior_box(input, ...@@ -1542,6 +1547,7 @@ def prior_box(input,
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
input = fluid.layers.data(name="input", shape=[3,6,9]) input = fluid.layers.data(name="input", shape=[3,6,9])
images = fluid.layers.data(name="images", shape=[3,9,12]) images = fluid.layers.data(name="images", shape=[3,9,12])
box, var = fluid.layers.prior_box( box, var = fluid.layers.prior_box(
...@@ -1668,6 +1674,7 @@ def density_prior_box(input, ...@@ -1668,6 +1674,7 @@ def density_prior_box(input,
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
input = fluid.layers.data(name="input", shape=[3,6,9]) input = fluid.layers.data(name="input", shape=[3,6,9])
images = fluid.layers.data(name="images", shape=[3,9,12]) images = fluid.layers.data(name="images", shape=[3,9,12])
box, var = fluid.layers.density_prior_box( box, var = fluid.layers.density_prior_box(
...@@ -2019,6 +2026,7 @@ def anchor_generator(input, ...@@ -2019,6 +2026,7 @@ def anchor_generator(input,
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
conv1 = fluid.layers.data(name='conv1', shape=[48, 16, 16], dtype='float32') conv1 = fluid.layers.data(name='conv1', shape=[48, 16, 16], dtype='float32')
anchor, var = fluid.layers.anchor_generator( anchor, var = fluid.layers.anchor_generator(
input=conv1, input=conv1,
...@@ -2525,6 +2533,7 @@ def box_clip(input, im_info, name=None): ...@@ -2525,6 +2533,7 @@ def box_clip(input, im_info, name=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
boxes = fluid.layers.data( boxes = fluid.layers.data(
name='boxes', shape=[8, 4], dtype='float32', lod_level=1) name='boxes', shape=[8, 4], dtype='float32', lod_level=1)
im_info = fluid.layers.data(name='im_info', shape=[3]) im_info = fluid.layers.data(name='im_info', shape=[3])
...@@ -2729,6 +2738,7 @@ def multiclass_nms(bboxes, ...@@ -2729,6 +2738,7 @@ def multiclass_nms(bboxes,
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
boxes = fluid.layers.data(name='bboxes', shape=[81, 4], boxes = fluid.layers.data(name='bboxes', shape=[81, 4],
dtype='float32', lod_level=1) dtype='float32', lod_level=1)
scores = fluid.layers.data(name='scores', shape=[81], scores = fluid.layers.data(name='scores', shape=[81],
...@@ -2807,6 +2817,7 @@ def distribute_fpn_proposals(fpn_rois, ...@@ -2807,6 +2817,7 @@ def distribute_fpn_proposals(fpn_rois,
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
fpn_rois = fluid.layers.data( fpn_rois = fluid.layers.data(
name='data', shape=[4], dtype='float32', lod_level=1) name='data', shape=[4], dtype='float32', lod_level=1)
multi_rois, restore_ind = fluid.layers.distribute_fpn_proposals( multi_rois, restore_ind = fluid.layers.distribute_fpn_proposals(
...@@ -2865,6 +2876,7 @@ def box_decoder_and_assign(prior_box, ...@@ -2865,6 +2876,7 @@ def box_decoder_and_assign(prior_box,
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
pb = fluid.layers.data( pb = fluid.layers.data(
name='prior_box', shape=[4], dtype='float32') name='prior_box', shape=[4], dtype='float32')
pbv = fluid.layers.data( pbv = fluid.layers.data(
...@@ -2931,6 +2943,7 @@ def collect_fpn_proposals(multi_rois, ...@@ -2931,6 +2943,7 @@ def collect_fpn_proposals(multi_rois,
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
multi_rois = [] multi_rois = []
multi_scores = [] multi_scores = []
for i in range(4): for i in range(4):
......
...@@ -84,6 +84,7 @@ def data(name, ...@@ -84,6 +84,7 @@ def data(name,
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
data = fluid.layers.data(name='x', shape=[784], dtype='float32') data = fluid.layers.data(name='x', shape=[784], dtype='float32')
""" """
helper = LayerHelper('data', **locals()) helper = LayerHelper('data', **locals())
...@@ -147,6 +148,7 @@ class ListenAndServ(object): ...@@ -147,6 +148,7 @@ class ListenAndServ(object):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
with fluid.program_guard(main): with fluid.program_guard(main):
serv = layers.ListenAndServ( serv = layers.ListenAndServ(
"127.0.0.1:6170", ["X"], optimizer_mode=False) "127.0.0.1:6170", ["X"], optimizer_mode=False)
...@@ -449,6 +451,7 @@ def random_data_generator(low, high, shapes, lod_levels, for_parallel=True): ...@@ -449,6 +451,7 @@ def random_data_generator(low, high, shapes, lod_levels, for_parallel=True):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
reader = fluid.layers.random_data_generator( reader = fluid.layers.random_data_generator(
low=0.0, low=0.0,
high=1.0, high=1.0,
...@@ -1017,6 +1020,7 @@ def shuffle(reader, buffer_size): ...@@ -1017,6 +1020,7 @@ def shuffle(reader, buffer_size):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
raw_reader = fluid.layers.io.open_files(filenames=['./data1.recordio', raw_reader = fluid.layers.io.open_files(filenames=['./data1.recordio',
'./data2.recordio'], './data2.recordio'],
shapes=[(3,224,224), (1,)], shapes=[(3,224,224), (1,)],
...@@ -1048,6 +1052,7 @@ def batch(reader, batch_size): ...@@ -1048,6 +1052,7 @@ def batch(reader, batch_size):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
raw_reader = fluid.layers.io.open_files(filenames=['./data1.recordio', raw_reader = fluid.layers.io.open_files(filenames=['./data1.recordio',
'./data2.recordio'], './data2.recordio'],
shapes=[(3,224,224), (1,)], shapes=[(3,224,224), (1,)],
......
...@@ -253,6 +253,7 @@ def generate_activation_fn(op_type): ...@@ -253,6 +253,7 @@ def generate_activation_fn(op_type):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
data = fluid.layers.data(name="input", shape=[32, 784]) data = fluid.layers.data(name="input", shape=[32, 784])
result = fluid.layers.%s(data) result = fluid.layers.%s(data)
""" % op_type """ % op_type
......
...@@ -54,6 +54,7 @@ def noam_decay(d_model, warmup_steps): ...@@ -54,6 +54,7 @@ def noam_decay(d_model, warmup_steps):
.. code-block:: python .. code-block:: python
import padde.fluid as fluid
import numpy as np import numpy as np
# set hyper parameters # set hyper parameters
d_model = 2 d_model = 2
...@@ -415,7 +416,8 @@ def cosine_decay(learning_rate, step_each_epoch, epochs): ...@@ -415,7 +416,8 @@ def cosine_decay(learning_rate, step_each_epoch, epochs):
Examples: Examples:
.. code-block:: python .. code-block:: python
base_lr = 0.1 import paddle.fluid as fluid
base_lr = 0.1
lr = fluid.layers.cosine_decay( lr = fluid.layers.cosine_decay(
learning_rate = base_lr, step_each_epoch=10000, epochs=120) learning_rate = base_lr, step_each_epoch=10000, epochs=120)
""" """
...@@ -457,6 +459,7 @@ def linear_lr_warmup(learning_rate, warmup_steps, start_lr, end_lr): ...@@ -457,6 +459,7 @@ def linear_lr_warmup(learning_rate, warmup_steps, start_lr, end_lr):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
boundaries = [100, 200] boundaries = [100, 200]
lr_steps = [0.1, 0.01, 0.001] lr_steps = [0.1, 0.01, 0.001]
warmup_steps = 50 warmup_steps = 50
......
此差异已折叠。
...@@ -114,6 +114,7 @@ def hard_shrink(x, threshold=None): ...@@ -114,6 +114,7 @@ def hard_shrink(x, threshold=None):
hard_shrink.__doc__ = _hard_shrink_.__doc__ + """ hard_shrink.__doc__ = _hard_shrink_.__doc__ + """
Examples: Examples:
>>> import paddle.fluid as fluid
>>> data = fluid.layers.data(name="input", shape=[784]) >>> data = fluid.layers.data(name="input", shape=[784])
>>> result = fluid.layers.hard_shrink(x=data, threshold=0.3) >>> result = fluid.layers.hard_shrink(x=data, threshold=0.3)
""" """
...@@ -135,6 +136,7 @@ def cumsum(x, axis=None, exclusive=None, reverse=None): ...@@ -135,6 +136,7 @@ def cumsum(x, axis=None, exclusive=None, reverse=None):
cumsum.__doc__ = _cum_sum_.__doc__ + """ cumsum.__doc__ = _cum_sum_.__doc__ + """
Examples: Examples:
>>> import paddle.fluid as fluid
>>> data = fluid.layers.data(name="input", shape=[32, 784]) >>> data = fluid.layers.data(name="input", shape=[32, 784])
>>> result = fluid.layers.cumsum(data, axis=0) >>> result = fluid.layers.cumsum(data, axis=0)
""" """
...@@ -157,6 +159,7 @@ def thresholded_relu(x, threshold=None): ...@@ -157,6 +159,7 @@ def thresholded_relu(x, threshold=None):
thresholded_relu.__doc__ = _thresholded_relu_.__doc__ + """ thresholded_relu.__doc__ = _thresholded_relu_.__doc__ + """
Examples: Examples:
>>> import paddle.fluid as fluid
>>> data = fluid.layers.data(name="input", shape=[1]) >>> data = fluid.layers.data(name="input", shape=[1])
>>> result = fluid.layers.thresholded_relu(data, threshold=0.4) >>> result = fluid.layers.thresholded_relu(data, threshold=0.4)
""" """
...@@ -49,6 +49,7 @@ def create_tensor(dtype, name=None, persistable=False): ...@@ -49,6 +49,7 @@ def create_tensor(dtype, name=None, persistable=False):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
tensor = fluid.layers.create_tensor(dtype='float32') tensor = fluid.layers.create_tensor(dtype='float32')
""" """
helper = LayerHelper("create_tensor", **locals()) helper = LayerHelper("create_tensor", **locals())
...@@ -85,6 +86,7 @@ def create_parameter(shape, ...@@ -85,6 +86,7 @@ def create_parameter(shape,
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import paddle.fluid.layers as layers import paddle.fluid.layers as layers
W = layers.create_parameter(shape=[784, 200], dtype='float32') W = layers.create_parameter(shape=[784, 200], dtype='float32')
""" """
...@@ -123,6 +125,7 @@ def create_global_var(shape, ...@@ -123,6 +125,7 @@ def create_global_var(shape,
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import paddle.fluid.layers as layers import paddle.fluid.layers as layers
var = layers.create_global_var(shape=[2,3], value=1.0, dtype='float32', var = layers.create_global_var(shape=[2,3], value=1.0, dtype='float32',
persistable=True, force_cpu=True, name='new_var') persistable=True, force_cpu=True, name='new_var')
...@@ -157,6 +160,7 @@ def cast(x, dtype): ...@@ -157,6 +160,7 @@ def cast(x, dtype):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
data = fluid.layers.data(name='x', shape=[13], dtype='float32') data = fluid.layers.data(name='x', shape=[13], dtype='float32')
result = fluid.layers.cast(x=data, dtype='float64') result = fluid.layers.cast(x=data, dtype='float64')
""" """
...@@ -190,6 +194,7 @@ def concat(input, axis=0, name=None): ...@@ -190,6 +194,7 @@ def concat(input, axis=0, name=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
a = fluid.layers.data(name='a', shape=[2, 13], dtype='float32') a = fluid.layers.data(name='a', shape=[2, 13], dtype='float32')
b = fluid.layers.data(name='b', shape=[2, 3], dtype='float32') b = fluid.layers.data(name='b', shape=[2, 3], dtype='float32')
c = fluid.layers.data(name='c', shape=[2, 2], dtype='float32') c = fluid.layers.data(name='c', shape=[2, 2], dtype='float32')
...@@ -482,6 +487,7 @@ def argmin(x, axis=0): ...@@ -482,6 +487,7 @@ def argmin(x, axis=0):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
x = fluid.layers.data(name="x", shape=[3, 4], dtype="float32") x = fluid.layers.data(name="x", shape=[3, 4], dtype="float32")
out = fluid.layers.argmin(x, axis=0) out = fluid.layers.argmin(x, axis=0)
out = fluid.layers.argmin(x, axis=-1) out = fluid.layers.argmin(x, axis=-1)
...@@ -514,6 +520,7 @@ def argmax(x, axis=0): ...@@ -514,6 +520,7 @@ def argmax(x, axis=0):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
x = fluid.layers.data(name="x", shape=[3, 4], dtype="float32") x = fluid.layers.data(name="x", shape=[3, 4], dtype="float32")
out = fluid.layers.argmax(x, axis=0) out = fluid.layers.argmax(x, axis=0)
out = fluid.layers.argmax(x, axis=-1) out = fluid.layers.argmax(x, axis=-1)
...@@ -565,6 +572,7 @@ def argsort(input, axis=-1, name=None): ...@@ -565,6 +572,7 @@ def argsort(input, axis=-1, name=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
x = fluid.layers.data(name="x", shape=[3, 4], dtype="float32") x = fluid.layers.data(name="x", shape=[3, 4], dtype="float32")
out, indices = fluid.layers.argsort(input=x, axis=0) out, indices = fluid.layers.argsort(input=x, axis=0)
""" """
...@@ -712,6 +720,7 @@ def save_combine(x, file_path, overwrite=True): ...@@ -712,6 +720,7 @@ def save_combine(x, file_path, overwrite=True):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
v1 = fluid.layers.data(name="data", v1 = fluid.layers.data(name="data",
shape=(4, 6), shape=(4, 6),
dtype="float32") dtype="float32")
...@@ -808,6 +817,7 @@ def isfinite(x): ...@@ -808,6 +817,7 @@ def isfinite(x):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
var = fluid.layers.data(name="data", var = fluid.layers.data(name="data",
shape=(4, 6), shape=(4, 6),
dtype="float32") dtype="float32")
...@@ -843,6 +853,7 @@ def range(start, end, step, dtype): ...@@ -843,6 +853,7 @@ def range(start, end, step, dtype):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
data = fluid.layers.range(0, 10, 2, 'int32') data = fluid.layers.range(0, 10, 2, 'int32')
""" """
...@@ -884,6 +895,7 @@ def linspace(start, stop, num, dtype): ...@@ -884,6 +895,7 @@ def linspace(start, stop, num, dtype):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
data = fluid.layers.linspace(0, 10, 5, 'float32') # [0.0, 2.5, 5.0, 7.5, 10.0] data = fluid.layers.linspace(0, 10, 5, 'float32') # [0.0, 2.5, 5.0, 7.5, 10.0]
data = fluid.layers.linspace(0, 10, 1, 'float32') # [0.0] data = fluid.layers.linspace(0, 10, 1, 'float32') # [0.0]
...@@ -925,6 +937,7 @@ def zeros_like(x, out=None): ...@@ -925,6 +937,7 @@ def zeros_like(x, out=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
x = fluid.layers.data(name='x', dtype='float32', shape=[3], append_batch_size=False) x = fluid.layers.data(name='x', dtype='float32', shape=[3], append_batch_size=False)
data = fluid.layers.zeros_like(x) # [0.0, 0.0, 0.0] data = fluid.layers.zeros_like(x) # [0.0, 0.0, 0.0]
......
...@@ -154,6 +154,7 @@ class CompositeMetric(MetricBase): ...@@ -154,6 +154,7 @@ class CompositeMetric(MetricBase):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import numpy as np import numpy as np
preds = [[0.1], [0.7], [0.8], [0.9], [0.2], preds = [[0.1], [0.7], [0.8], [0.9], [0.2],
[0.2], [0.3], [0.5], [0.8], [0.6]] [0.2], [0.3], [0.5], [0.8], [0.6]]
...@@ -226,6 +227,7 @@ class Precision(MetricBase): ...@@ -226,6 +227,7 @@ class Precision(MetricBase):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import numpy as np import numpy as np
metric = fluid.metrics.Precision() metric = fluid.metrics.Precision()
...@@ -287,6 +289,7 @@ class Recall(MetricBase): ...@@ -287,6 +289,7 @@ class Recall(MetricBase):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import numpy as np import numpy as np
metric = fluid.metrics.Recall() metric = fluid.metrics.Recall()
...@@ -346,6 +349,7 @@ class Accuracy(MetricBase): ...@@ -346,6 +349,7 @@ class Accuracy(MetricBase):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
#suppose we have batch_size = 128 #suppose we have batch_size = 128
batch_size=128 batch_size=128
accuracy_manager = fluid.metrics.Accuracy() accuracy_manager = fluid.metrics.Accuracy()
...@@ -416,6 +420,7 @@ class ChunkEvaluator(MetricBase): ...@@ -416,6 +420,7 @@ class ChunkEvaluator(MetricBase):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
# init the chunck-level evaluation manager # init the chunck-level evaluation manager
metric = fluid.metrics.ChunkEvaluator() metric = fluid.metrics.ChunkEvaluator()
...@@ -505,6 +510,7 @@ class EditDistance(MetricBase): ...@@ -505,6 +510,7 @@ class EditDistance(MetricBase):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import numpy as np import numpy as np
# suppose that batch_size is 128 # suppose that batch_size is 128
...@@ -605,6 +611,7 @@ class Auc(MetricBase): ...@@ -605,6 +611,7 @@ class Auc(MetricBase):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import numpy as np import numpy as np
# init the auc metric # init the auc metric
auc_metric = fluid.metrics.Auc("ROC") auc_metric = fluid.metrics.Auc("ROC")
...@@ -729,6 +736,7 @@ class DetectionMAP(object): ...@@ -729,6 +736,7 @@ class DetectionMAP(object):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import paddle.fluid.layers as layers import paddle.fluid.layers as layers
batch_size = -1 # can be any size batch_size = -1 # can be any size
......
...@@ -190,6 +190,7 @@ def img_conv_group(input, ...@@ -190,6 +190,7 @@ def img_conv_group(input,
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32') img = fluid.layers.data(name='img', shape=[1, 28, 28], dtype='float32')
conv_pool = fluid.nets.img_conv_group(input=img, conv_pool = fluid.nets.img_conv_group(input=img,
conv_padding=1, conv_padding=1,
...@@ -328,6 +329,7 @@ def glu(input, dim=-1): ...@@ -328,6 +329,7 @@ def glu(input, dim=-1):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
data = fluid.layers.data( data = fluid.layers.data(
name="words", shape=[-1, 6, 3, 9], dtype="float32") name="words", shape=[-1, 6, 3, 9], dtype="float32")
# shape of output: [-1, 3, 3, 9] # shape of output: [-1, 3, 3, 9]
......
...@@ -510,6 +510,7 @@ class Optimizer(object): ...@@ -510,6 +510,7 @@ class Optimizer(object):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
loss = network() loss = network()
optimizer = fluid.optimizer.SGD(learning_rate=0.1) optimizer = fluid.optimizer.SGD(learning_rate=0.1)
params_grads = optimizer.backward(loss) params_grads = optimizer.backward(loss)
...@@ -827,6 +828,7 @@ class DGCMomentumOptimizer(MomentumOptimizer): ...@@ -827,6 +828,7 @@ class DGCMomentumOptimizer(MomentumOptimizer):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
optimizer = fluid.optimizer.DGCMomentumOptimizer( optimizer = fluid.optimizer.DGCMomentumOptimizer(
learning_rate=0.0001, learning_rate=0.0001,
momentum=0.9, momentum=0.9,
...@@ -1699,6 +1701,7 @@ class AdadeltaOptimizer(Optimizer): ...@@ -1699,6 +1701,7 @@ class AdadeltaOptimizer(Optimizer):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
optimizer = fluid.optimizer.Adadelta( optimizer = fluid.optimizer.Adadelta(
learning_rate=0.0003, epsilon=1.0e-6, rho=0.95) learning_rate=0.0003, epsilon=1.0e-6, rho=0.95)
_, params_grads = optimizer.minimize(cost) _, params_grads = optimizer.minimize(cost)
...@@ -2688,6 +2691,7 @@ class PipelineOptimizer(object): ...@@ -2688,6 +2691,7 @@ class PipelineOptimizer(object):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import paddle.fluid.layers as layers import paddle.fluid.layers as layers
x = fluid.layers.data(name='x', shape=[1], dtype='int64', lod_level=0) x = fluid.layers.data(name='x', shape=[1], dtype='int64', lod_level=0)
......
...@@ -113,6 +113,7 @@ def reset_profiler(): ...@@ -113,6 +113,7 @@ def reset_profiler():
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import paddle.fluid.profiler as profiler import paddle.fluid.profiler as profiler
with profiler.profiler('CPU', 'total', '/tmp/profile'): with profiler.profiler('CPU', 'total', '/tmp/profile'):
for iter in range(10): for iter in range(10):
...@@ -141,6 +142,7 @@ def start_profiler(state): ...@@ -141,6 +142,7 @@ def start_profiler(state):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import paddle.fluid.profiler as profiler import paddle.fluid.profiler as profiler
profiler.start_profiler('GPU') profiler.start_profiler('GPU')
...@@ -190,6 +192,7 @@ def stop_profiler(sorted_key=None, profile_path='/tmp/profile'): ...@@ -190,6 +192,7 @@ def stop_profiler(sorted_key=None, profile_path='/tmp/profile'):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import paddle.fluid.profiler as profiler import paddle.fluid.profiler as profiler
profiler.start_profiler('GPU') profiler.start_profiler('GPU')
...@@ -257,6 +260,7 @@ def profiler(state, sorted_key=None, profile_path='/tmp/profile'): ...@@ -257,6 +260,7 @@ def profiler(state, sorted_key=None, profile_path='/tmp/profile'):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import paddle.fluid.profiler as profiler import paddle.fluid.profiler as profiler
import numpy as np import numpy as np
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册