-
Notifications
You must be signed in to change notification settings - Fork 0
/
reshape.cpp
68 lines (58 loc) · 1.43 KB
/
reshape.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "reshape.h"
#include "layer_register.h"
#include "utils.h"
#include "math.h"
Reshape::Reshape()
{
}
Reshape::~Reshape()
{
}
int Reshape::load_model(const vector<string> ¶ms, FILE* fp)
{
vector<string> dims_param = split(params[6], "=");
int dims = atoi(dims_param[1].c_str());
_dims.resize(dims);
for(int i=0; i<dims; i++)
{
vector<string> size_param = split(params[7+i], "=");
_dims[i] = atoi(size_param[1].c_str());
}
return 0;
}
void Reshape::forward(vector<Tensor*> &input, vector<Tensor*> &output)
{
Tensor* result;
if(output[0] == nullptr)
{
result = new Tensor();
}
else
{
result = output[0];
}
//TODO:进行更多形状检查
vector<int> inputShape = input[0]->get_shape();
vector<int> outputShape;
for(int i=0; i<_dims.size(); i++)
{
if(_dims[i] == -1)
{
outputShape.push_back(inputShape[i]);
}
else
{
outputShape.push_back(_dims[i]);
}
}
//result->set_shape(outputShape);
//memcpy(result->get_data()->data(), input[0]->get_data()->data(), input[0]->get_data()->size()*sizeof(float));
result->set_shape_data(outputShape, input[0]->get_data());
output[0] = result;
}
int Reshape::CreateInstance(Layer* &layer)
{
layer = new Reshape();
return 0;
}
LayerRegistererWrapper reshapeCreateInstance("Reshape_t", Reshape::CreateInstance);