Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
d70e45d9
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
d70e45d9
编写于
9月 26, 2021
作者:
W
wangzhuang01
提交者:
GitHub
9月 26, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改了 示例代码错误 (#36041)
上级
97922557
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
70 addition
and
17 deletion
+70
-17
python/paddle/fluid/data.py
python/paddle/fluid/data.py
+2
-0
python/paddle/fluid/dataset.py
python/paddle/fluid/dataset.py
+8
-0
python/paddle/fluid/input.py
python/paddle/fluid/input.py
+3
-0
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+53
-16
python/paddle/fluid/layers/rnn.py
python/paddle/fluid/layers/rnn.py
+4
-1
未找到文件。
python/paddle/fluid/data.py
浏览文件 @
d70e45d9
...
...
@@ -73,8 +73,10 @@ def data(name, shape, dtype='float32', lod_level=0):
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
paddle.enable_static()
# Creates a variable with fixed size [3, 2, 1]
# User can only feed data of the same shape to x
...
...
python/paddle/fluid/dataset.py
浏览文件 @
d70e45d9
...
...
@@ -727,6 +727,7 @@ class InMemoryDataset(DatasetBase):
Examples:
.. code-block:: python
# required: skiptest
import paddle.fluid as fluid
dataset = fluid.DatasetFactory().create_dataset("InMemoryDataset")
filelist = ["a.txt", "b.txt"]
...
...
@@ -753,6 +754,7 @@ class InMemoryDataset(DatasetBase):
Examples:
.. code-block:: python
# required: skiptest
import paddle.fluid as fluid
dataset = fluid.DatasetFactory().create_dataset("InMemoryDataset")
filelist = ["a.txt", "b.txt"]
...
...
@@ -777,6 +779,7 @@ class InMemoryDataset(DatasetBase):
Examples:
.. code-block:: python
# required: skiptest
import paddle.fluid as fluid
dataset = fluid.DatasetFactory().create_dataset("InMemoryDataset")
filelist = ["a.txt", "b.txt"]
...
...
@@ -797,6 +800,7 @@ class InMemoryDataset(DatasetBase):
Examples:
.. code-block:: python
# required: skiptest
import paddle.fluid as fluid
dataset = fluid.DatasetFactory().create_dataset("InMemoryDataset")
filelist = ["a.txt", "b.txt"]
...
...
@@ -819,6 +823,7 @@ class InMemoryDataset(DatasetBase):
Examples:
.. code-block:: python
# required: skiptest
import paddle.fluid as fluid
from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet
dataset = fluid.DatasetFactory().create_dataset("InMemoryDataset")
...
...
@@ -866,6 +871,7 @@ class InMemoryDataset(DatasetBase):
Examples:
.. code-block:: python
# required: skiptest
import paddle.fluid as fluid
from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet
dataset = fluid.DatasetFactory().create_dataset("InMemoryDataset")
...
...
@@ -925,6 +931,7 @@ class InMemoryDataset(DatasetBase):
Examples:
.. code-block:: python
# required: skiptest
import paddle.fluid as fluid
from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet
dataset = fluid.DatasetFactory().create_dataset("InMemoryDataset")
...
...
@@ -965,6 +972,7 @@ class InMemoryDataset(DatasetBase):
Examples:
.. code-block:: python
# required: skiptest
import paddle.fluid as fluid
from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet
dataset = fluid.DatasetFactory().create_dataset("InMemoryDataset")
...
...
python/paddle/fluid/input.py
浏览文件 @
d70e45d9
...
...
@@ -98,7 +98,10 @@ def one_hot(input, depth, allow_out_of_range=False):
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
# Correspond to the first example above, where label.shape is 4 and one_hot_label.shape is [4, 4].
label = fluid.data(name="label", shape=[4], dtype="int64")
one_hot_label = fluid.one_hot(input=label, depth=4)
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
d70e45d9
...
...
@@ -4521,7 +4521,10 @@ def reduce_mean(input, dim=None, keep_dim=False, name=None):
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
# x is a Tensor variable with following elements:
# [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]]
...
...
@@ -5160,7 +5163,10 @@ def matmul(x, y, transpose_x=False, transpose_y=False, alpha=1.0, name=None):
# x: [M], y: [N]
# fluid.layers.matmul(x, y, True, True) # out: [M, N]
import paddle
import paddle.fluid as fluid
paddle.enable_static()
x = fluid.layers.data(name='x', shape=[2, 3], dtype='float32')
y = fluid.layers.data(name='y', shape=[3, 2], dtype='float32')
out = fluid.layers.matmul(x, y, True, True)
...
...
@@ -5999,7 +6005,10 @@ def one_hot(input, depth, allow_out_of_range=False):
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
# Correspond to the first example above, where label.shape is [4, 1] and one_hot_label.shape is [4, 4].
label = fluid.data(name="label", shape=[4, 1], dtype="int64")
one_hot_label = fluid.layers.one_hot(input=label, depth=4)
...
...
@@ -8363,7 +8372,10 @@ def gather(input, index, overwrite=True):
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
x = fluid.data(name='x', shape=[-1, 5], dtype='float32')
index = fluid.data(name='index', shape=[-1, 1], dtype='int32')
output = fluid.layers.gather(x, index)
...
...
@@ -8453,7 +8465,10 @@ def gather_nd(input, index, name=None):
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
x = fluid.data(name='x', shape=[3, 4, 5], dtype='float32')
index = fluid.data(name='index', shape=[2, 2], dtype='int32')
output = fluid.layers.gather_nd(x, index)
...
...
@@ -8488,6 +8503,7 @@ def scatter(input, index, updates, name=None, overwrite=True):
Output is obtained by updating the input on selected indices based on updates.
.. code-block:: python
import numpy as np
#input:
...
...
@@ -8529,8 +8545,10 @@ def scatter(input, index, updates, name=None, overwrite=True):
.. code-block:: python
import paddle
import numpy as np
import paddle.fluid as fluid
paddle.enable_static()
input = fluid.layers.data(name='data', shape=[3, 2], dtype='float32', append_batch_size=False)
index = fluid.layers.data(name='index', shape=[4], dtype='int64', append_batch_size=False)
...
...
@@ -8871,8 +8889,10 @@ def selu(x, scale=None, alpha=None, name=None):
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
paddle.enable_static()
inputs = fluid.layers.data(name="x", shape=[2, 2], dtype="float32")
output = fluid.layers.selu(inputs)
...
...
@@ -10480,22 +10500,24 @@ def expand_as(x, target_tensor, name=None):
Examples:
.. code-block:: python
import paddle.fluid as fluid
import numpy as np
import paddle
import paddle.fluid as fluid
import numpy as np
paddle.enable_static()
data = fluid.layers.data(name="data", shape=[-1,10], dtype='float64')
target_tensor = fluid.layers.data(
name="target_tensor", shape=[-1,20], dtype='float64')
result = fluid.layers.expand_as(x=data, target_tensor=target_tensor)
use_cuda = False
place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
x = np.random.rand(3,10)
y = np.random.rand(3,20)
output= exe.run(feed={"data":x,"target_tensor":y},fetch_list=[result.name])
print(output[0].shape)
#(3,20)
data = fluid.layers.data(name="data", shape=[-1,10], dtype='float64')
target_tensor = fluid.layers.data(
name="target_tensor", shape=[-1,20], dtype='float64')
result = fluid.layers.expand_as(x=data, target_tensor=target_tensor)
use_cuda = False
place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
x = np.random.rand(3,10)
y = np.random.rand(3,20)
output= exe.run(feed={"data":x,"target_tensor":y},fetch_list=[result.name])
print(output[0].shape)
#(3,20)
"""
if in_dygraph_mode():
...
...
@@ -10576,7 +10598,9 @@ def uniform_random_batch_size_like(input,
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
# example 1:
input = fluid.data(name="input", shape=[1, 3], dtype='float32')
...
...
@@ -10649,7 +10673,9 @@ def gaussian_random(shape,
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
# example 1:
# attr shape is a list which doesn't contain Tensor.
...
...
@@ -10677,7 +10703,8 @@ def gaussian_random(shape,
.. code-block:: python
# declarative mode
# declarative mode
# required: skiptest
import numpy as np
from paddle import fluid
...
...
@@ -10816,7 +10843,10 @@ def gaussian_random_batch_size_like(input,
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
input = fluid.data(name="input", shape=[13, 11], dtype='float32')
out = fluid.layers.gaussian_random_batch_size_like(
...
...
@@ -11422,7 +11452,9 @@ def size(input):
Examples:
.. code-block:: python
import paddle
import paddle.fluid.layers as layers
paddle.enable_static()
input = layers.data(
name="input", shape=[3, 100], dtype="float32", append_batch_size=False)
...
...
@@ -12525,7 +12557,10 @@ def mean(x, name=None):
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
input = fluid.layers.data(
name='data', shape=[2, 3], dtype='float32')
mean = fluid.layers.mean(input)
...
...
@@ -15195,7 +15230,9 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0,
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
# example 1:
# attr shape is a list which doesn't contain Tensor.
...
...
python/paddle/fluid/layers/rnn.py
浏览文件 @
d70e45d9
...
...
@@ -2528,18 +2528,21 @@ def lstm(input,
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import paddle.fluid.layers as layers
paddle.enable_static()
emb_dim = 256
vocab_size = 10000
data = fluid.data(name='x', shape=[None, 100], dtype='int64')
emb = fluid.embedding(input=data, size=[vocab_size, emb_dim], is_sparse=True)
batch_size =
2
0
batch_size =
10
0
dropout_prob = 0.2
input_size = 100
hidden_size = 150
num_layers = 1
max_len = 12
init_h = layers.fill_constant( [num_layers, batch_size, hidden_size], 'float32', 0.0 )
init_c = layers.fill_constant( [num_layers, batch_size, hidden_size], 'float32', 0.0 )
rnn_out, last_h, last_c = layers.lstm( emb, init_h, init_c, \
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录