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
4848
4949 autograd::Variable forward (const autograd::Variable &input);
5050 };
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+
5161 }
5262}
Original file line number Diff line number Diff line change 99
1010#include < af/autograd/Functions.hpp>
1111#include < af/nn/Modules/Activations.hpp>
12-
12+ # include < af/nn/Types.hpp >
1313namespace af
1414{
1515 namespace nn
@@ -46,5 +46,26 @@ namespace af
4646 {
4747 return max (input, m_slope * input);
4848 }
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+
4970 }
5071}
You can’t perform that action at this time.
0 commit comments