Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
d0f62431
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d0f62431
编写于
9月 07, 2018
作者:
Y
yangfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
repair bug of dropout op
上级
412ee03a
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
142 addition
and
3 deletion
+142
-3
src/operators/kernel/arm/dropout_kernel.cpp
src/operators/kernel/arm/dropout_kernel.cpp
+7
-3
src/operators/op_param.h
src/operators/op_param.h
+5
-0
test/CMakeLists.txt
test/CMakeLists.txt
+10
-0
test/net/test_alexnet.cpp
test/net/test_alexnet.cpp
+59
-0
test/net/test_inceptionv4.cpp
test/net/test_inceptionv4.cpp
+59
-0
test/test_helper.h
test/test_helper.h
+2
-0
未找到文件。
src/operators/kernel/arm/dropout_kernel.cpp
浏览文件 @
d0f62431
...
@@ -27,7 +27,11 @@ bool DropoutKernel<CPU, float>::Init(DropoutParam<CPU> *para) {
...
@@ -27,7 +27,11 @@ bool DropoutKernel<CPU, float>::Init(DropoutParam<CPU> *para) {
template
<
typename
T
>
template
<
typename
T
>
struct
DropoutFunctor
{
struct
DropoutFunctor
{
inline
T
operator
()(
T
in
)
const
{
return
in
;
}
DropoutFunctor
(
T
drop_pro
)
:
dropout_pro_
(
drop_pro
)
{}
inline
T
operator
()(
T
in
)
const
{
return
(
1
-
dropout_pro_
)
*
in
;
}
private:
T
dropout_pro_
;
};
};
template
<
>
template
<
>
...
@@ -36,8 +40,8 @@ void DropoutKernel<CPU, float>::Compute(const DropoutParam<CPU> ¶m) const {
...
@@ -36,8 +40,8 @@ void DropoutKernel<CPU, float>::Compute(const DropoutParam<CPU> ¶m) const {
auto
*
input_x_ptr
=
input_x
->
data
<
float
>
();
auto
*
input_x_ptr
=
input_x
->
data
<
float
>
();
auto
*
out
=
param
.
Out
();
auto
*
out
=
param
.
Out
();
auto
*
out_ptr
=
out
->
mutable_data
<
float
>
();
auto
*
out_ptr
=
out
->
mutable_data
<
float
>
();
const
float
dropoutProb
=
param
.
DropoutProb
();
DropoutFunctor
<
float
>
func_
;
DropoutFunctor
<
float
>
func_
(
dropoutProb
)
;
math
::
Transform
trans
;
math
::
Transform
trans
;
trans
(
input_x_ptr
,
input_x_ptr
+
input_x
->
numel
(),
out_ptr
,
func_
);
trans
(
input_x_ptr
,
input_x_ptr
+
input_x
->
numel
(),
out_ptr
,
func_
);
}
}
...
...
src/operators/op_param.h
浏览文件 @
d0f62431
...
@@ -2136,15 +2136,20 @@ class DropoutParam : public OpParam {
...
@@ -2136,15 +2136,20 @@ class DropoutParam : public OpParam {
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
input_x_
=
InputXFrom
<
GType
>
(
inputs
,
scope
);
input_x_
=
InputXFrom
<
GType
>
(
inputs
,
scope
);
out_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
out_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
dropout_prob_
=
GetAttr
<
float
>
(
"dropout_prob"
,
attrs
);
}
}
const
RType
*
InputX
()
const
{
return
input_x_
;
}
const
RType
*
InputX
()
const
{
return
input_x_
;
}
RType
*
Out
()
const
{
return
out_
;
}
RType
*
Out
()
const
{
return
out_
;
}
float
DropoutProb
()
const
{
return
dropout_prob_
;
}
private:
private:
RType
*
input_x_
;
RType
*
input_x_
;
RType
*
out_
;
RType
*
out_
;
float
dropout_prob_
;
};
};
#endif
#endif
...
...
test/CMakeLists.txt
浏览文件 @
d0f62431
...
@@ -207,10 +207,20 @@ else ()
...
@@ -207,10 +207,20 @@ else ()
ADD_EXECUTABLE
(
test-gru-op operators/test_gru_op.cpp test_helper.h test_include.h
)
ADD_EXECUTABLE
(
test-gru-op operators/test_gru_op.cpp test_helper.h test_include.h
)
target_link_libraries
(
test-gru-op paddle-mobile
)
target_link_libraries
(
test-gru-op paddle-mobile
)
# gen test
ADD_EXECUTABLE
(
test-inceptionv4 net/test_inceptionv4.cpp test_helper.h test_include.h executor_for_test.h
)
target_link_libraries
(
test-inceptionv4 paddle-mobile
)
# gen test
ADD_EXECUTABLE
(
test-alexnet net/test_alexnet.cpp test_helper.h test_include.h executor_for_test.h
)
target_link_libraries
(
test-alexnet paddle-mobile
)
#add_library(test-lib-size SHARED common/test_lib_size.h common/test_lib_size.cpp)
#add_library(test-lib-size SHARED common/test_lib_size.h common/test_lib_size.cpp)
endif
()
endif
()
# if(FPGA)
# if(FPGA)
...
...
test/net/test_alexnet.cpp
0 → 100644
浏览文件 @
d0f62431
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <iostream>
#include "../test_helper.h"
#include "../test_include.h"
int
main
()
{
paddle_mobile
::
PaddleMobile
<
paddle_mobile
::
CPU
>
paddle_mobile
;
paddle_mobile
.
SetThreadNum
(
4
);
auto
time1
=
time
();
// auto isok = paddle_mobile.Load(std::string(g_mobilenet_detect) + "/model",
// std::string(g_mobilenet_detect) + "/params", true);
auto
isok
=
paddle_mobile
.
Load
(
g_alexnet
,
true
);
if
(
isok
)
{
auto
time2
=
time
();
std
::
cout
<<
"load cost :"
<<
time_diff
(
time1
,
time1
)
<<
"ms"
<<
std
::
endl
;
std
::
vector
<
float
>
input
;
std
::
vector
<
int64_t
>
dims
{
1
,
3
,
224
,
224
};
GetInput
<
float
>
(
g_test_image_1x3x224x224_banana
,
&
input
,
dims
);
auto
vec_result
=
paddle_mobile
.
Predict
(
input
,
dims
);
std
::
vector
<
float
>::
iterator
biggest
=
std
::
max_element
(
std
::
begin
(
vec_result
),
std
::
end
(
vec_result
));
std
::
cout
<<
" Max element is "
<<
*
biggest
<<
" at position "
<<
std
::
distance
(
std
::
begin
(
vec_result
),
biggest
)
<<
std
::
endl
;
// 预热十次
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
auto
vec_result
=
paddle_mobile
.
Predict
(
input
,
dims
);
}
auto
time3
=
time
();
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
auto
vec_result
=
paddle_mobile
.
Predict
(
input
,
dims
);
}
DLOG
<<
vec_result
;
auto
time4
=
time
();
std
::
cout
<<
"predict cost :"
<<
time_diff
(
time3
,
time4
)
/
10
<<
"ms"
<<
std
::
endl
;
}
std
::
cout
<<
"如果结果Nan请查看: test/images/g_test_image_1x3x224x224_banana "
"是否存在?"
<<
std
::
endl
;
return
0
;
}
test/net/test_inceptionv4.cpp
0 → 100644
浏览文件 @
d0f62431
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <iostream>
#include "../test_helper.h"
#include "../test_include.h"
int
main
()
{
paddle_mobile
::
PaddleMobile
<
paddle_mobile
::
CPU
>
paddle_mobile
;
paddle_mobile
.
SetThreadNum
(
4
);
auto
time1
=
time
();
// auto isok = paddle_mobile.Load(std::string(g_mobilenet_detect) + "/model",
// std::string(g_mobilenet_detect) + "/params", true);
auto
isok
=
paddle_mobile
.
Load
(
g_inceptionv4
,
true
);
if
(
isok
)
{
auto
time2
=
time
();
std
::
cout
<<
"load cost :"
<<
time_diff
(
time1
,
time1
)
<<
"ms"
<<
std
::
endl
;
std
::
vector
<
float
>
input
;
std
::
vector
<
int64_t
>
dims
{
1
,
3
,
224
,
224
};
GetInput
<
float
>
(
g_test_image_1x3x224x224_banana
,
&
input
,
dims
);
auto
vec_result
=
paddle_mobile
.
Predict
(
input
,
dims
);
std
::
vector
<
float
>::
iterator
biggest
=
std
::
max_element
(
std
::
begin
(
vec_result
),
std
::
end
(
vec_result
));
std
::
cout
<<
" Max element is "
<<
*
biggest
<<
" at position "
<<
std
::
distance
(
std
::
begin
(
vec_result
),
biggest
)
<<
std
::
endl
;
// 预热十次
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
auto
vec_result
=
paddle_mobile
.
Predict
(
input
,
dims
);
}
auto
time3
=
time
();
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
auto
vec_result
=
paddle_mobile
.
Predict
(
input
,
dims
);
}
// DLOG << vec_result;
auto
time4
=
time
();
std
::
cout
<<
"predict cost :"
<<
time_diff
(
time3
,
time4
)
/
10
<<
"ms"
<<
std
::
endl
;
}
std
::
cout
<<
"如果结果Nan请查看: test/images/g_test_image_1x3x224x224_banana "
"是否存在?"
<<
std
::
endl
;
return
0
;
}
test/test_helper.h
浏览文件 @
d0f62431
...
@@ -33,6 +33,8 @@ static const char *g_mobilenet_detect = "../models/mobilenet-detect";
...
@@ -33,6 +33,8 @@ static const char *g_mobilenet_detect = "../models/mobilenet-detect";
static
const
char
*
g_squeezenet
=
"../models/squeezenet"
;
static
const
char
*
g_squeezenet
=
"../models/squeezenet"
;
static
const
char
*
g_googlenet
=
"../models/googlenet"
;
static
const
char
*
g_googlenet
=
"../models/googlenet"
;
static
const
char
*
g_mobilenet
=
"../models/mobilenet"
;
static
const
char
*
g_mobilenet
=
"../models/mobilenet"
;
static
const
char
*
g_alexnet
=
"../models/alexnet"
;
static
const
char
*
g_inceptionv4
=
"../models/inceptionv4"
;
static
const
char
*
g_nlp
=
"../models/nlp"
;
static
const
char
*
g_nlp
=
"../models/nlp"
;
static
const
char
*
g_resnet_50
=
"../models/resnet_50"
;
static
const
char
*
g_resnet_50
=
"../models/resnet_50"
;
static
const
char
*
g_resnet
=
"../models/resnet"
;
static
const
char
*
g_resnet
=
"../models/resnet"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录