mirror of
https://github.com/ultralytics/ultralytics.git
synced 2025-09-15 15:48:41 +08:00
New AGLU activation module (#14644)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
parent
c6db604fe1
commit
b7c90526c8
16
docs/en/reference/nn/modules/activation.md
Normal file
16
docs/en/reference/nn/modules/activation.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
description: Explore activation functions in Ultralytics, including the Unified activation function and other custom implementations for neural networks.
|
||||||
|
keywords: ultralytics, activation functions, neural networks, Unified activation, AGLU, SiLU, ReLU, PyTorch, deep learning, custom activations
|
||||||
|
---
|
||||||
|
|
||||||
|
# Reference for `ultralytics/nn/modules/activation.py`
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
|
||||||
|
This file is available at [https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn/modules/activation.py](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn/modules/activation.py). If you spot a problem please help fix it by [contributing](https://docs.ultralytics.com/help/contributing/) a [Pull Request](https://github.com/ultralytics/ultralytics/edit/main/ultralytics/nn/modules/activation.py) 🛠️. Thank you 🙏!
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
## ::: ultralytics.nn.modules.activation.AGLU
|
||||||
|
|
||||||
|
<br><br>
|
||||||
@ -12,6 +12,7 @@
|
|||||||
48149018+zhixuwei@users.noreply.github.com: zhixuwei
|
48149018+zhixuwei@users.noreply.github.com: zhixuwei
|
||||||
49699333+dependabot[bot]@users.noreply.github.com: dependabot
|
49699333+dependabot[bot]@users.noreply.github.com: dependabot
|
||||||
52826299+Chayanonjackal@users.noreply.github.com: Chayanonjackal
|
52826299+Chayanonjackal@users.noreply.github.com: Chayanonjackal
|
||||||
|
53246858+hasanghaffari93@users.noreply.github.com: hasanghaffari93
|
||||||
61612323+Laughing-q@users.noreply.github.com: Laughing-q
|
61612323+Laughing-q@users.noreply.github.com: Laughing-q
|
||||||
62214284+Burhan-Q@users.noreply.github.com: Burhan-Q
|
62214284+Burhan-Q@users.noreply.github.com: Burhan-Q
|
||||||
68285002+Kayzwer@users.noreply.github.com: Kayzwer
|
68285002+Kayzwer@users.noreply.github.com: Kayzwer
|
||||||
|
|||||||
@ -536,6 +536,7 @@ nav:
|
|||||||
- nn:
|
- nn:
|
||||||
- autobackend: reference/nn/autobackend.md
|
- autobackend: reference/nn/autobackend.md
|
||||||
- modules:
|
- modules:
|
||||||
|
- activation: reference/nn/modules/activation.md
|
||||||
- block: reference/nn/modules/block.md
|
- block: reference/nn/modules/block.md
|
||||||
- conv: reference/nn/modules/conv.md
|
- conv: reference/nn/modules/conv.md
|
||||||
- head: reference/nn/modules/head.md
|
- head: reference/nn/modules/head.md
|
||||||
|
|||||||
22
ultralytics/nn/modules/activation.py
Normal file
22
ultralytics/nn/modules/activation.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
||||||
|
"""Activation modules."""
|
||||||
|
|
||||||
|
import torch
|
||||||
|
import torch.nn as nn
|
||||||
|
|
||||||
|
|
||||||
|
class AGLU(nn.Module):
|
||||||
|
"""Unified activation function module from https://github.com/kostas1515/AGLU."""
|
||||||
|
|
||||||
|
def __init__(self, device=None, dtype=None) -> None:
|
||||||
|
"""Initialize the Unified activation function."""
|
||||||
|
super().__init__()
|
||||||
|
self.act = nn.Softplus(beta=-1.0)
|
||||||
|
self.lambd = nn.Parameter(nn.init.uniform_(torch.empty(1, device=device, dtype=dtype))) # lambda parameter
|
||||||
|
self.kappa = nn.Parameter(nn.init.uniform_(torch.empty(1, device=device, dtype=dtype))) # kappa parameter
|
||||||
|
|
||||||
|
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
||||||
|
"""Compute the forward pass of the Unified activation function."""
|
||||||
|
lam = torch.clamp(self.lambd, min=0.0001)
|
||||||
|
y = torch.exp((1 / lam) * self.act((self.kappa * x) - torch.log(lam)))
|
||||||
|
return y # for AGLU simply return y * input
|
||||||
Loading…
Reference in New Issue
Block a user