-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswish.cpp
52 lines (42 loc) · 997 Bytes
/
swish.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "swish.h"
#include "layer_register.h"
#include "utils.h"
#include <cmath>
Swish::Swish()
{
}
Swish::~Swish()
{
}
int Swish::load_model(const vector<string> ¶ms, FILE* fp)
{
return 0;
}
void Swish::forward(vector<Tensor*> &input, vector<Tensor*> &output)
{
Tensor* result;
if(output[0] == nullptr)
{
result = new Tensor();
}
else
{
result = output[0];
}
vector<float>* input0Data = input[0]->get_data();
vector<int> input0Shape = input[0]->get_shape();
result->set_shape(input0Shape);
vector<float>* outputData = result->get_data();
//#pragma omp parallel for
for(int i=0; i<input0Data->size(); i++)
{
outputData->data()[i] = input0Data->data()[i] * (1.0f / (1.0f + expf(-input0Data->data()[i])));
}
output[0] = result;
}
int Swish::CreateInstance(Layer* &layer)
{
layer = new Swish();
return 0;
}
LayerRegistererWrapper swishCreateInstance("Swish_t", Swish::CreateInstance);