MCPcopy
hub / github.com/tensorlayer/TensorLayer / dense_module

Function dense_module

tests/utils/custom_layers/basic_layers.py:100–134  ·  view source on GitHub ↗
(
    prev_layer, n_units, is_train, use_batchnorm=True, activation_fn=None, dense_init=tl.initializers.random_uniform(),
    batch_norm_init=tl.initializers.truncated_normal(mean=1., stddev=0.02), bias_init=tf.zeros_initializer(), name=None
)

Source from the content-addressed store, hash-verified

98
99
100def dense_module(
101 prev_layer, n_units, is_train, use_batchnorm=True, activation_fn=None, dense_init=tl.initializers.random_uniform(),
102 batch_norm_init=tl.initializers.truncated_normal(mean=1., stddev=0.02), bias_init=tf.zeros_initializer(), name=None
103):
104
105 if activation_fn not in ["ReLU", "ReLU6", "Leaky_ReLU", "PReLU", "PReLU6", "PTReLU6", "CReLU", "ELU", "SELU",
106 "tanh", "sigmoid", "softmax", None]:
107 raise Exception("Unknown 'activation_fn': %s" % activation_fn)
108
109 # Flatten: Conv to FC
110 if prev_layer.outputs.get_shape().__len__() != 2: # The input dimension must be rank 2
111 layer = tl.layers.FlattenLayer(prev_layer, name='flatten')
112
113 else:
114 layer = prev_layer
115
116 layer = tl.layers.DenseLayer(
117 layer,
118 n_units=n_units,
119 act=None,
120 W_init=dense_init,
121 b_init=None if use_batchnorm else bias_init, # Not useful as the convolutions are batch normalized
122 name='dense' if name is None else name
123 )
124
125 if use_batchnorm:
126 layer = tl.layers.BatchNormLayer(
127 layer, act=None, is_train=is_train, gamma_init=batch_norm_init, name='batch_norm'
128 )
129
130 logits = layer.outputs
131
132 layer = activation_module(layer, activation_fn)
133
134 return layer, logits

Callers 1

__call__Method · 0.90

Calls 2

activation_moduleFunction · 0.85
__len__Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…