FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Caffe-HRT/unit_tests/test_softmax_layer.cpp at master · OAID/Caffe-HRT · GitHub
OAID
Caffe-HRT
Repository navigation
Code
Issues
20
(20)
Pull requests
4
(4)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Caffe-HRT
/
unit_tests
/
test_softmax_layer.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
99 lines (75 loc) · 2.82 KB
Breadcrumbs
Caffe-HRT
/
unit_tests
/
test_softmax_layer.cpp
Copy path
File metadata and controls
99 lines (75 loc) · 2.82 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#
include
<
cmath
>
#
include
<
vector
>
#
include
"
gtest/gtest.h
"
#
include
"
caffe/blob.hpp
"
#
include
"
caffe/common.hpp
"
#
include
"
caffe/filler.hpp
"
#
include
"
caffe/layers/softmax_layer.hpp
"
#
ifdef
USE_CUDNN
#
include
"
caffe/layers/cudnn_softmax_layer.hpp
"
#
endif
#
include
"
caffe/test/test_caffe_main.hpp
"
#
include
"
caffe/test/test_gradient_check_util.hpp
"
namespace
caffe
{
template
<
typename
TypeParam>
class
SoftmaxLayerTest
:
public
MultiDeviceTest
<TypeParam> {
typedef
typename
TypeParam::Dtype Dtype;
protected:
SoftmaxLayerTest
()
: blob_bottom_(
new
Blob<Dtype>(
2
,
10
,
1
,
1
)),
blob_top_
(
new
Blob<Dtype>()) {
//
fill the values
FillerParameter filler_param;
GaussianFiller<Dtype>
filler
(filler_param);
filler.
Fill
(
this
->
blob_bottom_
);
blob_bottom_vec_.
push_back
(blob_bottom_);
blob_top_vec_.
push_back
(blob_top_);
}
virtual
~SoftmaxLayerTest
() {
delete
blob_bottom_;
delete
blob_top_; }
Blob<Dtype>*
const
blob_bottom_;
Blob<Dtype>*
const
blob_top_;
vector<Blob<Dtype>*> blob_bottom_vec_;
vector<Blob<Dtype>*> blob_top_vec_;
};
typedef
::testing::Types<CPUDevice<
float
> > float_only;
#
define
TestDtypesAndDevices
float_only
TYPED_TEST_CASE
(SoftmaxLayerTest, TestDtypesAndDevices);
TYPED_TEST
(SoftmaxLayerTest, TestForward) {
typedef
typename
TypeParam::Dtype Dtype;
LayerParameter layer_param;
layer_param.
set_type
(
"
Softmax
"
);
shared_ptr<Layer<Dtype> > new_layer=
LayerRegistry<Dtype>::
CreateLayer
(layer_param);
shared_ptr<SoftmaxLayer<Dtype> > layer=
boost::static_pointer_cast<SoftmaxLayer<Dtype> > (new_layer);
//
layer=shared_ptr<SoftmaxLayer<Dtype> >(new SoftmaxLayer<Dtype>(layer_param));
layer->
SetUp
(
this
->
blob_bottom_vec_
,
this
->
blob_top_vec_
);
layer->
Forward
(
this
->
blob_bottom_vec_
,
this
->
blob_top_vec_
);
//
Test sum
for
(
int
i =
0
; i <
this
->
blob_bottom_
->
num
(); ++i) {
for
(
int
k =
0
; k <
this
->
blob_bottom_
->
height
(); ++k) {
for
(
int
l =
0
; l <
this
->
blob_bottom_
->
width
(); ++l) {
Dtype sum =
0
;
for
(
int
j =
0
; j <
this
->
blob_top_
->
channels
(); ++j) {
sum +=
this
->
blob_top_
->
data_at
(i, j, k, l);
}
EXPECT_GE
(sum,
0.999
);
EXPECT_LE
(sum,
1.001
);
//
Test exact values
Dtype scale =
0
;
for
(
int
j =
0
; j <
this
->
blob_bottom_
->
channels
(); ++j) {
scale +=
exp
(
this
->
blob_bottom_
->
data_at
(i, j, k, l));
}
for
(
int
j =
0
; j <
this
->
blob_bottom_
->
channels
(); ++j) {
EXPECT_GE
(
this
->
blob_top_
->
data_at
(i, j, k, l) +
1e-4
,
exp
(
this
->
blob_bottom_
->
data_at
(i, j, k, l)) / scale)
<<
"
debug:
"
<< i <<
"
"
<< j;
EXPECT_LE
(
this
->
blob_top_
->
data_at
(i, j, k, l) -
1e-4
,
exp
(
this
->
blob_bottom_
->
data_at
(i, j, k, l)) / scale)
<<
"
debug:
"
<< i <<
"
"
<< j;
}
}
}
}
}
}
//
namespace caffe
Back
|
FazBrowse Home
|
New Git URL