Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
cb7bbf42
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
694
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cb7bbf42
编写于
4月 10, 2018
作者:
Y
Yancey1989
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
revert uniform_random_op
上级
291aa231
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
7 addition
and
65 deletion
+7
-65
paddle/fluid/operators/uniform_random_op.cc
paddle/fluid/operators/uniform_random_op.cc
+1
-12
paddle/fluid/operators/uniform_random_op.cu
paddle/fluid/operators/uniform_random_op.cu
+1
-12
python/paddle/fluid/tests/unittests/test_uniform_random_op.py
...on/paddle/fluid/tests/unittests/test_uniform_random_op.py
+5
-41
未找到文件。
paddle/fluid/operators/uniform_random_op.cc
浏览文件 @
cb7bbf42
...
@@ -24,19 +24,8 @@ template <typename T>
...
@@ -24,19 +24,8 @@ template <typename T>
class
CPUUniformRandomKernel
:
public
framework
::
OpKernel
<
T
>
{
class
CPUUniformRandomKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
framework
::
Tensor
*
tensor
(
nullptr
);
auto
*
tensor
=
ctx
.
Output
<
framework
::
Tensor
>
(
"Out"
);
auto
out_var
=
ctx
.
OutputVar
(
"Out"
);
if
(
out_var
->
IsType
<
framework
::
LoDTensor
>
())
{
tensor
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
);
}
else
if
(
out_var
->
IsType
<
framework
::
SelectedRows
>
())
{
auto
shape
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"shape"
);
tensor
=
ctx
.
Output
<
framework
::
SelectedRows
>
(
"Out"
)
->
mutable_value
();
tensor
->
Resize
(
framework
::
make_ddim
(
shape
));
}
else
{
PADDLE_THROW
(
"Only support LoDTensor and SelectedRows."
);
}
T
*
data
=
tensor
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
T
*
data
=
tensor
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
data
[
0
]
=
static_cast
<
T
>
(
1000
);
unsigned
int
seed
=
static_cast
<
unsigned
int
>
(
ctx
.
Attr
<
int
>
(
"seed"
));
unsigned
int
seed
=
static_cast
<
unsigned
int
>
(
ctx
.
Attr
<
int
>
(
"seed"
));
std
::
minstd_rand
engine
;
std
::
minstd_rand
engine
;
if
(
seed
==
0
)
{
if
(
seed
==
0
)
{
...
...
paddle/fluid/operators/uniform_random_op.cu
浏览文件 @
cb7bbf42
...
@@ -43,18 +43,7 @@ template <typename T>
...
@@ -43,18 +43,7 @@ template <typename T>
class
GPUUniformRandomKernel
:
public
framework
::
OpKernel
<
T
>
{
class
GPUUniformRandomKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
framework
::
Tensor
*
tensor
(
nullptr
);
auto
*
tensor
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
auto
out_var
=
ctx
.
OutputVar
(
"Out"
);
if
(
out_var
->
IsType
<
framework
::
LoDTensor
>
())
{
tensor
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
);
}
else
if
(
out_var
->
IsType
<
framework
::
SelectedRows
>
())
{
auto
shape
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"shape"
);
tensor
=
ctx
.
Output
<
framework
::
SelectedRows
>
(
"Out"
)
->
mutable_value
();
tensor
->
Resize
(
framework
::
make_ddim
(
shape
));
}
else
{
PADDLE_THROW
(
"Only support LoDTensor and SelectedRows."
);
}
T
*
data
=
tensor
->
mutable_data
<
T
>
(
context
.
GetPlace
());
T
*
data
=
tensor
->
mutable_data
<
T
>
(
context
.
GetPlace
());
unsigned
int
seed
=
static_cast
<
unsigned
int
>
(
context
.
Attr
<
int
>
(
"seed"
));
unsigned
int
seed
=
static_cast
<
unsigned
int
>
(
context
.
Attr
<
int
>
(
"seed"
));
if
(
seed
==
0
)
{
if
(
seed
==
0
)
{
...
...
python/paddle/fluid/tests/unittests/test_uniform_random_op.py
浏览文件 @
cb7bbf42
...
@@ -15,16 +15,6 @@
...
@@ -15,16 +15,6 @@
import
unittest
import
unittest
import
numpy
as
np
import
numpy
as
np
from
op_test
import
OpTest
from
op_test
import
OpTest
import
paddle.fluid.core
as
core
from
paddle.fluid.op
import
Operator
def
output_hist
(
out
):
hist
,
_
=
np
.
histogram
(
out
,
range
=
(
-
5
,
10
))
hist
=
hist
.
astype
(
"float32"
)
hist
/=
float
(
out
.
size
)
prob
=
0.1
*
np
.
ones
((
10
))
return
hist
,
prob
class
TestUniformRandomOp
(
OpTest
):
class
TestUniformRandomOp
(
OpTest
):
...
@@ -43,37 +33,11 @@ class TestUniformRandomOp(OpTest):
...
@@ -43,37 +33,11 @@ class TestUniformRandomOp(OpTest):
self
.
check_output_customized
(
self
.
verify_output
)
self
.
check_output_customized
(
self
.
verify_output
)
def
verify_output
(
self
,
outs
):
def
verify_output
(
self
,
outs
):
hist
,
prob
=
output_hist
(
outs
[
0
])
tensor
=
outs
[
0
]
self
.
assertTrue
(
hist
,
_
=
np
.
histogram
(
outs
[
0
],
range
=
(
-
5
,
10
))
np
.
allclose
(
hist
=
hist
.
astype
(
"float32"
)
hist
,
prob
,
rtol
=
0
,
atol
=
0.01
),
"hist: "
+
str
(
hist
))
hist
/=
float
(
outs
[
0
].
size
)
prob
=
0.1
*
np
.
ones
((
10
))
class
TestUniformRandomOpSelectedRows
(
unittest
.
TestCase
):
def
get_places
(
self
):
places
=
[
core
.
CPUPlace
()]
if
core
.
is_compiled_with_cuda
():
places
.
append
(
core
.
CUDAPlace
(
0
))
return
places
def
test_check_output
(
self
):
for
place
in
self
.
get_places
():
self
.
check_with_place
(
place
)
def
check_with_place
(
self
,
place
):
scope
=
core
.
Scope
()
out
=
scope
.
var
(
"X"
).
get_selected_rows
()
op
=
Operator
(
"uniform_random"
,
Out
=
"X"
,
shape
=
[
1000
,
784
],
min
=-
5.0
,
max
=
10.0
,
seed
=
10
)
op
.
run
(
scope
,
place
)
out_tensor
=
out
.
get_tensor
()
hist
,
prob
=
output_hist
(
np
.
array
(
out_tensor
))
self
.
assertTrue
(
self
.
assertTrue
(
np
.
allclose
(
np
.
allclose
(
hist
,
prob
,
rtol
=
0
,
atol
=
0.01
),
"hist: "
+
str
(
hist
))
hist
,
prob
,
rtol
=
0
,
atol
=
0.01
),
"hist: "
+
str
(
hist
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录