-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathLeNet.cpp
More file actions
40 lines (33 loc) · 880 Bytes
/
Copy pathLeNet.cpp
File metadata and controls
40 lines (33 loc) · 880 Bytes
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
#include <algorithm>
#include "LeNet.h"
using namespace std;
LeNet::LeNet(string initNet,string predictNet)
:Caffe2Net(initNet,predictNet)
{
}
LeNet::~LeNet()
{
}
TensorCPU LeNet::preProcess(Mat img)
{
assert(img.channels() == 1);
assert(img.rows == 28);
assert(img.cols == 28);
vector<TIndex> dims({1, img.channels(), img.rows, img.cols});
vector<float> data(1 * 1 * 28 * 28);
img.convertTo(img, CV_32FC1, 1.0/256,0);
copy((float *)img.datastart, (float *)img.dataend,data.begin());
return TensorCPU(dims, data, NULL);
}
vector<float> LeNet::postProcess(TensorCPU output)
{
const float * probs = output.data<float>();
vector<TIndex> dims = output.dims();
//检查输出的dims是否正确
assert(2 == output.ndim());
assert(1 == dims[0]);
assert(10 == dims[1]);
vector<float> retVal(dims[1]);
copy(probs,probs+dims[1],retVal.begin());
return retVal;
}