Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleX
提交
d4986632
P
PaddleX
项目概览
PaddlePaddle
/
PaddleX
通知
138
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
43
列表
看板
标记
里程碑
合并请求
5
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleX
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
43
Issue
43
列表
看板
标记
里程碑
合并请求
5
合并请求
5
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d4986632
编写于
8月 25, 2020
作者:
C
Channingss
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize visualize&preprocess speed
上级
38980c5c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
16 deletion
+27
-16
deploy/lite/android/sdk/src/main/java/com/baidu/paddlex/preprocess/Transforms.java
...rc/main/java/com/baidu/paddlex/preprocess/Transforms.java
+21
-11
deploy/lite/android/sdk/src/main/java/com/baidu/paddlex/visual/Visualize.java
...sdk/src/main/java/com/baidu/paddlex/visual/Visualize.java
+6
-5
未找到文件。
deploy/lite/android/sdk/src/main/java/com/baidu/paddlex/preprocess/Transforms.java
浏览文件 @
d4986632
...
@@ -23,6 +23,7 @@ import org.opencv.core.Scalar;
...
@@ -23,6 +23,7 @@ import org.opencv.core.Scalar;
import
org.opencv.core.Size
;
import
org.opencv.core.Size
;
import
org.opencv.imgproc.Imgproc
;
import
org.opencv.imgproc.Imgproc
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
...
@@ -101,6 +102,15 @@ public class Transforms {
...
@@ -101,6 +102,15 @@ public class Transforms {
if
(
info
.
containsKey
(
"coarsest_stride"
))
{
if
(
info
.
containsKey
(
"coarsest_stride"
))
{
padding
.
coarsest_stride
=
(
int
)
info
.
get
(
"coarsest_stride"
);
padding
.
coarsest_stride
=
(
int
)
info
.
get
(
"coarsest_stride"
);
}
}
if
(
info
.
containsKey
(
"im_padding_value"
))
{
List
<
Double
>
im_padding_value
=
(
List
<
Double
>)
info
.
get
(
"im_padding_value"
);
if
(
im_padding_value
.
size
()!=
3
){
Log
.
e
(
TAG
,
"len of im_padding_value in padding must == 3."
);
}
for
(
int
k
=
0
;
i
<
im_padding_value
.
size
();
i
++){
padding
.
paddding_value
[
k
]
=
im_padding_value
.
get
(
k
);
}
}
if
(
info
.
containsKey
(
"target_size"
))
{
if
(
info
.
containsKey
(
"target_size"
))
{
if
(
info
.
get
(
"target_size"
)
instanceof
Integer
)
{
if
(
info
.
get
(
"target_size"
)
instanceof
Integer
)
{
padding
.
width
=
(
int
)
info
.
get
(
"target_size"
);
padding
.
width
=
(
int
)
info
.
get
(
"target_size"
);
...
@@ -124,7 +134,7 @@ public class Transforms {
...
@@ -124,7 +134,7 @@ public class Transforms {
if
(
transformsMode
.
equalsIgnoreCase
(
"RGB"
)){
if
(
transformsMode
.
equalsIgnoreCase
(
"RGB"
)){
Imgproc
.
cvtColor
(
inputMat
,
inputMat
,
Imgproc
.
COLOR_BGR2RGB
);
Imgproc
.
cvtColor
(
inputMat
,
inputMat
,
Imgproc
.
COLOR_BGR2RGB
);
}
else
if
(!
transformsMode
.
equalsIgnoreCase
(
"BGR"
)){
}
else
if
(!
transformsMode
.
equalsIgnoreCase
(
"BGR"
)){
Log
.
e
(
TAG
,
"transformsMode only support RGB or BGR"
);
Log
.
e
(
TAG
,
"transformsMode only support RGB or BGR
.
"
);
}
}
inputMat
.
convertTo
(
inputMat
,
CvType
.
CV_32FC
(
3
));
inputMat
.
convertTo
(
inputMat
,
CvType
.
CV_32FC
(
3
));
...
@@ -136,16 +146,15 @@ public class Transforms {
...
@@ -136,16 +146,15 @@ public class Transforms {
int
h
=
inputMat
.
height
();
int
h
=
inputMat
.
height
();
int
c
=
inputMat
.
channels
();
int
c
=
inputMat
.
channels
();
imageBlob
.
setImageData
(
new
float
[
w
*
h
*
c
]);
imageBlob
.
setImageData
(
new
float
[
w
*
h
*
c
]);
int
[]
channelStride
=
new
int
[]{
w
*
h
,
w
*
h
*
2
};
for
(
int
y
=
0
;
y
<
h
;
y
++)
{
Mat
singleChannelMat
=
new
Mat
(
h
,
w
,
CvType
.
CV_32FC
(
1
));
for
(
int
x
=
0
;
float
[]
singleChannelImageData
=
new
float
[
w
*
h
];
x
<
w
;
x
++)
{
for
(
int
i
=
0
;
i
<
c
;
i
++)
{
double
[]
color
=
inputMat
.
get
(
y
,
x
);
Core
.
extractChannel
(
inputMat
,
singleChannelMat
,
i
);
imageBlob
.
getImageData
()[
y
*
w
+
x
]
=
(
float
)
(
color
[
0
]);
singleChannelMat
.
get
(
0
,
0
,
singleChannelImageData
);
imageBlob
.
getImageData
()[
y
*
w
+
x
+
channelStride
[
0
]]
=
(
float
)
(
color
[
1
]);
System
.
arraycopy
(
singleChannelImageData
,
0
,
imageBlob
.
getImageData
(),
i
*
w
*
h
,
w
*
h
);
imageBlob
.
getImageData
()[
y
*
w
+
x
+
channelStride
[
1
]]
=
(
float
)
(
color
[
2
]);
}
}
}
return
imageBlob
;
return
imageBlob
;
}
}
...
@@ -248,6 +257,7 @@ public class Transforms {
...
@@ -248,6 +257,7 @@ public class Transforms {
private
double
width
;
private
double
width
;
private
double
height
;
private
double
height
;
private
double
coarsest_stride
;
private
double
coarsest_stride
;
private
double
[]
paddding_value
=
{
0.0
,
0.0
,
0.0
};
public
Mat
run
(
Mat
inputMat
,
ImageBlob
imageBlob
)
{
public
Mat
run
(
Mat
inputMat
,
ImageBlob
imageBlob
)
{
int
origin_w
=
inputMat
.
width
();
int
origin_w
=
inputMat
.
width
();
...
@@ -264,7 +274,7 @@ public class Transforms {
...
@@ -264,7 +274,7 @@ public class Transforms {
}
}
imageBlob
.
setNewImageSize
(
inputMat
.
height
(),
2
);
imageBlob
.
setNewImageSize
(
inputMat
.
height
(),
2
);
imageBlob
.
setNewImageSize
(
inputMat
.
width
(),
3
);
imageBlob
.
setNewImageSize
(
inputMat
.
width
(),
3
);
Core
.
copyMakeBorder
(
inputMat
,
inputMat
,
0
,
(
int
)
padding_h
,
0
,
(
int
)
padding_w
,
Core
.
BORDER_CONSTANT
,
new
Scalar
(
0
));
Core
.
copyMakeBorder
(
inputMat
,
inputMat
,
0
,
(
int
)
padding_h
,
0
,
(
int
)
padding_w
,
Core
.
BORDER_CONSTANT
,
new
Scalar
(
paddding_value
));
return
inputMat
;
return
inputMat
;
}
}
}
}
...
...
deploy/lite/android/sdk/src/main/java/com/baidu/paddlex/visual/Visualize.java
浏览文件 @
d4986632
...
@@ -31,8 +31,11 @@ import org.opencv.core.Scalar;
...
@@ -31,8 +31,11 @@ import org.opencv.core.Scalar;
import
org.opencv.core.Size
;
import
org.opencv.core.Size
;
import
org.opencv.imgproc.Imgproc
;
import
org.opencv.imgproc.Imgproc
;
import
java.nio.ByteBuffer
;
import
java.nio.FloatBuffer
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.ListIterator
;
import
java.util.ListIterator
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -120,13 +123,11 @@ public class Visualize {
...
@@ -120,13 +123,11 @@ public class Visualize {
int
new_w
=
(
int
)
imageBlob
.
getNewImageSize
()[
3
];
int
new_w
=
(
int
)
imageBlob
.
getNewImageSize
()[
3
];
Mat
mask
=
new
Mat
(
new_h
,
new_w
,
CvType
.
CV_32FC
(
1
));
Mat
mask
=
new
Mat
(
new_h
,
new_w
,
CvType
.
CV_32FC
(
1
));
float
[]
scoreData
=
new
float
[
new_h
*
new_w
];
float
[]
scoreData
=
new
float
[
new_h
*
new_w
];
for
(
int
h
=
0
;
h
<
new_h
;
h
++)
{
System
.
arraycopy
(
result
.
getMask
().
getScoreData
()
,
cutoutClass
*
new_h
*
new_w
,
scoreData
,
0
,
new_h
*
new_w
);
for
(
int
w
=
0
;
w
<
new_w
;
w
++){
scoreData
[
new_h
*
h
+
w
]
=
(
1
-
result
.
getMask
().
getScoreData
()[
cutoutClass
+
h
*
new_h
+
w
])
*
255
;
}
}
mask
.
put
(
0
,
0
,
scoreData
);
mask
.
put
(
0
,
0
,
scoreData
);
Core
.
multiply
(
mask
,
new
Scalar
(
255
),
mask
);
mask
.
convertTo
(
mask
,
CvType
.
CV_8UC
(
1
));
mask
.
convertTo
(
mask
,
CvType
.
CV_8UC
(
1
));
ListIterator
<
Map
.
Entry
<
String
,
int
[]>>
reverseReshapeInfo
=
new
ArrayList
<
Map
.
Entry
<
String
,
int
[]>>(
imageBlob
.
getReshapeInfo
().
entrySet
()).
listIterator
(
imageBlob
.
getReshapeInfo
().
size
());
ListIterator
<
Map
.
Entry
<
String
,
int
[]>>
reverseReshapeInfo
=
new
ArrayList
<
Map
.
Entry
<
String
,
int
[]>>(
imageBlob
.
getReshapeInfo
().
entrySet
()).
listIterator
(
imageBlob
.
getReshapeInfo
().
size
());
while
(
reverseReshapeInfo
.
hasPrevious
())
{
while
(
reverseReshapeInfo
.
hasPrevious
())
{
Map
.
Entry
<
String
,
int
[]>
entry
=
reverseReshapeInfo
.
previous
();
Map
.
Entry
<
String
,
int
[]>
entry
=
reverseReshapeInfo
.
previous
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录