Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
19466046
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
403
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看板
提交
19466046
编写于
1月 21, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(mge/funcitonal): add cvt_color opr python interface
GitOrigin-RevId: 29e069fb2334a20545021f37a7133f7bfdbafd0b
上级
412d1f0c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
97 addition
and
0 deletion
+97
-0
imperative/python/megengine/functional/__init__.py
imperative/python/megengine/functional/__init__.py
+1
-0
imperative/python/megengine/functional/img_proc.py
imperative/python/megengine/functional/img_proc.py
+50
-0
imperative/python/test/unit/functional/test_functional.py
imperative/python/test/unit/functional/test_functional.py
+11
-0
imperative/src/impl/ops/img_proc.cpp
imperative/src/impl/ops/img_proc.cpp
+33
-0
src/core/include/megbrain/ir/ops.td
src/core/include/megbrain/ir/ops.td
+2
-0
未找到文件。
imperative/python/megengine/functional/__init__.py
浏览文件 @
19466046
...
...
@@ -8,6 +8,7 @@
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# pylint: disable=redefined-builtin
from
.elemwise
import
*
from
.img_proc
import
*
from
.math
import
*
from
.nn
import
*
from
.tensor
import
*
...
...
imperative/python/megengine/functional/img_proc.py
0 → 100644
浏览文件 @
19466046
# -*- coding: utf-8 -*-
# MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
#
# Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
from
..core._imperative_rt.core2
import
apply
from
..core.ops
import
builtin
from
..tensor
import
Tensor
__all__
=
[
"cvt_color"
,
]
def
cvt_color
(
inp
:
Tensor
,
mode
:
str
=
""
):
r
"""
Convert images from one format to another
:param inp: input images.
:param mode: format mode.
:return: convert result.
Examples:
.. testcode::
import numpy as np
import megengine as mge
import megengine.functional as F
x = mge.tensor(np.array([[[[-0.58675045, 1.7526233, 0.10702174]]]]).astype(np.float32))
y = F.img_proc.cvt_color(x, mode="RGB2GRAY")
print(y.numpy())
Outputs:
.. testoutput::
[[[[0.86555195]]]]
"""
assert
mode
in
builtin
.
CvtColor
.
Mode
.
__dict__
,
"unspport mode for cvt_color"
mode
=
getattr
(
builtin
.
CvtColor
.
Mode
,
mode
)
assert
isinstance
(
mode
,
builtin
.
CvtColor
.
Mode
)
op
=
builtin
.
CvtColor
(
mode
=
mode
)
(
out
,)
=
apply
(
op
,
inp
)
return
out
imperative/python/test/unit/functional/test_functional.py
浏览文件 @
19466046
...
...
@@ -704,3 +704,14 @@ def test_argmxx_on_inf():
assert
all
(
run_argmax
()
>=
0
)
assert
all
(
run_argmin
()
>=
0
)
def
test_cvt_color
():
def
rgb2gray
(
rgb
):
return
np
.
dot
(
rgb
[...,
:
3
],
[
0.299
,
0.587
,
0.114
])
inp
=
np
.
random
.
randn
(
3
,
3
,
3
,
3
).
astype
(
np
.
float32
)
out
=
np
.
expand_dims
(
rgb2gray
(
inp
),
3
).
astype
(
np
.
float32
)
x
=
tensor
(
inp
)
y
=
F
.
img_proc
.
cvt_color
(
x
,
mode
=
"RGB2GRAY"
)
np
.
testing
.
assert_allclose
(
y
.
numpy
(),
out
,
atol
=
1e-5
)
imperative/src/impl/ops/img_proc.cpp
0 → 100644
浏览文件 @
19466046
/**
* \file imperative/src/impl/ops/img_proc.cpp
* MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
*
* Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
#include "megbrain/imperative/ops/autogen.h"
#include "megbrain/opr/imgproc.h"
#include "../op_trait.h"
namespace
mgb
{
namespace
imperative
{
namespace
{
auto
apply_on_var_node
(
const
OpDef
&
def
,
const
VarNodeArray
&
inputs
)
{
auto
&&
op
=
static_cast
<
const
CvtColor
&>
(
def
);
mgb_assert
(
inputs
.
size
()
==
1
);
return
opr
::
CvtColor
::
make
(
inputs
[
0
],
op
.
param
());
}
OP_TRAIT_REG
(
CvtColor
,
CvtColor
)
.
apply_on_var_node
(
apply_on_var_node
)
.
fallback
();
}
}
}
\ No newline at end of file
src/core/include/megbrain/ir/ops.td
浏览文件 @
19466046
...
...
@@ -254,4 +254,6 @@ def TensorRTRuntime: MgbHashableOp<"TensorRTRuntime"> {
);
}
def CvtColor: MgbHashableOp<"CvtColor", [CvtColorParam]>;
#endif // MGB_OPS
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录