@@ -2,19 +2,19 @@ use blob::Blob;
2
2
use math:: * ;
3
3
4
4
pub struct Layer {
5
- top : Vec < Layer >
5
+ top : Vec < Layer > ,
6
6
}
7
7
8
8
fn sigmoid ( z : f32 ) -> f32 {
9
- return 1f32 / ( 1f32 + ( -z) . exp ( ) )
9
+ 1f32 / ( 1f32 + ( -z) . exp ( ) )
10
10
}
11
11
12
12
fn sigmoid_prime ( z : f32 ) -> f32 {
13
- return sigmoid_prime_precalc ( sigmoid ( z) )
13
+ sigmoid_prime_precalc ( sigmoid ( z) )
14
14
}
15
15
16
16
fn sigmoid_prime_precalc ( sigmoid_z : f32 ) -> f32 {
17
- return sigmoid_z * ( 1f32 - sigmoid_z)
17
+ sigmoid_z * ( 1f32 - sigmoid_z)
18
18
}
19
19
20
20
impl Layer {
@@ -38,11 +38,11 @@ impl Layer {
38
38
39
39
// Unlock();
40
40
41
- return loss
41
+ loss
42
42
}
43
43
44
44
// forward_cpu for sigmoid layer
45
- pub fn forward_cpu ( & self , bottom : & Vec < Box < Blob < f32 > > > , top : & mut Vec < Box < Blob < f32 > > > ) {
45
+ pub fn forward_cpu ( & self , bottom : & Vec < Box < Blob < f32 > > > , top : & mut Vec < Box < Blob < f32 > > > ) {
46
46
let bottom_data = bottom[ 0 ] . cpu_data ( ) ;
47
47
let top_data = top[ 0 ] . mutable_cpu_data ( ) ;
48
48
@@ -52,7 +52,10 @@ impl Layer {
52
52
}
53
53
54
54
// backward_cpu for sigmoid layer
55
- pub fn backward_cpu ( & self , top : & Vec < Box < Blob < f32 > > > , propagate_down : & Vec < bool > , bottom : & mut Vec < Box < Blob < f32 > > > ) {
55
+ pub fn backward_cpu ( & self ,
56
+ top : & Vec < Box < Blob < f32 > > > ,
57
+ propagate_down : & Vec < bool > ,
58
+ bottom : & mut Vec < Box < Blob < f32 > > > ) {
56
59
if propagate_down[ 0 ] {
57
60
let top_data = top[ 0 ] . cpu_data ( ) ;
58
61
let top_diff = top[ 0 ] . cpu_diff ( ) ;
@@ -66,6 +69,16 @@ impl Layer {
66
69
}
67
70
}
68
71
}
72
+
73
+ pub fn auto_top_blobs ( & self ) -> bool {
74
+ false
75
+ }
76
+ pub fn min_top_blobs ( & self ) -> usize {
77
+ 0
78
+ }
79
+ pub fn exact_num_top_blobs ( & self ) -> usize {
80
+ 0
81
+ }
69
82
}
70
83
71
84
pub struct LayerConfig {
@@ -75,10 +88,26 @@ pub struct LayerConfig {
75
88
bottoms : Vec < String > , // the name of each bottom blob; called bottom in Caffe
76
89
tops : Vec < String > , // the name of each top blob; called top in Caffe
77
90
78
- // minimal, a lot of Caffe not ported yet
91
+ // Specifies on which bottoms the backpropagation should be skipped.
92
+ // The size must be either 0 or equal to the number of bottoms.
93
+ propagate_down : Vec < bool > , // minimal, a lot of Caffe not ported yet
79
94
}
80
95
81
96
impl LayerConfig {
82
- pub fn top ( & self , top_id : usize ) -> Option < & String > { return self . tops . get ( top_id) ; }
83
- pub fn bottom ( & self , bottom_id : usize ) -> Option < & String > { return self . bottoms . get ( bottom_id) ; }
97
+ pub fn top ( & self , top_id : usize ) -> Option < & String > {
98
+ self . tops . get ( top_id)
99
+ }
100
+ pub fn tops_len ( & self ) -> usize {
101
+ self . tops . len ( )
102
+ }
103
+ pub fn bottom ( & self , bottom_id : usize ) -> Option < & String > {
104
+ self . bottoms . get ( bottom_id)
105
+ }
106
+ pub fn bottoms_len ( & self ) -> usize {
107
+ self . bottoms . len ( )
108
+ }
109
+
110
+ pub fn check_propagate_down_len ( & self ) -> bool {
111
+ self . propagate_down . len ( ) == 0 || self . propagate_down . len ( ) == self . bottoms . len ( )
112
+ }
84
113
}
0 commit comments