Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-js
提交
a440e8a8
P
Paddle-js
项目概览
PaddlePaddle
/
Paddle-js
通知
22
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
11
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
11
Issue
11
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a440e8a8
编写于
7月 31, 2020
作者:
W
wangqun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[change]修复版本bug
修复版本bug
上级
89b63233
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
182 addition
and
65 deletion
+182
-65
examples/benchmark/config.vue
examples/benchmark/config.vue
+30
-23
examples/mobileNet/index.es6
examples/mobileNet/index.es6
+25
-9
examples/mobileNet/index.html
examples/mobileNet/index.html
+99
-4
src/feed/ImageFeed.es6
src/feed/ImageFeed.es6
+3
-13
src/graph/graph.es6
src/graph/graph.es6
+8
-4
src/utils/utils.es6
src/utils/utils.es6
+17
-12
未找到文件。
examples/benchmark/config.vue
浏览文件 @
a440e8a8
...
@@ -147,7 +147,7 @@ export default Vue.extend({
...
@@ -147,7 +147,7 @@ export default Vue.extend({
{
name
:
'
preheat time
'
,
t
:
this
.
preheatT
},
{
name
:
'
preheat time
'
,
t
:
this
.
preheatT
},
{
name
:
'
subsequent average time
'
,
t
:
this
.
remainOthersT
},
{
name
:
'
subsequent average time
'
,
t
:
this
.
remainOthersT
},
{
name
:
'
best time
'
,
t
:
this
.
bestT
},
{
name
:
'
best time
'
,
t
:
this
.
bestT
},
{
name
:
'
op count
'
,
t
:
this
.
opCount
}
{
name
:
'
op count
'
,
t
:
this
.
opCount
||
'
暂无
'
}
]
]
}
}
},
},
...
@@ -217,9 +217,23 @@ export default Vue.extend({
...
@@ -217,9 +217,23 @@ export default Vue.extend({
// this.remainOthersT = +(remainWholeT / (curTimes - 2).toFixed(4));
// this.remainOthersT = +(remainWholeT / (curTimes - 2).toFixed(4));
const
{
queryList
}
=
this
.
paddle
.
model
.
graph
;
const
{
queryList
}
=
this
.
paddle
.
model
.
graph
;
const
quertyResults
=
this
.
query
(
queryList
);
if
(
!
opCount
)
{
opCount
=
quertyResults
.
length
;
if
(
queryList
&&
queryList
.
length
)
{
const
quertyResults
=
this
.
query
(
queryList
);
if
(
!
opCount
)
{
opCount
=
quertyResults
.
length
;
}
for
(
let
item
of
quertyResults
)
{
progress
.
push
({
index
:
curTimes
,
time
:
item
.
time
,
name
:
item
.
name
});
}
ops
.
push
(
this
.
getOpPerf
(
quertyResults
,
this
.
aggregate
,
{},
true
));
}
}
progress
.
push
({
progress
.
push
({
...
@@ -228,18 +242,7 @@ export default Vue.extend({
...
@@ -228,18 +242,7 @@ export default Vue.extend({
name
:
'
total
'
name
:
'
total
'
});
});
for
(
let
item
of
quertyResults
)
{
progress
.
push
({
index
:
curTimes
,
time
:
item
.
time
,
name
:
item
.
name
});
}
totaltimeList
.
push
(
t
);
totaltimeList
.
push
(
t
);
ops
.
push
(
this
.
getOpPerf
(
quertyResults
,
this
.
aggregate
,
{},
true
));
curTimes
++
;
curTimes
++
;
}
}
...
@@ -247,16 +250,20 @@ export default Vue.extend({
...
@@ -247,16 +250,20 @@ export default Vue.extend({
totaltimeList
.
sort
((
a
,
b
)
=>
a
-
b
);
totaltimeList
.
sort
((
a
,
b
)
=>
a
-
b
);
this
.
bestT
=
totaltimeList
[
0
];
this
.
bestT
=
totaltimeList
[
0
];
const
opInfos
=
this
.
getOpPerf
(
ops
,
this
.
merge
);
this
.
opCount
=
opCount
;
this
.
remainOthersT
=
(
remainWholeT
/
this
.
times
).
toFixed
(
4
);
this
.
remainOthersT
=
(
remainWholeT
/
this
.
times
).
toFixed
(
4
);
this
.
progress
=
progress
;
this
.
progress
=
progress
;
this
.
ops
=
Object
.
keys
(
opInfos
).
map
(
opname
=>
{
return
{
if
(
ops
&&
ops
.
length
)
{
name
:
opname
,
const
opInfos
=
this
.
getOpPerf
(
ops
,
this
.
merge
);
time
:
opInfos
[
opname
].
time
this
.
opCount
=
opCount
;
};
this
.
ops
=
Object
.
keys
(
opInfos
).
map
(
opname
=>
{
});
return
{
name
:
opname
,
time
:
opInfos
[
opname
].
time
};
});
}
this
.
stage
=
4
;
this
.
stage
=
4
;
},
},
async
run
()
{
async
run
()
{
...
...
examples/mobileNet/index.es6
浏览文件 @
a440e8a8
import
'babel-polyfill'
;
import
'babel-polyfill'
;
import
Paddle
from
'../../src/paddle/paddle'
;
import
Paddle
from
'../../src/paddle/paddle'
;
import
IO
from
'../../src/feed/
i
mageFeed'
;
import
IO
from
'../../src/feed/
I
mageFeed'
;
import
Utils
from
'../../src/utils/utils'
;
import
Utils
from
'../../src/utils/utils'
;
// 获取map表
// 获取map表
import
Map
from
'../../test/data/map'
;
//
import Map from '../../test/data/map';
let
map
=
{};
const
fileDownload
=
require
(
'js-file-download'
);
const
fileDownload
=
require
(
'js-file-download'
);
/**
/**
...
@@ -33,6 +33,9 @@ const outputShape = fetchShape[modelType];
...
@@ -33,6 +33,9 @@ const outputShape = fetchShape[modelType];
let
loaded
=
false
;
let
loaded
=
false
;
let
model
=
{};
let
model
=
{};
window
.
statistic
=
[];
window
.
statistic
=
[];
let
loading
=
document
.
getElementsByClassName
(
'data-loading'
);
let
modelTxt
=
document
.
getElementById
(
'model-txt'
);
async
function
run
(
input
)
{
async
function
run
(
input
)
{
// const input = document.getElementById('mobilenet');
// const input = document.getElementById('mobilenet');
const
io
=
new
IO
();
const
io
=
new
IO
();
...
@@ -54,19 +57,25 @@ async function run(input) {
...
@@ -54,19 +57,25 @@ async function run(input) {
const
path
=
'https://paddlejs.cdn.bcebos.com/models/mobileNetV2'
;
const
path
=
'https://paddlejs.cdn.bcebos.com/models/mobileNetV2'
;
if
(
!
loaded
)
{
if
(
!
loaded
)
{
fetch
(
path
+
'/map.json'
)
.
then
(
response
=>
response
.
json
())
.
then
(
data
=>
(
map
=
data
));
const
MODEL_CONFIG
=
{
const
MODEL_CONFIG
=
{
dir
:
`${path}/`
,
// 存放模型的文件夹
dir
:
`${path}/`
,
// 存放模型的文件夹
main
:
'model.json'
,
// 主文件
main
:
'model.json'
,
// 主文件
};
};
loaded
=
true
;
loaded
=
true
;
modelTxt
.
style
.
visibility
=
'visible'
;
loading
[
0
]
.
style
.
visibility
=
'visible'
;
const
paddle
=
new
Paddle
({
const
paddle
=
new
Paddle
({
urlConf
:
MODEL_CONFIG
,
urlConf
:
MODEL_CONFIG
,
options
:
{
options
:
{
multipart
:
true
,
multipart
:
true
,
dataType
:
'binary'
,
dataType
:
'binary'
,
options
:
{
options
:
{
fileCount
:
4
,
// 切成了多少文件
//
fileCount: 4, // 切成了多少文件
getFileName
(
i
)
{
// 获取第i个文件的名称
getFileName
(
i
)
{
//
自定义chunk文件名,
获取第i个文件的名称
return
'chunk_'
+
i
+
'.dat'
;
return
'chunk_'
+
i
+
'.dat'
;
}
}
},
},
...
@@ -74,14 +83,20 @@ async function run(input) {
...
@@ -74,14 +83,20 @@ async function run(input) {
}
}
});
});
model
=
await
paddle
.
load
();
model
=
await
paddle
.
load
();
loading
[
0
]
.
style
.
visibility
=
'hidden'
;
modelTxt
.
innerText
=
'模型加载完成!'
;
}
}
loading
[
1
]
.
style
.
visibility
=
'visible'
;
loading
[
2
]
.
style
.
visibility
=
'visible'
;
window
.
statistic
.
startTime
=
(
+
new
Date
());
let
inst
=
model
.
execute
({
let
inst
=
model
.
execute
({
input
:
feed
input
:
feed
});
});
let
result
=
await
inst
.
read
();
let
result
=
await
inst
.
read
();
loading
[
1
]
.
style
.
visibility
=
'hidden'
;
loading
[
2
]
.
style
.
visibility
=
'hidden'
;
window
.
statistic
.
endTime
=
(
+
new
Date
())
-
window
.
statistic
.
startTime
;
let
N
=
outputShape
[
0
];
let
N
=
outputShape
[
0
];
let
C
=
outputShape
[
1
];
let
C
=
outputShape
[
1
];
let
H
=
outputShape
[
2
];
let
H
=
outputShape
[
2
];
...
@@ -98,8 +113,9 @@ async function run(input) {
...
@@ -98,8 +113,9 @@ async function run(input) {
let
maxItem
=
Utils
.
getMaxItem
(
nchwData
);
let
maxItem
=
Utils
.
getMaxItem
(
nchwData
);
console
.
log
(
maxItem
);
console
.
log
(
maxItem
);
document
.
getElementById
(
'txt'
)
.
innerHTML
=
Map
[
''
+
maxItem
.
index
];
document
.
getElementById
(
'txt'
)
.
innerHTML
=
map
[
''
+
maxItem
.
index
];
console
.
log
(
'识别出的结果是'
+
Map
[
''
+
maxItem
.
index
]);
document
.
getElementById
(
'all-performance-time'
)
.
innerHTML
=
'计算时间是'
+
window
.
statistic
.
endTime
;
console
.
log
(
'识别出的结果是'
+
map
[
''
+
maxItem
.
index
]);
};
};
var
image
=
''
;
var
image
=
''
;
function
selectImage
(
file
)
{
function
selectImage
(
file
)
{
...
...
examples/mobileNet/index.html
浏览文件 @
a440e8a8
...
@@ -3,12 +3,107 @@
...
@@ -3,12 +3,107 @@
<head>
<head>
<meta
charset=
"utf-8"
>
<meta
charset=
"utf-8"
>
<title>
paddle web demo
</title>
<title>
paddle web demo
</title>
<meta
name=
"viewport"
content=
"width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"
>
<link
rel=
"stylesheet"
href=
"https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
integrity=
"sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin=
"anonymous"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<style>
.demo-nav
{
background-color
:
#2932e1
;
color
:
#fff
;
}
.paddle-demo-card
{
margin-right
:
0
;
margin-left
:
0
;
background-color
:
#fff
;
border
:
1px
solid
#ddd
;
}
.infobox
{
background-color
:
#fff
;
border-radius
:
6px
;
margin-bottom
:
30px
;
padding
:
20px
;
position
:
relative
;
min-height
:
350px
;
box-sizing
:
border-box
;
color
:
#707070
;
}
@-webkit-keyframes
spin
{
from
{
-webkit-transform
:
rotate
(
0deg
);
}
to
{
-webkit-transform
:
rotate
(
360deg
);
}
}
@keyframes
spin
{
from
{
transform
:
rotate
(
0deg
);
}
to
{
transform
:
rotate
(
360deg
);
}
}
.data-loading
{
visibility
:
hidden
;
-webkit-animation
:
spin
1s
linear
1s
5
alternate
;
animation
:
spin
1s
linear
infinite
;
}
#model-txt
{
visibility
:
hidden
;
}
</style>
</head>
</head>
<body>
<body>
<img
id=
"image"
src=
"https://m.baidu.com/se/static/img/iphone/logo.png"
style=
"max-width: 100%;"
>
<header
class=
"navbar navbar-static-top bs-docs-nav demo-nav"
>
<input
type=
"file"
id=
"uploadImg"
>
<div
class=
"container"
>
<div
id=
"txt"
></div>
<div
class=
"navbar-header"
>
<div
class=
"navbar-brand"
>
paddleJS Demo Page
</div>
</div>
</div>
</header>
<div
class=
"container"
>
<div
class=
"col-xs-12"
>
<div
class=
"row"
>
<div
class=
"col-lg-3 col-md-6 col-sm-6 col-xs-12 continfobox"
>
<div
class=
"paddle-demo-card infobox text-center"
>
<div
class=
"flip-container"
>
<div
class=
"paddle-demo-block-wrapper"
>
<div
class=
"h2"
>
操作面板:
</div><input
type=
"file"
id=
"uploadImg"
>
<p
class=
"help-block"
>
点击按钮,选择图片触发计算.
</p>
<p
id=
"model-txt"
>
模型加载中.
</p>
<div
class=
"glyphicon glyphicon-refresh data-loading"
></div>
<div
class=
"paddle-demo-block-wrapper"
>
<img
id=
"image"
src=
"https://mms-voice.cdn.bcebos.com/mumstory/banana.jpg"
style=
"height: 50px"
alt=
"Responsive image"
>
</div>
</div>
</div>
</div>
</div>
<div
class=
"col-lg-3 col-md-6 col-sm-6 col-xs-12 continfobox"
>
<div
class=
"paddle-demo-card infobox text-center"
>
<div
class=
"flip-container"
>
<div
class=
"paddle-demo-block-wrapper"
>
<div
class=
"h2"
>
预测结果:
</div><div
id=
"txt"
>
...
</div>
<div
class=
"glyphicon glyphicon-refresh data-loading"
></div>
</div>
</div>
</div>
</div>
<div
class=
"col-lg-3 col-md-6 col-sm-6 col-xs-12 continfobox"
>
<div
class=
"paddle-demo-card infobox text-center"
>
<div
class=
"flip-container"
>
<div
class=
"paddle-demo-block-wrapper"
>
<div
class=
"h2"
>
性能分析:
</div><div
id=
"all-performance-time"
>
...
</div>
<div
class=
"glyphicon glyphicon-refresh data-loading"
></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script
src=
"index.es6"
></script>
<script
src=
"index.es6"
></script>
</body>
</body>
</html>
</html>
\ No newline at end of file
src/feed/ImageFeed.es6
浏览文件 @
a440e8a8
...
@@ -170,21 +170,11 @@ export default class imageFeed {
...
@@ -170,21 +170,11 @@ export default class imageFeed {
// 原始图片宽高
// 原始图片宽高
const width = this.pixelWidth;
const width = this.pixelWidth;
const height = this.pixelHeight;
const height = this.pixelHeight;
//
缩放
后的宽高
//
Resize
后的宽高
let sw = width;
let sw = width;
let sh = height;
let sh = height;
// 最小边缩放到scale
// 直接Resize
if (width < height) {
sw = sh = params.scale ;
sw = params.scale || width;
sh = Math.round(sw * height / width);
}
else if (width > height){
sh = params.scale || height;
sw = Math.round(sh * width / height);
}
else {
sw = sh = params.scale || width;
}
this.fromPixels2DContext.canvas.width = sw;
this.fromPixels2DContext.canvas.width = sw;
this.fromPixels2DContext.canvas.height = sh;
this.fromPixels2DContext.canvas.height = sh;
...
...
src/graph/graph.es6
浏览文件 @
a440e8a8
...
@@ -32,6 +32,7 @@ export default class Graph {
...
@@ -32,6 +32,7 @@ export default class Graph {
// 网络层数
// 网络层数
this.iLayer = 0;
this.iLayer = 0;
this.queryList = [];
this.queryList = [];
this.glVersion = 2;
if (this.options && this.options.options ) {
if (this.options && this.options.options ) {
if (this.options.options.test === true) {
if (this.options.options.test === true) {
...
@@ -46,7 +47,8 @@ export default class Graph {
...
@@ -46,7 +47,8 @@ export default class Graph {
if (!this.inst) {
if (!this.inst) {
// op runner
// op runner
this.inst = new Runtime(this.options.options);
this.inst = new Runtime(this.options.options);
factory.setWebglVersion(this.inst.getWebglVersion());
this.glVersion = this.inst.getWebglVersion();
factory.setWebglVersion(this.glVersion);
factory.setIsFrameBufferSupportFloat(this.inst.getIsFrameBufferSupportFloat());
factory.setIsFrameBufferSupportFloat(this.inst.getIsFrameBufferSupportFloat());
Utils.setTextureMaxSize(this.inst.getWebglMaxTextureSize());
Utils.setTextureMaxSize(this.inst.getWebglMaxTextureSize());
...
@@ -95,13 +97,15 @@ export default class Graph {
...
@@ -95,13 +97,15 @@ export default class Graph {
}
}
const gl = this.inst.gpu.gl;
const gl = this.inst.gpu.gl;
let query = Utils.beginQuery(gl);
let query = Utils.beginQuery(gl
, this.glVersion
);
opindex++;
opindex++;
executor.execute(this.inst, this.isExecuted);
executor.execute(this.inst, this.isExecuted);
this.queryList.push({name: executor.type, query, count: 1});
if (query) {
query = Utils.endQuery(gl, query);
this.queryList.push({name: executor.type, query, count: 1});
query = Utils.endQuery(gl,this.glVersion, query);
}
if (false && executor.opData && opindex >= 184){
if (false && executor.opData && opindex >= 184){
console.log('return!');
console.log('return!');
...
...
src/utils/utils.es6
浏览文件 @
a440e8a8
...
@@ -15,21 +15,26 @@ export default {
...
@@ -15,21 +15,26 @@ export default {
// Return milliseconds.
// Return milliseconds.
return timeElapsedNanos;
return timeElapsedNanos;
},
},
beginQuery(gl) {
beginQuery(gl, glVersion) {
const ext = gl.getExtension('EXT_disjoint_timer_query_webgl2');
if (glVersion === 2) {
if (!ext) {
const ext = gl.getExtension('EXT_disjoint_timer_query_webgl2');
return;
if (!ext) {
return;
}
const query = gl.createQuery();
gl.beginQuery(ext.TIME_ELAPSED_EXT, query);
return query;
}
}
const query = gl.createQuery();
return null;
gl.beginQuery(ext.TIME_ELAPSED_EXT, query);
return query;
},
},
endQuery(gl, query) {
endQuery(gl, glVersion, query) {
const ext = gl.getExtension('EXT_disjoint_timer_query_webgl2');
if (glVersion === 2) {
if (!ext) {
const ext = gl.getExtension('EXT_disjoint_timer_query_webgl2');
return;
if (!ext) {
return;
}
gl.endQuery(ext.TIME_ELAPSED_EXT);
}
}
gl.endQuery(ext.TIME_ELAPSED_EXT);
return query;
return query;
},
},
// todo: 适用2维矩阵乘法,以后实现通用版本
// todo: 适用2维矩阵乘法,以后实现通用版本
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录