MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _initializer

Function _initializer

tensorflow/contrib/layers/python/layers/initializers.py:117–150  ·  view source on GitHub ↗

Initializer function.

(shape, dtype=dtype, partition_info=None)

Source from the content-addressed store, hash-verified

115
116 # pylint: disable=unused-argument
117 def _initializer(shape, dtype=dtype, partition_info=None):
118 """Initializer function."""
119 if not dtype.is_floating:
120 raise TypeError('Cannot create initializer for non-floating point type.')
121 # Estimating fan_in and fan_out is not possible to do perfectly, but we try.
122 # This is the right thing for matrix multiply and convolutions.
123 if shape:
124 fan_in = float(shape[-2]) if len(shape) > 1 else float(shape[-1])
125 fan_out = float(shape[-1])
126 else:
127 fan_in = 1.0
128 fan_out = 1.0
129 for dim in shape[:-2]:
130 fan_in *= float(dim)
131 fan_out *= float(dim)
132 if mode == 'FAN_IN':
133 # Count only number of input connections.
134 n = fan_in
135 elif mode == 'FAN_OUT':
136 # Count only number of output connections.
137 n = fan_out
138 elif mode == 'FAN_AVG':
139 # Average number of inputs and output connections.
140 n = (fan_in + fan_out) / 2.0
141 if uniform:
142 # To get stddev = math.sqrt(factor / n) need to adjust for uniform.
143 limit = math.sqrt(3.0 * factor / n)
144 return random_ops.random_uniform(shape, -limit, limit,
145 dtype, seed=seed)
146 else:
147 # To get stddev = math.sqrt(factor / n) need to adjust for truncated.
148 trunc_stddev = math.sqrt(1.3 * factor / n)
149 return random_ops.truncated_normal(shape, 0.0, trunc_stddev, dtype,
150 seed=seed)
151 # pylint: enable=unused-argument
152
153 return _initializer

Callers

nothing calls this directly

Calls 2

random_uniformMethod · 0.80
truncated_normalMethod · 0.45

Tested by

no test coverage detected