Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
ac86d644
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
412
Star
4707
Fork
583
代码
文件
提交
分支
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看板
提交
ac86d644
编写于
10月 28, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mge/module): fix prelu error when use_symbolic_shape is true
GitOrigin-RevId: 25b9c4d41d0584922eaaf657b0b2d3c2d515b6e8
上级
4f6c5d8f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
7 deletion
+19
-7
imperative/python/megengine/module/activation.py
imperative/python/megengine/module/activation.py
+0
-6
imperative/python/test/unit/module/test_activation.py
imperative/python/test/unit/module/test_activation.py
+19
-1
未找到文件。
imperative/python/megengine/module/activation.py
浏览文件 @
ac86d644
...
@@ -239,12 +239,6 @@ class PReLU(Module):
...
@@ -239,12 +239,6 @@ class PReLU(Module):
self
.
weight
=
Parameter
(
data
=
[
init
])
self
.
weight
=
Parameter
(
data
=
[
init
])
def
forward
(
self
,
inputs
):
def
forward
(
self
,
inputs
):
assert
self
.
weight
.
shape
==
(
1
,)
or
self
.
weight
.
shape
==
(
1
,
int
(
inputs
.
shape
[
1
]),
1
,
1
,
),
"invalid weight's shape"
return
prelu
(
inputs
,
self
.
weight
)
return
prelu
(
inputs
,
self
.
weight
)
...
...
imperative/python/test/unit/module/test_activation.py
浏览文件 @
ac86d644
...
@@ -7,9 +7,11 @@
...
@@ -7,9 +7,11 @@
# software distributed under the License is distributed on an
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import
numpy
as
np
import
numpy
as
np
import
pytest
import
megengine
as
mge
import
megengine
as
mge
from
megengine.module
import
LeakyReLU
from
megengine.jit.tracing
import
set_symbolic_shape
from
megengine.module
import
LeakyReLU
,
PReLU
def
test_leaky_relu
():
def
test_leaky_relu
():
...
@@ -21,3 +23,19 @@ def test_leaky_relu():
...
@@ -21,3 +23,19 @@ def test_leaky_relu():
np_output
=
np
.
maximum
(
0
,
data
)
+
negative_slope
*
np
.
minimum
(
0
,
data
)
np_output
=
np
.
maximum
(
0
,
data
)
+
negative_slope
*
np
.
minimum
(
0
,
data
)
np
.
testing
.
assert_equal
(
output
.
numpy
(),
np_output
)
np
.
testing
.
assert_equal
(
output
.
numpy
(),
np_output
)
@
pytest
.
mark
.
parametrize
(
"shape"
,
[(
1
,
64
,
15
,
15
),
(
64
,)])
@
pytest
.
mark
.
parametrize
(
"use_symbolic"
,
[
False
,
True
])
def
test_prelu
(
shape
,
use_symbolic
):
old_flag
=
set_symbolic_shape
(
use_symbolic
)
data
=
np
.
random
.
random
(
size
=
shape
)
num_channel
=
1
if
len
(
shape
)
==
1
else
shape
[
1
]
prelu
=
PReLU
(
num_parameters
=
num_channel
,
init
=
0.25
)
output
=
prelu
(
mge
.
Tensor
(
data
))
np_output
=
np
.
maximum
(
data
,
0
)
+
prelu
.
weight
.
numpy
()
*
np
.
minimum
(
data
,
0
)
set_symbolic_shape
(
old_flag
)
np
.
testing
.
assert_allclose
(
output
.
numpy
(),
np_output
,
atol
=
1e-5
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录