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