本文整理汇总了Python中keras.initializers._compute_fans方法的典型用法代码示例。如果您正苦于以下问题:Python initializers._compute_fans方法的具体用法?Python initializers._compute_fans怎么用?Python initializers._compute_fans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras.initializers
的用法示例。
在下文中一共展示了initializers._compute_fans方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import _compute_fans [as 别名]
def __call__(self, shape, dtype=None):
if self.nb_filters is not None:
kernel_shape = tuple(self.kernel_size) + (int(self.input_dim), self.nb_filters)
else:
kernel_shape = (int(self.input_dim), self.kernel_size[-1])
fan_in, fan_out = initializers._compute_fans(
tuple(self.kernel_size) + (self.input_dim, self.nb_filters)
)
if self.criterion == 'glorot':
s = 1. / (fan_in + fan_out)
elif self.criterion == 'he':
s = 1. / fan_in
else:
raise ValueError('Invalid criterion: ' + self.criterion)
rng = RandomState(self.seed)
modulus = rng.rayleigh(scale=s, size=kernel_shape)
phase = rng.uniform(low=-np.pi, high=np.pi, size=kernel_shape)
weight_real = modulus * np.cos(phase)
weight_imag = modulus * np.sin(phase)
weight = np.concatenate([weight_real, weight_imag], axis=-1)
return weight
示例2: test_lecun_uniform
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import _compute_fans [as 别名]
def test_lecun_uniform(tensor_shape):
fan_in, _ = initializers._compute_fans(tensor_shape)
scale = np.sqrt(3. / fan_in)
_runner(initializers.lecun_uniform(), tensor_shape,
target_mean=0., target_max=scale, target_min=-scale)
示例3: test_glorot_uniform
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import _compute_fans [as 别名]
def test_glorot_uniform(tensor_shape):
fan_in, fan_out = initializers._compute_fans(tensor_shape)
scale = np.sqrt(6. / (fan_in + fan_out))
_runner(initializers.glorot_uniform(), tensor_shape,
target_mean=0., target_max=scale, target_min=-scale)
示例4: test_he_uniform
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import _compute_fans [as 别名]
def test_he_uniform(tensor_shape):
fan_in, _ = initializers._compute_fans(tensor_shape)
scale = np.sqrt(6. / fan_in)
_runner(initializers.he_uniform(), tensor_shape,
target_mean=0., target_max=scale, target_min=-scale)
示例5: test_glorot_normal
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import _compute_fans [as 别名]
def test_glorot_normal(tensor_shape):
fan_in, fan_out = initializers._compute_fans(tensor_shape)
scale = np.sqrt(2. / (fan_in + fan_out))
_runner(initializers.glorot_normal(), tensor_shape,
target_mean=0., target_std=None, target_max=2 * scale)
示例6: test_he_normal
# 需要导入模块: from keras import initializers [as 别名]
# 或者: from keras.initializers import _compute_fans [as 别名]
def test_he_normal(tensor_shape):
fan_in, _ = initializers._compute_fans(tensor_shape)
scale = np.sqrt(2. / fan_in)
_runner(initializers.he_normal(), tensor_shape,
target_mean=0., target_std=None, target_max=2 * scale)