Belle II Software light-2406-ragdoll
Layer Class Reference
Inheritance diagram for Layer:
Collaboration diagram for Layer:

Public Member Functions

def __init__ (self, name, tf_activation_str, dim_input, dim_output, p_bias, p_w, random_seed=None)
 
def __call__ (self, x)
 
def variable_to_summary (self, var, step, writer)
 
def all_to_summary (self, step, writer)
 

Public Attributes

 tf_activation
 layer parameters
 
 shape
 layer shape
 
 w
 init parameters for uniform distribution
 
 b
 init parameters for bias
 
 input
 input
 
 output
 output
 

Protected Member Functions

def _init_bias (self, width, init_val, name=None)
 
def _init_weight (self, shape, stddev, operation_seed, name=None)
 

Detailed Description

definition of a layer obj

Definition at line 21 of file tensorflow_dnn_model.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  name,
  tf_activation_str,
  dim_input,
  dim_output,
  p_bias,
  p_w,
  random_seed = None 
)
:param name: name of the layer.
:param tf_activation: string, name of an available tensorflow activations function
:param dim_input: dimension of the input
:param dim_output: dimension of the output
:param p_bias: initial bias
:param p_w: stddev of uniform distribution to initialize
:param random_seed: random seed used in initialising the weights
:return: None

Definition at line 26 of file tensorflow_dnn_model.py.

27 random_seed=None):
28 """
29 :param name: name of the layer.
30 :param tf_activation: string, name of an available tensorflow activations function
31 :param dim_input: dimension of the input
32 :param dim_output: dimension of the output
33 :param p_bias: initial bias
34 :param p_w: stddev of uniform distribution to initialize
35 :param random_seed: random seed used in initialising the weights
36 :return: None
37 """
38
39 super().__init__(name=name)
40
41 tf_activation_dict = {
42 'tanh': tf.nn.tanh,
43 'sigmoid': tf.nn.sigmoid,
44 'relu': tf.nn.relu,
45 'leaky_relu': tf.nn.leaky_relu,
46 }
47
48 if tf_activation_str not in tf_activation_dict:
49 raise ValueError
50
51
52 self.tf_activation = tf_activation_dict[tf_activation_str]
53
54
55 self.shape = [dim_input, dim_output]
56
57
58 self.w = self._init_weight(self.shape, p_w, random_seed)
59
60
61 self.b = self._init_bias(self.shape[1], p_bias)
62
63
64 self.input = None
65
66
67 self.output = None
68

Member Function Documentation

◆ __call__()

def __call__ (   self,
  x 
)
evaluate the layer

Definition at line 88 of file tensorflow_dnn_model.py.

88 def __call__(self, x):
89 """
90 evaluate the layer
91 """
92 return self.tf_activation(tf.matmul(x, self.w) + self.b)
93

◆ _init_bias()

def _init_bias (   self,
  width,
  init_val,
  name = None 
)
protected
define bias variables

Definition at line 69 of file tensorflow_dnn_model.py.

69 def _init_bias(self, width, init_val, name=None):
70 """
71 define bias variables
72 """
73 if name is None:
74 name = self.name + '_b'
75 initial = tf.constant(init_val, shape=[width], name=name)
76 return tf.Variable(initial, name=name, trainable=True)
77

◆ _init_weight()

def _init_weight (   self,
  shape,
  stddev,
  operation_seed,
  name = None 
)
protected
define weight variables

Definition at line 78 of file tensorflow_dnn_model.py.

78 def _init_weight(self, shape, stddev, operation_seed, name=None):
79 """
80 define weight variables
81 """
82 if name is None:
83 name = self.name + '_w'
84 initial = tf.random.truncated_normal(shape, stddev=stddev, seed=operation_seed, name=name)
85 return tf.Variable(initial, name=name, trainable=True)
86

◆ all_to_summary()

def all_to_summary (   self,
  step,
  writer 
)
Passes all layer variables to the tf.summary writer.

Definition at line 109 of file tensorflow_dnn_model.py.

109 def all_to_summary(self, step, writer):
110 """
111 Passes all layer variables to the tf.summary writer.
112 """
113 self.variable_to_summary(self.w, step=step, writer=writer)
114 self.variable_to_summary(self.b, step=step, writer=writer)
115 return
116
117

◆ variable_to_summary()

def variable_to_summary (   self,
  var,
  step,
  writer 
)
Passes information about each variable to the summary writer.

Definition at line 94 of file tensorflow_dnn_model.py.

94 def variable_to_summary(self, var, step, writer):
95 """
96 Passes information about each variable to the summary writer.
97 """
98 with writer.as_default():
99 mean = tf.reduce_mean(var)
100 stddev = tf.sqrt(tf.reduce_mean(tf.square(var - mean)))
101 tf.summary.scalar(f'{var.name}_mean', mean, step=step)
102 tf.summary.scalar(f'{var.name}_stddev', stddev, step=step)
103 tf.summary.scalar(f'{var.name}_max', tf.reduce_max(var), step=step)
104 tf.summary.scalar(f'{var.name}_min', tf.reduce_min(var), step=step)
105 tf.summary.histogram(f'{var.name}_histogram', var, step=step)
106 writer.flush()
107 return
108

Member Data Documentation

◆ b

b

init parameters for bias

Definition at line 61 of file tensorflow_dnn_model.py.

◆ input

input

input

Definition at line 64 of file tensorflow_dnn_model.py.

◆ output

output

output

Definition at line 67 of file tensorflow_dnn_model.py.

◆ shape

shape

layer shape

Definition at line 55 of file tensorflow_dnn_model.py.

◆ tf_activation

tf_activation

layer parameters

activation function

Definition at line 52 of file tensorflow_dnn_model.py.

◆ w

w

init parameters for uniform distribution

Definition at line 58 of file tensorflow_dnn_model.py.


The documentation for this class was generated from the following file: