提交 dd962a47 编写于 作者: M Megvii Engine Team 提交者: Xinran Xu

fix(mge/module): add negative slope attribute for LeakyReLU module

GitOrigin-RevId: 67e1967b56e63d227c0fe080619d89195d0df35b
上级 64401dfe
......@@ -223,5 +223,9 @@ class LeakyReLU(Module):
"""
def __init__(self, negative_slope: float = 0.01):
super().__init__()
self.negative_slope = negative_slope
def forward(self, inputs):
return leaky_relu(inputs)
return leaky_relu(inputs, self.negative_slope)
# -*- coding: utf-8 -*-
# MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
#
# Copyright (c) 2014-2020 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.
import numpy as np
import megengine as mge
from megengine.module import LeakyReLU
from megengine.test import assertTensorClose
def test_leaky_relu():
data = np.array([-8, -12, 6, 10]).astype(np.float32)
negative_slope = 0.1
leaky_relu = LeakyReLU(negative_slope)
output = leaky_relu(mge.tensor(data))
np_output = np.maximum(0, data) + negative_slope * np.minimum(0, data)
assertTensorClose(output.numpy(), np_output, max_err=0)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册