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
use arrayfire::*;
use crate::errors::Error;
use crate::regularizers::*;
use crate::tensor::*;
pub use self::batch_normalization::BatchNorm;
pub use self::conv2d::Conv2D;
pub use self::conv2d::Padding;
pub use self::dense::Dense;
pub use self::dropout::Dropout;
pub use self::flatten::Flatten;
pub use self::max_pooling::MaxPool2D;
mod batch_normalization;
mod conv2d;
mod dense;
mod dropout;
mod flatten;
mod max_pooling;
pub trait Layer: std::fmt::Display {
fn name(&self) -> &str;
fn initialize_parameters(&mut self, input_shape: Dim4);
fn compute_activation(&self, input: &Tensor) -> Tensor;
fn compute_activation_mut(&mut self, input: &Tensor) -> Tensor;
fn compute_dactivation_mut(&mut self, input: &Tensor) -> Tensor;
fn output_shape(&self) -> Dim;
fn parameters(&self) -> Option<Vec<&Tensor>> { None }
fn parameters_mut(&mut self) -> Option<(Vec<&mut Tensor>, Vec<&Tensor>)> { None }
fn save(&self, group: &hdf5::Group, layer_number: usize) -> Result<(), Error>;
fn set_regularizer(&mut self, _regularizer: Option<Regularizer>) {}
fn print(&self) {}
}