-
Notifications
You must be signed in to change notification settings - Fork 2
/
relu_layer.h
39 lines (32 loc) · 987 Bytes
/
relu_layer.h
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
36
37
38
39
#pragma once
#include "layer.h"
#include "util.h"
namespace con {
class ReluLayer : public Layer {
public:
ReluLayer(const string &name, Layer *prev) :
Layer(name, prev->num, prev->width, prev->height, prev->depth, prev),
inputSize(prev->depth * prev->width * prev->height) {}
const int inputSize;
void forward() {
for (int n = 0; n < num; n++) {
for (int i = 0; i < inputSize; i++) {
output[n][i] = std::max<Real>(0, prev->output[n][i]);
}
}
}
void backProp(const vector<Vec> &nextErrors) {
clear(&errors);
for (int n = 0; n < num; n++) {
for (int i = 0; i < inputSize; i++) {
if (prev->output[n][i] < 0) {
errors[n][i] = 0;
} else {
errors[n][i] = nextErrors[n][i];
}
}
}
}
void applyUpdate(const Real &lr, const Real &momentum, const Real &decay) {}
};
}