File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -48,5 +48,15 @@ namespace af
48
48
49
49
autograd::Variable forward (const autograd::Variable &input);
50
50
};
51
+
52
+ class PReLU : public Module
53
+ {
54
+ public:
55
+ PReLU (int size, double spread = 1.0 );
56
+ PReLU (const autograd::Variable &w);
57
+
58
+ autograd::Variable forward (const autograd::Variable &input);
59
+ };
60
+
51
61
}
52
62
}
Original file line number Diff line number Diff line change 9
9
10
10
#include < af/autograd/Functions.hpp>
11
11
#include < af/nn/Modules/Activations.hpp>
12
-
12
+ # include < af/nn/Types.hpp >
13
13
namespace af
14
14
{
15
15
namespace nn
@@ -46,5 +46,26 @@ namespace af
46
46
{
47
47
return max (input, m_slope * input);
48
48
}
49
+
50
+ PReLU::PReLU (int size, double spread)
51
+ {
52
+ auto w = nn::weight (size, 1 , spread);
53
+ setParams ({w});
54
+ }
55
+
56
+ PReLU::PReLU (const Variable &w) :
57
+ Module ({w})
58
+ {
59
+ }
60
+
61
+ Variable PReLU::forward (const Variable &input)
62
+ {
63
+ auto tmp = max (input, 0.0 );
64
+ auto res = expandAs (m_parameters[0 ],tmp) * tmp;
65
+ // TODO: Determine if doing the max after the mul is preferable
66
+ return res;
67
+
68
+ }
69
+
49
70
}
50
71
}
You can’t perform that action at this time.
0 commit comments