-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxpoolinglayer.cpp
More file actions
66 lines (61 loc) · 2.35 KB
/
maxpoolinglayer.cpp
File metadata and controls
66 lines (61 loc) · 2.35 KB
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
#include "maxpoolinglayer.h"
MaxPoolingLayer::MaxPoolingLayer(TensorSize size, int scale):_maskOfMaximums(size)
{
_scale = scale;
mInputSize = size;
mOutputSize = TensorSize(size.width/scale, size.height/scale,size.depth);
}
TensorSize MaxPoolingLayer::getOutputSize(){
return mOutputSize;
}
TensorSize MaxPoolingLayer::getInputSize()
{
return mInputSize;
}
void MaxPoolingLayer::debug(QDebug &debug)
{
debug << "Maxpool (" << mInputSize.width << mInputSize.height << mInputSize.depth<<") -> ("
<< mOutputSize.width << mOutputSize.height << mOutputSize.depth << ")";
//debug << _filter;
}
Tensor MaxPoolingLayer::backward(Tensor &inputErrors, double learningSpeed){
//qDebug() << "Tensor MaxPoolingLayer::backward(...) started!";
Tensor result = Tensor(mInputSize);
for (int z = 0; z < mInputSize.depth; z++){
for (int y =0; y < mInputSize.height; y++){
for(int x = 0; x < mInputSize.width;x++){
result.set(x,y,z, inputErrors.get(x/_scale,y/_scale,z,QString("maxPool get error"))*
_maskOfMaximums.get(x,y,z,QString("maxPool get from mask")),QString("maxPool set value for output"));
}
}
}
//qDebug() << "Tensor MaxPoolingLayer::backward(...) completed succesfull!";
return result;
}
Tensor MaxPoolingLayer::forward(Tensor &inputTensor)
{
Tensor result = Tensor(mOutputSize);
for (int z = 0; z < mInputSize.depth; z++){
for(int y = 0; y < mInputSize.height; y+= _scale) {
for(int x = 0; x <mInputSize.width; x+= _scale){
double max = inputTensor.get(x,y,z,QString("get first maximun"));
int maxDX = 0;
int maxDY = 0;
for (int dY = 0; dY < _scale; dY++){
for (int dX = 0; dX < _scale; dX++){
_maskOfMaximums.set(x+dX, y+dY,z,0,QString("Mask set 0"));
if (inputTensor.get(x+dX,y+dY,z) > max){
max = inputTensor.get(x+dX,dY+y,z);
maxDY = dY;
maxDX = dX;
}
}
}
_maskOfMaximums.set(x+maxDX, y + maxDY, z,1, QString("Set max mask"));
result.set(x/2,y/2,z,max);
}
}
}
//qDebug() << *result;
return result;
}