Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
04f4775b
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
04f4775b
编写于
9月 06, 2019
作者:
Y
Yanzhan Yang
提交者:
GitHub
9月 06, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix ios CPU preprocess test=develop (#1972)
* fix ios CPU preprocess test=develop * fix style test=develop
上级
c49958a2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
27 deletion
+33
-27
.pre-commit-config.yaml
.pre-commit-config.yaml
+1
-1
mobile/src/framework/executor.cpp
mobile/src/framework/executor.cpp
+5
-5
mobile/src/io/ios_io/PaddleMobileCPU.h
mobile/src/io/ios_io/PaddleMobileCPU.h
+12
-0
mobile/src/io/ios_io/PaddleMobileCPU.mm
mobile/src/io/ios_io/PaddleMobileCPU.mm
+15
-21
未找到文件。
.pre-commit-config.yaml
浏览文件 @
04f4775b
...
...
@@ -36,7 +36,7 @@ repos:
entry
:
bash ./tools/codestyle/cpplint_pre_commit.hook
language
:
system
files
:
\.(c|cc|cxx|cpp|cu|h|hpp|hxx)$
exclude
:
^(mobile/
|metal/|
web/)
exclude
:
^(mobile/
) | ^(metal/) | ^(
web/)
#- repo: local
#hooks:
#- id: pylint-doc-string
...
...
mobile/src/framework/executor.cpp
浏览文件 @
04f4775b
...
...
@@ -102,9 +102,9 @@ Executor<Device, T>::Executor(const Program<Device> &program,
}
int
count
=
0
;
#ifdef PADDLE_MOBILE_PROFILE
std
::
vector
<
ProfInfo
>
profile
(
ops_of_block0_
.
size
());
struct
timespec
ts
;
int
op_index
=
0
;
std
::
vector
<
ProfInfo
>
profile
(
ops_of_block0_
.
size
());
struct
timespec
ts
;
int
op_index
=
0
;
#endif
for
(
auto
&
op_handler
:
ops_of_block0_
)
{
#ifdef PADDLE_MOBILE_PROFILE
...
...
@@ -115,8 +115,8 @@ Executor<Device, T>::Executor(const Program<Device> &program,
op_handler
->
Init
();
#ifdef PADDLE_MOBILE_PROFILE
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
profile
[
op_index
].
runEnd
=
(
uint64_t
)
ts
.
tv_sec
*
1e9
+
ts
.
tv_nsec
;
++
op_index
;
profile
[
op_index
].
runEnd
=
(
uint64_t
)
ts
.
tv_sec
*
1e9
+
ts
.
tv_nsec
;
++
op_index
;
#endif
}
#ifdef PADDLE_MOBILE_PROFILE
...
...
mobile/src/io/ios_io/PaddleMobileCPU.h
浏览文件 @
04f4775b
...
...
@@ -139,6 +139,18 @@
*/
-
(
PaddleMobileCPUResult
*
)
predict
:(
CGImageRef
)
image
dim
:(
NSArray
<
NSNumber
*>
*
)
dim
means
:(
NSArray
<
NSNumber
*>
*
)
means
scale
:(
float
)
scale
;
/**
@b 进行预测, means stds和 scale 为训练模型时的预处理参数, 如训练时没有做这些预处理则直接使用 predict, 每一个像素经过这样的预处理 (x + means) * scale, 其中 x 为像素值
@param image 输入图像
@param dim 输入维度
@param means 预处理中 means
@param stds 预处理中 stds
@param scale 预处理中 scale
@return 预测结果
*/
-
(
PaddleMobileCPUResult
*
)
predict
:(
CGImageRef
)
image
dim
:(
NSArray
<
NSNumber
*>
*
)
dim
means
:(
NSArray
<
NSNumber
*>
*
)
means
stds
:(
NSArray
<
NSNumber
*>
*
)
stds
scale
:(
float
)
scale
;
/**
@b 进行预测, 预处理 means 值为 0, scale 值为 1
...
...
mobile/src/io/ios_io/PaddleMobileCPU.mm
浏览文件 @
04f4775b
...
...
@@ -181,25 +181,22 @@ static std::mutex shared_mutex;
for
(
int
x
=
0
;
x
<
wanted_input_width
;
++
x
)
{
int
in_row
=
(
y
*
imageHeight
)
/
wanted_input_height
;
int
in_col
=
(
x
*
imageWidth
)
/
wanted_input_width
;
const
UInt8
*
in_pixel
=
input
+
(
in_row
*
imageWidth
*
imageChannel
s
)
+
(
in_col
*
imageChannels
);
const
UInt8
*
in_pixel
=
input
+
(
in_row
*
sourceRowByte
s
)
+
(
in_col
*
imageChannels
);
float
*
out_pos
=
out_row
+
x
;
if
(
c
==
0
)
{
*
out_pos
=
(
in_pixel
[
c
]
-
means
[
c
].
floatValue
)
*
scale
;
}
else
if
(
c
==
1
){
*
out_pos
=
(
in_pixel
[
c
]
-
means
[
c
].
floatValue
)
*
scale
;
}
else
if
(
c
==
2
){
*
out_pos
=
(
in_pixel
[
c
]
-
means
[
c
].
floatValue
)
*
scale
;
}
*
out_pos
=
(
in_pixel
[
2
-
c
]
-
means
[
c
].
floatValue
)
*
scale
;
}
}
}
}
-
(
void
)
preprocess
:(
const
UInt8
*
)
input
output
:(
float
*
)
output
imageWidth
:(
int
)
imageWidth
imageHeight
:(
int
)
imageHeight
imageChannels
:(
int
)
imageChannels
means
:(
NSArray
<
NSNumber
*>
*
)
means
scale
:(
float
)
scale
dim
:(
std
::
vector
<
int64_t
>
)
dim
{
-
(
void
)
preprocess
:(
const
UInt8
*
)
input
output
:(
float
*
)
output
bytesPerRow
:(
int
)
bytesPerRow
imageWidth
:(
int
)
imageWidth
imageHeight
:(
int
)
imageHeight
imageChannels
:(
int
)
imageChannels
means
:(
NSArray
<
NSNumber
*>
*
)
means
stds
:(
NSArray
<
NSNumber
*>
*
)
stds
scale
:(
float
)
scale
dim
:(
std
::
vector
<
int64_t
>
)
dim
{
if
(
means
==
nil
)
{
means
=
@[
@0
,
@0
,
@0
];
}
if
(
stds
==
nil
)
{
stds
=
@[
@1
,
@1
,
@1
];
}
int
wanted_input_width
=
dim
[
3
];
int
wanted_input_height
=
dim
[
2
];
...
...
@@ -212,15 +209,9 @@ static std::mutex shared_mutex;
for
(
int
x
=
0
;
x
<
wanted_input_width
;
++
x
)
{
int
in_row
=
(
y
*
imageHeight
)
/
wanted_input_height
;
int
in_col
=
(
x
*
imageWidth
)
/
wanted_input_width
;
const
UInt8
*
in_pixel
=
input
+
(
in_row
*
imageWidth
*
imageChannels
)
+
(
in_col
*
imageChannels
);
const
UInt8
*
in_pixel
=
input
+
(
in_row
*
bytesPerRow
)
+
(
in_col
*
imageChannels
);
float
*
out_pos
=
out_row
+
x
;
if
(
c
==
0
)
{
*
out_pos
=
(
in_pixel
[
c
]
-
means
[
c
].
floatValue
)
*
scale
;
}
else
if
(
c
==
1
){
*
out_pos
=
(
in_pixel
[
c
]
-
means
[
c
].
floatValue
)
*
scale
;
}
else
if
(
c
==
2
){
*
out_pos
=
(
in_pixel
[
c
]
-
means
[
c
].
floatValue
)
*
scale
;
}
*
out_pos
=
(
in_pixel
[
2
-
c
]
-
means
[
c
].
floatValue
)
/
stds
[
c
].
floatValue
*
scale
;
}
}
}
...
...
@@ -278,8 +269,7 @@ static std::mutex shared_mutex;
return
cpuResult
;
}
-
(
PaddleMobileCPUResult
*
)
predict
:(
CGImageRef
)
image
dim
:(
NSArray
<
NSNumber
*>
*
)
dim
means
:(
NSArray
<
NSNumber
*>
*
)
means
scale
:(
float
)
scale
{
// printf(" predict one ");
-
(
PaddleMobileCPUResult
*
)
predict
:(
CGImageRef
)
image
dim
:(
NSArray
<
NSNumber
*>
*
)
dim
means
:(
NSArray
<
NSNumber
*>
*
)
means
stds
:(
NSArray
<
NSNumber
*>
*
)
stds
scale
:(
float
)
scale
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
shared_mutex
);
if
(
!
loaded_
)
{
printf
(
"PaddleMobile doesn't be loaded yet"
);
...
...
@@ -310,7 +300,7 @@ static std::mutex shared_mutex;
// sample image
float
*
output
=
(
float
*
)
malloc
(
numel
*
sizeof
(
float
));
[
self
preprocess
:
input
output
:
output
imageWidth
:
image_width
imageHeight
:
image_height
imageChannels
:
image_channels
means
:
mean
s
scale
:
scale
dim
:
dim_vec
];
[
self
preprocess
:
input
output
:
output
bytesPerRow
:
sourceRowBytes
imageWidth
:
image_width
imageHeight
:
image_height
imageChannels
:
image_channels
means
:
means
stds
:
std
s
scale
:
scale
dim
:
dim_vec
];
float
*
dataPointer
=
nullptr
;
if
(
nullptr
!=
output
)
{
dataPointer
=
output
;
...
...
@@ -351,7 +341,11 @@ static std::mutex shared_mutex;
}
-
(
PaddleMobileCPUResult
*
)
predict
:(
CGImageRef
)
image
dim
:(
NSArray
<
NSNumber
*>
*
)
dim
{
return
[
self
predict
:
image
dim
:
dim
means
:
nil
scale
:
1
];
return
[
self
predict
:
image
dim
:
dim
means
:
nil
stds
:
nil
scale
:
1
];
}
-
(
PaddleMobileCPUResult
*
)
predict
:(
CGImageRef
)
image
dim
:(
NSArray
<
NSNumber
*>
*
)
dim
means
:(
NSArray
<
NSNumber
*>
*
)
means
scale
:(
float
)
scale
{
return
[
self
predict
:
image
dim
:
dim
means
:
means
stds
:
nil
scale
:
scale
];
}
-
(
PaddleMobileCPUResult
*
)
fetchOutput
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录