-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomActivation.py
More file actions
35 lines (30 loc) · 820 Bytes
/
CustomActivation.py
File metadata and controls
35 lines (30 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import torch
import torch.nn as nn
class Sigmoid(torch.nn.Module):
def __init__(self, a=1, max = 10):
super().__init__()
self.a = a
self.max = max
def forward(self, v):
sig = nn.Sigmoid()
act = sig(self.a*v)*self.max
return act
class TanH(torch.nn.Module):
def __init__(self, a=1, max = 10):
super().__init__()
self.a = a
self.max = max
def forward(self, v):
tanh = nn.Tanh()
act = tanh(self.a*(v))*self.max
return act
class MyCustom(torch.nn.Module):
def __init__(self, a=1, max = 10):
super().__init__()
self.sig = Sigmoid(a, max)
self.tan = TanH(100, 1)
def forward(self, v):
tan = self.tan(v)
sig = self.sig(v)
act = tan*sig
return act