Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
d2258a41
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,发现更多精彩内容 >>
提交
d2258a41
编写于
8月 10, 2017
作者:
Y
Yiqun Liu
提交者:
GitHub
8月 10, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3400 from Xreki/capi_read_assets
Support to create a gradient machine with merged model in c-api
上级
478efa2e
4f1f7e90
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
80 addition
and
12 deletion
+80
-12
cmake/flags.cmake
cmake/flags.cmake
+6
-4
paddle/capi/Arguments.cpp
paddle/capi/Arguments.cpp
+12
-0
paddle/capi/arguments.h
paddle/capi/arguments.h
+14
-0
paddle/capi/examples/model_inference/common/common.h
paddle/capi/examples/model_inference/common/common.h
+11
-8
paddle/capi/gradient_machine.cpp
paddle/capi/gradient_machine.cpp
+25
-0
paddle/capi/gradient_machine.h
paddle/capi/gradient_machine.h
+12
-0
未找到文件。
cmake/flags.cmake
浏览文件 @
d2258a41
...
...
@@ -9,10 +9,12 @@ function(CheckCompilerCXX11Flag)
if
(
${
CMAKE_CXX_COMPILER_VERSION
}
VERSION_LESS 4.8
)
message
(
FATAL_ERROR
"Unsupported GCC version. GCC >= 4.8 required."
)
endif
()
# TODO(qijun) gcc 4.9 or later versions raise SEGV due to the optimization problem.
# Use Debug mode instead for now.
if
(
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.9
)
set
(
CMAKE_BUILD_TYPE
"Debug"
CACHE STRING
""
FORCE
)
if
(
NOT ANDROID
)
# TODO(qijun) gcc 4.9 or later versions raise SEGV due to the optimization problem.
# Use Debug mode instead for now.
if
(
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.9
)
set
(
CMAKE_BUILD_TYPE
"Debug"
CACHE STRING
""
FORCE
)
endif
()
endif
()
elseif
(
CMAKE_CXX_COMPILER_ID STREQUAL
"AppleClang"
OR CMAKE_CXX_COMPILER_ID STREQUAL
"Clang"
)
# cmake >= 3.0 compiler id "AppleClang" on Mac OS X, otherwise "Clang"
...
...
paddle/capi/Arguments.cpp
浏览文件 @
d2258a41
...
...
@@ -90,6 +90,18 @@ paddle_error paddle_arguments_set_ids(paddle_arguments args,
return
kPD_NO_ERROR
;
}
paddle_error
paddle_arguments_set_frame_shape
(
paddle_arguments
args
,
uint64_t
ID
,
uint64_t
frameHeight
,
uint64_t
frameWidth
)
{
if
(
args
==
nullptr
)
return
kPD_NULLPTR
;
auto
a
=
castArg
(
args
);
if
(
ID
>=
a
->
args
.
size
())
return
kPD_OUT_OF_RANGE
;
a
->
args
[
ID
].
setFrameHeight
(
frameHeight
);
a
->
args
[
ID
].
setFrameWidth
(
frameWidth
);
return
kPD_NO_ERROR
;
}
paddle_error
paddle_arguments_set_sequence_start_pos
(
paddle_arguments
args
,
uint64_t
ID
,
uint32_t
nestedLevel
,
...
...
paddle/capi/arguments.h
浏览文件 @
d2258a41
...
...
@@ -111,6 +111,20 @@ PD_API paddle_error paddle_arguments_set_ids(paddle_arguments args,
uint64_t
ID
,
paddle_ivector
ids
);
/**
* @brief paddle_arguments_set_frame_shape Set the fram size of one argument
* in array, which index is `ID`.
* @param [in] args arguments array
* @param [in] ID array index
* @param [in] frameHeight maximum height of input images
* @param [in] frameWidth maximum width of input images
* @return paddle_error
*/
PD_API
paddle_error
paddle_arguments_set_frame_shape
(
paddle_arguments
args
,
uint64_t
ID
,
uint64_t
frameHeight
,
uint64_t
frameWidth
);
/**
* @brief PDArgsSetSequenceStartPos Set sequence start position vector of one
* argument in array, which index is `ID`.
...
...
paddle/capi/examples/model_inference/common/common.h
浏览文件 @
d2258a41
...
...
@@ -3,18 +3,21 @@
#include <stdio.h>
#include <stdlib.h>
#define CHECK(stmt) \
do { \
paddle_error __err__ = stmt; \
if (__err__ != kPD_NO_ERROR) { \
fprintf(stderr, "Invoke paddle error %d
\n" #stmt
, __err__); \
exit(__err__); \
} \
#define CHECK(stmt)
\
do {
\
paddle_error __err__ = stmt;
\
if (__err__ != kPD_NO_ERROR) {
\
fprintf(stderr, "Invoke paddle error %d
in " #stmt "\n"
, __err__); \
exit(__err__);
\
}
\
} while (0)
void
*
read_config
(
const
char
*
filename
,
long
*
size
)
{
FILE
*
file
=
fopen
(
filename
,
"r"
);
if
(
file
==
NULL
)
return
NULL
;
if
(
file
==
NULL
)
{
fprintf
(
stderr
,
"Open %s error
\n
"
,
filename
);
return
NULL
;
}
fseek
(
file
,
0L
,
SEEK_END
);
*
size
=
ftell
(
file
);
fseek
(
file
,
0L
,
SEEK_SET
);
...
...
paddle/capi/gradient_machine.cpp
浏览文件 @
d2258a41
...
...
@@ -54,6 +54,31 @@ paddle_error paddle_gradient_machine_create_for_inference(
return
kPD_NO_ERROR
;
}
paddle_error
paddle_gradient_machine_create_for_inference_with_parameters
(
paddle_gradient_machine
*
machine
,
void
*
mergedModel
,
uint64_t
size
)
{
if
(
mergedModel
==
nullptr
)
return
kPD_NULLPTR
;
std
::
istringstream
is
(
std
::
string
(
static_cast
<
char
*>
(
mergedModel
),
size
));
int64_t
modelConfigSize
=
0
;
is
.
read
((
char
*
)(
&
modelConfigSize
),
sizeof
(
modelConfigSize
));
std
::
string
modelConfigProtobuf
;
modelConfigProtobuf
.
resize
(
modelConfigSize
);
is
.
read
(
&
modelConfigProtobuf
[
0
],
modelConfigSize
);
paddle
::
TrainerConfig
config
;
if
(
!
config
.
ParseFromString
(
modelConfigProtobuf
)
||
!
config
.
IsInitialized
())
{
return
kPD_PROTOBUF_ERROR
;
}
auto
ptr
=
new
paddle
::
capi
::
CGradientMachine
();
ptr
->
machine
.
reset
(
paddle
::
GradientMachine
::
create
(
config
.
model_config
(),
CREATE_MODE_TESTING
,
{
paddle
::
PARAMETER_VALUE
}));
std
::
vector
<
paddle
::
ParameterPtr
>&
parameters
=
ptr
->
machine
->
getParameters
();
for
(
auto
&
para
:
parameters
)
{
para
->
load
(
is
);
}
*
machine
=
ptr
;
return
kPD_NO_ERROR
;
}
paddle_error
paddle_gradient_machine_destroy
(
paddle_gradient_machine
machine
)
{
delete
cast
(
machine
);
return
kPD_NO_ERROR
;
...
...
paddle/capi/gradient_machine.h
浏览文件 @
d2258a41
...
...
@@ -36,6 +36,18 @@ typedef void* paddle_gradient_machine;
PD_API
paddle_error
paddle_gradient_machine_create_for_inference
(
paddle_gradient_machine
*
machine
,
void
*
modelConfigProtobuf
,
int
size
);
/**
* @brief Create a gradient machine used for model inference, using config with
* parameters which is generated by `paddle merge_model`.
* @param [out] machine that used for model inference.
* @param [in] mergedModel
* @param [in] size
* @return paddle_error
*/
PD_API
paddle_error
paddle_gradient_machine_create_for_inference_with_parameters
(
paddle_gradient_machine
*
machine
,
void
*
mergedModel
,
uint64_t
size
);
/**
* @brief Load parameter from disk.
* @param machine Gradient Machine.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录