添加upsamper参数描述
message UpsampleParameter{
optional int32 scale = 1 [default = 1];
}
message LayerParameter{
...
optional UpsampleParameter upsample_param = 149; //序号不冲突即可
}
https://github.com/SeanQ88/caffe_upsample
假设输入为2x2, scale=2.0;则输出则为4x4
1 | 2 |
3 | 4 |
1 | 1 | 2 | 2 |
1 | 1 | 2 | 2 |
3 | 3 | 4 | 4 |
3 | 3 | 4 | 4 |
用目的坐标映射到原坐标
int N = 1, C =1, H = 4, H = 4;
for (int n = 0; n
由于bottom_diff是NCHW=(1,1,2,2), top_diff(1,1,4,4)
并且scale是常数,不参数梯度,即可认为是f = x,导数为f’=1
从整个表达来说f = scale * x,top_diff * scale 应该也是可以的,然后再做如下运算,传递梯度到下一层。如有理解误的,望指正。
for (int n = 0; n < N; n++) {
for (int c = 0; c < C; c++) {
for (int h = 0; h < H; h++) {
for (int w = 0; w < W; w++) {
for (int i = 0; i < scale_; i++) {
for (int j = 0; j < scale_; j++) {
int nw = w * scale_ + i;
int nh = h * scale_ + j;
int out_idx = (((n * C + c) * H) + h) * W + w;
int in_idx = (((n * C + c) * (H * scale_))
+ nh) * (W * scale_) + nw;
bottom_diff[out_idx] += top_diff[in_idx];
}
}
}
}
}
}