FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
CaffeOnACL/src/caffe/layers/deconv_layer.cpp at master · 2php/CaffeOnACL · GitHub
2php
CaffeOnACL
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
CaffeOnACL
/
src
/
caffe
/
layers
/
deconv_layer.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
84 lines (76 loc) · 3.07 KB
Breadcrumbs
CaffeOnACL
/
src
/
caffe
/
layers
/
deconv_layer.cpp
Copy path
File metadata and controls
84 lines (76 loc) · 3.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#
include
<
vector
>
#
include
"
caffe/layers/deconv_layer.hpp
"
namespace
caffe
{
template
<
typename
Dtype>
void
DeconvolutionLayer<Dtype>::compute_output_shape() {
const
int
* kernel_shape_data =
this
->
kernel_shape_
.
cpu_data
();
const
int
* stride_data =
this
->
stride_
.
cpu_data
();
const
int
* pad_data =
this
->
pad_
.
cpu_data
();
const
int
* dilation_data =
this
->
dilation_
.
cpu_data
();
this
->
output_shape_
.
clear
();
for
(
int
i =
0
; i <
this
->
num_spatial_axes_
; ++i) {
//
i + 1 to skip channel axis
const
int
input_dim =
this
->
input_shape
(i +
1
);
const
int
kernel_extent = dilation_data[i] * (kernel_shape_data[i] -
1
) +
1
;
const
int
output_dim = stride_data[i] * (input_dim -
1
)
+ kernel_extent -
2
* pad_data[i];
this
->
output_shape_
.
push_back
(output_dim);
}
}
template
<
typename
Dtype>
void
DeconvolutionLayer<Dtype>::Forward_cpu(
const
vector<Blob<Dtype>*>& bottom,
const
vector<Blob<Dtype>*>& top) {
const
Dtype* weight =
this
->
blobs_
[
0
]->
cpu_data
();
for
(
int
i =
0
; i < bottom.
size
(); ++i) {
const
Dtype* bottom_data = bottom[i]->
cpu_data
();
Dtype* top_data = top[i]->
mutable_cpu_data
();
for
(
int
n =
0
; n <
this
->
num_
; ++n) {
this
->
backward_cpu_gemm
(bottom_data + n *
this
->
bottom_dim_
, weight,
top_data + n *
this
->
top_dim_
);
if
(
this
->
bias_term_
) {
const
Dtype* bias =
this
->
blobs_
[
1
]->
cpu_data
();
this
->
forward_cpu_bias
(top_data + n *
this
->
top_dim_
, bias);
}
}
}
}
template
<
typename
Dtype>
void
DeconvolutionLayer<Dtype>::Backward_cpu(
const
vector<Blob<Dtype>*>& top,
const
vector<
bool
>& propagate_down,
const
vector<Blob<Dtype>*>& bottom) {
const
Dtype* weight =
this
->
blobs_
[
0
]->
cpu_data
();
Dtype* weight_diff =
this
->
blobs_
[
0
]->
mutable_cpu_diff
();
for
(
int
i =
0
; i < top.
size
(); ++i) {
const
Dtype* top_diff = top[i]->
cpu_diff
();
const
Dtype* bottom_data = bottom[i]->
cpu_data
();
Dtype* bottom_diff = bottom[i]->
mutable_cpu_diff
();
//
Bias gradient, if necessary.
if
(
this
->
bias_term_
&&
this
->
param_propagate_down_
[
1
]) {
Dtype* bias_diff =
this
->
blobs_
[
1
]->
mutable_cpu_diff
();
for
(
int
n =
0
; n <
this
->
num_
; ++n) {
this
->
backward_cpu_bias
(bias_diff, top_diff + n *
this
->
top_dim_
);
}
}
if
(
this
->
param_propagate_down_
[
0
] || propagate_down[i]) {
for
(
int
n =
0
; n <
this
->
num_
; ++n) {
//
Gradient w.r.t. weight. Note that we will accumulate diffs.
if
(
this
->
param_propagate_down_
[
0
]) {
this
->
weight_cpu_gemm
(top_diff + n *
this
->
top_dim_
,
bottom_data + n *
this
->
bottom_dim_
, weight_diff);
}
//
Gradient w.r.t. bottom data, if necessary, reusing the column buffer
//
we might have just computed above.
if
(propagate_down[i]) {
this
->
forward_cpu_gemm
(top_diff + n *
this
->
top_dim_
, weight,
bottom_diff + n *
this
->
bottom_dim_
,
this
->
param_propagate_down_
[
0
]);
}
}
}
}
}
#
ifdef
CPU_ONLY
STUB_GPU
(DeconvolutionLayer);
#
endif
INSTANTIATE_CLASS
(DeconvolutionLayer);
REGISTER_LAYER_CLASS
(Deconvolution);
}
//
namespace caffe
Back
|
FazBrowse Home
|
New Git URL