Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
fa5b1f60
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看板
提交
fa5b1f60
编写于
10月 15, 2018
作者:
D
dolphin8
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove web-exporter from opencl branch
上级
c67257de
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
0 addition
and
216 deletion
+0
-216
tools/web-exporter/CMakeLists.txt
tools/web-exporter/CMakeLists.txt
+0
-20
tools/web-exporter/export-nodejs.cpp
tools/web-exporter/export-nodejs.cpp
+0
-49
tools/web-exporter/export-scope.cpp
tools/web-exporter/export-scope.cpp
+0
-34
tools/web-exporter/export.cpp
tools/web-exporter/export.cpp
+0
-52
tools/web-exporter/export.h
tools/web-exporter/export.h
+0
-61
未找到文件。
tools/web-exporter/CMakeLists.txt
已删除
100644 → 0
浏览文件 @
c67257de
cmake_minimum_required
(
VERSION 3.6
)
project
(
web-exporter
)
set
(
CMAKE_CXX_STANDARD 11
)
file
(
GLOB PADDLE_MOBILE_CPP_FILES
"../../src/common/*.c"
"../../src/common/*.cpp"
"../../src/memory/*.cpp"
"../../src/framework/*.c"
"../../src/framework/*.cpp"
"../../src/framework/program/*.cpp"
"../../src/framework/program/program-optimize/*.cpp"
)
file
(
GLOB EXPORT_CPP_FILES
"*.cpp"
)
add_executable
(
web-exporter
${
PADDLE_MOBILE_CPP_FILES
}
${
EXPORT_CPP_FILES
}
)
target_include_directories
(
web-exporter PRIVATE
"../../src"
)
target_link_libraries
(
web-exporter
)
\ No newline at end of file
tools/web-exporter/export-nodejs.cpp
已删除
100644 → 0
浏览文件 @
c67257de
#include "export.h"
inline
std
::
string
indent
(
int
i
)
{
return
std
::
string
(
i
,
' '
);
}
void
export_nodejs
(
ProgramPtr
program
,
ScopePtr
scope
,
std
::
ostream
&
os
)
{
os
<<
"module.exports.program = {
\n
"
;
os
<<
indent
(
2
)
<<
var2str
(
"blocks"
)
<<
": [
\n
"
;
for
(
const
auto
&
block
:
program
->
Blocks
())
{
os
<<
indent
(
4
)
<<
"{
\n
"
;
os
<<
indent
(
6
)
<<
var2str
(
"vars"
)
<<
": {
\n
"
;
for
(
const
auto
&
var
:
block
->
Vars
())
{
const
auto
&
dim
=
var
->
Tensor_desc
().
Dims
();
os
<<
indent
(
8
)
<<
var2str
(
var
->
Name
())
<<
": {
\n
"
;
os
<<
indent
(
10
)
<<
var2str
(
"dim"
)
<<
": "
<<
var2str
(
dim
)
<<
",
\n
"
;
os
<<
indent
(
10
)
<<
var2str
(
"persistable"
)
<<
": "
<<
var2str
(
var
->
Persistable
())
<<
"
\n
"
;
os
<<
indent
(
8
)
<<
"},
\n
"
;
}
os
<<
indent
(
6
)
<<
"},
\n
"
;
os
<<
indent
(
6
)
<<
var2str
(
"ops"
)
<<
": [
\n
"
;
for
(
const
auto
&
op
:
block
->
Ops
())
{
os
<<
indent
(
8
)
<<
"{
\n
"
;
os
<<
indent
(
10
)
<<
var2str
(
"type"
)
<<
": "
<<
var2str
(
op
->
Type
())
<<
",
\n
"
;
os
<<
indent
(
10
)
<<
var2str
(
"inputs"
)
<<
": {
\n
"
;
for
(
const
auto
&
kv
:
op
->
GetInputs
())
{
os
<<
indent
(
12
)
<<
var2str
(
kv
.
first
)
<<
": "
<<
var2str
(
kv
.
second
)
<<
",
\n
"
;
}
os
<<
indent
(
10
)
<<
"},
\n
"
;
os
<<
indent
(
10
)
<<
var2str
(
"outputs"
)
<<
": {
\n
"
;
for
(
const
auto
&
kv
:
op
->
GetInputs
())
{
os
<<
indent
(
12
)
<<
var2str
(
kv
.
first
)
<<
": "
<<
var2str
(
kv
.
second
)
<<
",
\n
"
;
}
os
<<
indent
(
10
)
<<
"},
\n
"
;
os
<<
indent
(
10
)
<<
var2str
(
"attrs"
)
<<
": {
\n
"
;
for
(
const
auto
&
kv
:
op
->
GetAttrMap
())
{
os
<<
indent
(
12
)
<<
var2str
(
kv
.
first
)
<<
": "
;
os
<<
decltype
(
kv
.
second
)
::
ApplyVistor
(
VarVisitor
(),
kv
.
second
)
<<
",
\n
"
;
}
os
<<
indent
(
10
)
<<
"},
\n
"
;
os
<<
indent
(
8
)
<<
"},
\n
"
;
}
os
<<
indent
(
6
)
<<
"],
\n
"
;
os
<<
indent
(
4
)
<<
"},
\n
"
;
}
os
<<
indent
(
2
)
<<
"]
\n
"
;
os
<<
"}
\n
"
;
}
tools/web-exporter/export-scope.cpp
已删除
100644 → 0
浏览文件 @
c67257de
#include <cstdio>
#include "export.h"
void
export_scope
(
ProgramPtr
program
,
ScopePtr
scope
,
const
std
::
string
&
dirname
)
{
for
(
const
auto
&
block
:
program
->
Blocks
())
{
for
(
const
auto
&
var
:
block
->
Vars
())
{
if
(
var
->
Name
()
==
"feed"
||
var
->
Name
()
==
"fetch"
)
{
continue
;
}
if
(
var
->
Persistable
())
{
auto
*
v
=
scope
->
FindVar
(
var
->
Name
());
assert
(
v
!=
nullptr
);
int
count
=
1
;
for
(
auto
n
:
var
->
Tensor_desc
().
Dims
())
{
count
*=
n
;
}
auto
*
tensor
=
v
->
GetMutable
<
paddle_mobile
::
framework
::
LoDTensor
>
();
const
float
*
p
=
tensor
->
mutable_data
<
float
>
();
std
::
string
para_file_name
=
dirname
+
'/'
+
var
->
Name
();
FILE
*
para_file
=
fopen
(
para_file_name
.
c_str
(),
"w"
);
assert
(
p
!=
nullptr
);
fwrite
(
p
,
sizeof
(
float
),
count
,
para_file
);
fclose
(
para_file
);
// std::cout << "==> " << var->Name() << " " << count << "\n";
// for (int i = 0; i < count; i++) {
// std::cout << p[i] << ", ";
// }
// std::cout << "\n";
}
}
}
}
tools/web-exporter/export.cpp
已删除
100644 → 0
浏览文件 @
c67257de
#include "export.h"
#include <sys/stat.h>
#include <sys/types.h>
class
FakeExecutor
:
public
paddle_mobile
::
framework
::
Executor
<
paddle_mobile
::
CPU
,
paddle_mobile
::
Precision
::
FP32
>
{
public:
FakeExecutor
(
const
paddle_mobile
::
framework
::
Program
<
paddle_mobile
::
CPU
>
p
)
{
program_
=
p
;
batch_size_
=
1
;
use_optimize_
=
true
;
loddable_
=
false
;
if
(
use_optimize_
)
{
to_predict_program_
=
program_
.
optimizeProgram
;
}
else
{
to_predict_program_
=
program_
.
originProgram
;
}
auto
*
variable_ptr
=
program_
.
scope
->
Var
(
"batch_size"
);
variable_ptr
[
0
].
SetValue
<
int
>
(
1
);
if
(
program_
.
combined
)
{
InitCombineMemory
();
}
else
{
InitMemory
();
}
}
};
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
!=
3
)
{
std
::
cout
<<
"Usage: "
<<
argv
[
0
]
<<
" <combined-modle-dir> <output-dir>
\n
"
;
return
-
1
;
}
std
::
string
model_dir
=
argv
[
1
];
std
::
string
model_path
=
model_dir
+
"/model"
;
std
::
string
para_path
=
model_dir
+
"/params"
;
std
::
string
out_dir
=
argv
[
2
];
std
::
string
out_model_js
=
out_dir
+
"/model.js"
;
std
::
string
out_para_dir
=
out_dir
+
"/paras"
;
mkdir
(
out_dir
.
c_str
(),
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
mkdir
(
out_para_dir
.
c_str
(),
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
std
::
cout
<<
"loading "
<<
model_path
<<
" & "
<<
para_path
<<
"
\n
"
;
paddle_mobile
::
framework
::
Loader
<>
loader
;
auto
program
=
loader
.
Load
(
model_path
,
para_path
,
true
);
FakeExecutor
executor
(
program
);
auto
optimizedProgram
=
program
.
optimizeProgram
;
export_scope
(
optimizedProgram
,
program
.
scope
,
out_para_dir
);
std
::
ofstream
fs
(
out_model_js
.
c_str
());
export_nodejs
(
optimizedProgram
,
program
.
scope
,
fs
);
fs
.
close
();
return
0
;
}
tools/web-exporter/export.h
已删除
100644 → 0
浏览文件 @
c67257de
#pragma once
#include <iostream>
#include <vector>
#include <memory>
#include <string>
#include <ostream>
#include <fstream>
#include "framework/loader.h"
#include "framework/executor.h"
#include "framework/scope.h"
#include "framework/program/program_desc.h"
// using paddle_mobile::framework::ProgramDesc;
// using paddle_mobile::framework::Scope;
using
ProgramPtr
=
std
::
shared_ptr
<
paddle_mobile
::
framework
::
ProgramDesc
>
;
using
ScopePtr
=
std
::
shared_ptr
<
paddle_mobile
::
framework
::
Scope
>
;
void
export_nodejs
(
ProgramPtr
program
,
ScopePtr
scope
,
std
::
ostream
&
os
=
std
::
cout
);
void
export_scope
(
ProgramPtr
program
,
ScopePtr
scope
,
const
std
::
string
&
dirname
=
"."
);
template
<
typename
T
>
inline
std
::
string
var2str
(
const
T
&
v
)
{
return
std
::
to_string
(
v
);
}
template
<
>
inline
std
::
string
var2str
(
const
std
::
string
&
v
)
{
return
"
\"
"
+
v
+
"
\"
"
;
}
inline
std
::
string
var2str
(
const
char
*
v
)
{
return
var2str
<
std
::
string
>
(
v
);
}
inline
std
::
string
var2str
(
const
bool
v
)
{
return
v
?
"true"
:
"false"
;
}
template
<
typename
T
>
std
::
string
var2str
(
const
std
::
vector
<
T
>
&
v
)
{
std
::
string
r
=
"["
;
auto
s
=
v
.
size
();
for
(
int
i
=
0
;
i
<
s
;
i
++
)
{
if
(
i
)
r
+=
", "
;
r
+=
var2str
(
v
[
i
]);
}
return
r
+
"]"
;
}
struct
VarVisitor
{
using
type_t
=
decltype
(
var2str
(
0
));
template
<
typename
T
>
type_t
operator
()(
const
T
&
v
)
{
return
var2str
(
v
);
}
};
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录