Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
536506c3
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
404
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
536506c3
编写于
7月 23, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(functional): let interpolate support more modes
GitOrigin-RevId: 9693a1ac638658ca1ee0b5d0eff507d74fcc996d
上级
d811dc54
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
7 deletion
+19
-7
imperative/python/megengine/functional/vision.py
imperative/python/megengine/functional/vision.py
+19
-7
未找到文件。
imperative/python/megengine/functional/vision.py
浏览文件 @
536506c3
...
@@ -17,7 +17,7 @@ from ..core.tensor.utils import astensor1d
...
@@ -17,7 +17,7 @@ from ..core.tensor.utils import astensor1d
from
..tensor
import
Tensor
from
..tensor
import
Tensor
from
.elemwise
import
floor
from
.elemwise
import
floor
from
.math
import
argsort
from
.math
import
argsort
from
.tensor
import
broadcast_to
,
concat
,
expand_dims
,
reshape
from
.tensor
import
broadcast_to
,
concat
,
expand_dims
,
reshape
,
transpose
def
cvt_color
(
inp
:
Tensor
,
mode
:
str
=
""
):
def
cvt_color
(
inp
:
Tensor
,
mode
:
str
=
""
):
...
@@ -474,7 +474,7 @@ def interpolate(
...
@@ -474,7 +474,7 @@ def interpolate(
:param size: size of the output tensor. Default: None
:param size: size of the output tensor. Default: None
:param scale_factor: scaling factor of the output tensor. Default: None
:param scale_factor: scaling factor of the output tensor. Default: None
:param mode: interpolation methods, acceptable values are:
:param mode: interpolation methods, acceptable values are:
"bilinear", "linear". Default: "bilinear"
"bilinear", "linear"
, "bicubic" and "nearest"
. Default: "bilinear"
:param align_corners: This only has an effect when `mode`
:param align_corners: This only has an effect when `mode`
is "bilinear" or "linear". Geometrically, we consider the pixels of the input
is "bilinear" or "linear". Geometrically, we consider the pixels of the input
and output as squares rather than points. If set to ``True``, the input
and output as squares rather than points. If set to ``True``, the input
...
@@ -511,8 +511,8 @@ def interpolate(
...
@@ -511,8 +511,8 @@ def interpolate(
"""
"""
mode
=
mode
.
lower
()
mode
=
mode
.
lower
()
if
mode
not
in
[
"bilinear"
,
"linear"
]:
if
mode
not
in
[
"bilinear"
,
"linear"
,
"bicubic"
,
"nearest"
]:
raise
ValueError
(
"
interpolate only support linear or bilinear mode"
)
raise
ValueError
(
"
unsupported interpolate mode: {}"
.
format
(
mode
)
)
if
mode
not
in
[
"bilinear"
,
"linear"
]:
if
mode
not
in
[
"bilinear"
,
"linear"
]:
if
align_corners
is
not
None
:
if
align_corners
is
not
None
:
raise
ValueError
(
raise
ValueError
(
...
@@ -625,9 +625,21 @@ def interpolate(
...
@@ -625,9 +625,21 @@ def interpolate(
weight
=
broadcast_to
(
weight
,
(
inp
.
shape
[
0
],
3
,
3
))
weight
=
broadcast_to
(
weight
,
(
inp
.
shape
[
0
],
3
,
3
))
weight
=
weight
.
astype
(
"float32"
)
weight
=
weight
.
astype
(
"float32"
)
ret
=
warp_perspective
(
inp
,
weight
,
dsize
,
interp_mode
=
"linear"
)
if
mode
in
[
"linear"
,
"bilinear"
]:
if
mode
==
"linear"
:
ret
=
warp_perspective
(
inp
,
weight
,
dsize
,
interp_mode
=
"linear"
)
ret
=
reshape
(
ret
,
ret
.
shape
[
0
:
3
])
if
mode
==
"linear"
:
ret
=
reshape
(
ret
,
ret
.
shape
[
0
:
3
])
else
:
# only NHWC format support "cubic" and "nearest" mode
inp
=
transpose
(
inp
,
(
0
,
2
,
3
,
1
))
ret
=
warp_perspective
(
inp
,
weight
,
dsize
,
format
=
"NHWC"
,
interp_mode
=
"cubic"
if
mode
==
"bicubic"
else
mode
,
)
ret
=
transpose
(
ret
,
(
0
,
3
,
1
,
2
))
return
ret
return
ret
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录