Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
Models
提交
a25570d6
M
Models
项目概览
MegEngine 天元
/
Models
通知
6
Star
3
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
a25570d6
编写于
8月 10, 2020
作者:
J
Jianfeng Wang
提交者:
GitHub
8月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(detection): optimize dtype (#55)
上级
61d87c76
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
11 addition
and
46 deletion
+11
-46
official/vision/detection/layers/basic/functional.py
official/vision/detection/layers/basic/functional.py
+0
-35
official/vision/detection/layers/det/anchor.py
official/vision/detection/layers/det/anchor.py
+2
-2
official/vision/detection/layers/det/box_utils.py
official/vision/detection/layers/det/box_utils.py
+2
-2
official/vision/detection/models/faster_rcnn.py
official/vision/detection/models/faster_rcnn.py
+2
-2
official/vision/detection/models/retinanet.py
official/vision/detection/models/retinanet.py
+3
-3
official/vision/detection/tools/test.py
official/vision/detection/tools/test.py
+2
-2
未找到文件。
official/vision/detection/layers/basic/functional.py
浏览文件 @
a25570d6
...
@@ -13,41 +13,6 @@ import megengine.functional as F
...
@@ -13,41 +13,6 @@ import megengine.functional as F
from
megengine.core
import
Tensor
from
megengine.core
import
Tensor
def
get_padded_array_np
(
array
:
np
.
ndarray
,
multiple_number
:
int
=
32
,
pad_value
:
float
=
0
)
->
np
.
ndarray
:
""" pad the nd-array to multiple stride of th e
Args:
array (np.ndarray):
the array with the shape of [batch, channel, height, width]
multiple_number (int):
make the height and width can be divided by multiple_number
pad_value (int): the value to be padded
Returns:
padded_array (np.ndarray)
"""
batch
,
chl
,
t_height
,
t_width
=
array
.
shape
padded_height
=
(
(
t_height
+
multiple_number
-
1
)
//
multiple_number
*
multiple_number
)
padded_width
=
(
t_width
+
multiple_number
-
1
)
//
multiple_number
*
multiple_number
padded_array
=
(
np
.
ones
([
batch
,
chl
,
padded_height
,
padded_width
],
dtype
=
np
.
float32
)
*
pad_value
)
ndim
=
array
.
ndim
if
ndim
==
4
:
padded_array
[:,
:,
:
t_height
,
:
t_width
]
=
array
elif
ndim
==
3
:
padded_array
[:,
:
t_height
,
:
t_width
]
=
array
else
:
raise
Exception
(
"Not supported tensor dim: %d"
%
ndim
)
return
padded_array
def
get_padded_tensor
(
def
get_padded_tensor
(
array
:
Tensor
,
multiple_number
:
int
=
32
,
pad_value
:
float
=
0
array
:
Tensor
,
multiple_number
:
int
=
32
,
pad_value
:
float
=
0
)
->
Tensor
:
)
->
Tensor
:
...
...
official/vision/detection/layers/det/anchor.py
浏览文件 @
a25570d6
...
@@ -48,8 +48,8 @@ class DefaultAnchorGenerator(BaseAnchorGenerator):
...
@@ -48,8 +48,8 @@ class DefaultAnchorGenerator(BaseAnchorGenerator):
):
):
super
().
__init__
()
super
().
__init__
()
self
.
base_size
=
base_size
self
.
base_size
=
base_size
self
.
anchor_scales
=
np
.
array
(
anchor_scales
)
self
.
anchor_scales
=
np
.
array
(
anchor_scales
,
dtype
=
np
.
float32
)
self
.
anchor_ratios
=
np
.
array
(
anchor_ratios
)
self
.
anchor_ratios
=
np
.
array
(
anchor_ratios
,
dtype
=
np
.
float32
)
self
.
offset
=
offset
self
.
offset
=
offset
def
_whctrs
(
self
,
anchor
):
def
_whctrs
(
self
,
anchor
):
...
...
official/vision/detection/layers/det/box_utils.py
浏览文件 @
a25570d6
...
@@ -42,8 +42,8 @@ class BoxCoder(BoxCoderBase, metaclass=ABCMeta):
...
@@ -42,8 +42,8 @@ class BoxCoder(BoxCoderBase, metaclass=ABCMeta):
reg_std(np.ndarray): [x0_std, x1_std, y0_std, y1_std] or None
reg_std(np.ndarray): [x0_std, x1_std, y0_std, y1_std] or None
"""
"""
self
.
reg_mean
=
np
.
array
(
reg_mean
)[
None
,
:]
self
.
reg_mean
=
np
.
array
(
reg_mean
,
dtype
=
np
.
float32
)[
None
,
:]
self
.
reg_std
=
np
.
array
(
reg_std
)[
None
,
:]
self
.
reg_std
=
np
.
array
(
reg_std
,
dtype
=
np
.
float32
)[
None
,
:]
super
().
__init__
()
super
().
__init__
()
@
staticmethod
@
staticmethod
...
...
official/vision/detection/models/faster_rcnn.py
浏览文件 @
a25570d6
...
@@ -68,8 +68,8 @@ class FasterRCNN(M.Module):
...
@@ -68,8 +68,8 @@ class FasterRCNN(M.Module):
def
preprocess_image
(
self
,
image
):
def
preprocess_image
(
self
,
image
):
normed_image
=
(
normed_image
=
(
image
-
np
.
array
(
self
.
cfg
.
img_mean
)[
None
,
:,
None
,
None
]
image
-
np
.
array
(
self
.
cfg
.
img_mean
,
dtype
=
np
.
float32
)[
None
,
:,
None
,
None
]
)
/
np
.
array
(
self
.
cfg
.
img_std
)[
None
,
:,
None
,
None
]
)
/
np
.
array
(
self
.
cfg
.
img_std
,
dtype
=
np
.
float32
)[
None
,
:,
None
,
None
]
return
layers
.
get_padded_tensor
(
normed_image
,
32
,
0.0
)
return
layers
.
get_padded_tensor
(
normed_image
,
32
,
0.0
)
def
forward
(
self
,
inputs
):
def
forward
(
self
,
inputs
):
...
...
official/vision/detection/models/retinanet.py
浏览文件 @
a25570d6
...
@@ -33,7 +33,7 @@ class RetinaNet(M.Module):
...
@@ -33,7 +33,7 @@ class RetinaNet(M.Module):
)
)
self
.
box_coder
=
layers
.
BoxCoder
(
cfg
.
reg_mean
,
cfg
.
reg_std
)
self
.
box_coder
=
layers
.
BoxCoder
(
cfg
.
reg_mean
,
cfg
.
reg_std
)
self
.
stride_list
=
np
.
array
(
cfg
.
stride
).
astype
(
np
.
float32
)
self
.
stride_list
=
np
.
array
(
cfg
.
stride
,
dtype
=
np
.
float32
)
self
.
in_features
=
[
"p3"
,
"p4"
,
"p5"
,
"p6"
,
"p7"
]
self
.
in_features
=
[
"p3"
,
"p4"
,
"p5"
,
"p6"
,
"p7"
]
# ----------------------- build the backbone ------------------------ #
# ----------------------- build the backbone ------------------------ #
...
@@ -82,8 +82,8 @@ class RetinaNet(M.Module):
...
@@ -82,8 +82,8 @@ class RetinaNet(M.Module):
def
preprocess_image
(
self
,
image
):
def
preprocess_image
(
self
,
image
):
normed_image
=
(
normed_image
=
(
image
-
np
.
array
(
self
.
cfg
.
img_mean
)[
None
,
:,
None
,
None
]
image
-
np
.
array
(
self
.
cfg
.
img_mean
,
dtype
=
np
.
float32
)[
None
,
:,
None
,
None
]
)
/
np
.
array
(
self
.
cfg
.
img_std
)[
None
,
:,
None
,
None
]
)
/
np
.
array
(
self
.
cfg
.
img_std
,
dtype
=
np
.
float32
)[
None
,
:,
None
,
None
]
return
layers
.
get_padded_tensor
(
normed_image
,
32
,
0.0
)
return
layers
.
get_padded_tensor
(
normed_image
,
32
,
0.0
)
def
forward
(
self
,
inputs
):
def
forward
(
self
,
inputs
):
...
...
official/vision/detection/tools/test.py
浏览文件 @
a25570d6
...
@@ -64,7 +64,7 @@ def main():
...
@@ -64,7 +64,7 @@ def main():
args
.
start_epoch
=
cfg
.
max_epoch
-
1
args
.
start_epoch
=
cfg
.
max_epoch
-
1
if
args
.
end_epoch
==
-
1
:
if
args
.
end_epoch
==
-
1
:
args
.
end_epoch
=
args
.
start_epoch
args
.
end_epoch
=
args
.
start_epoch
assert
0
<=
args
.
start_epoch
<=
args
.
end_epoch
<
cfg
.
max_epoch
assert
0
<=
args
.
start_epoch
<=
args
.
end_epoch
<
cfg
.
max_epoch
for
epoch_num
in
range
(
args
.
start_epoch
,
args
.
end_epoch
+
1
):
for
epoch_num
in
range
(
args
.
start_epoch
,
args
.
end_epoch
+
1
):
if
args
.
weight_file
:
if
args
.
weight_file
:
...
@@ -182,7 +182,7 @@ def worker(
...
@@ -182,7 +182,7 @@ def worker(
result_queue
.
put_nowait
(
result_queue
.
put_nowait
(
{
{
"det_res"
:
pred_res
,
"det_res"
:
pred_res
,
"image_id"
:
int
(
data_dict
[
1
][
2
][
0
].
split
(
"."
)[
0
]
.
split
(
"_"
)[
-
1
]
),
"image_id"
:
int
(
data_dict
[
1
][
2
][
0
].
split
(
"."
)[
0
]),
}
}
)
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录