本文整理汇总了Python中tensorflow.contrib.layers.l1_regularizer方法的典型用法代码示例。如果您正苦于以下问题:Python layers.l1_regularizer方法的具体用法?Python layers.l1_regularizer怎么用?Python layers.l1_regularizer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.layers
的用法示例。
在下文中一共展示了layers.l1_regularizer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import l1_regularizer [as 别名]
def __init__(self,
params,
device_assigner=None,
optimizer_class=adagrad.AdagradOptimizer,
**kwargs):
self.device_assigner = (
device_assigner or framework_variables.VariableDeviceChooser())
self.params = params
self.optimizer = optimizer_class(self.params.learning_rate)
self.is_regression = params.regression
self.regularizer = None
if params.regularization == "l1":
self.regularizer = layers.l1_regularizer(
self.params.regularization_strength)
elif params.regularization == "l2":
self.regularizer = layers.l2_regularizer(
self.params.regularization_strength)
示例2: __init__
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import l1_regularizer [as 别名]
def __init__(self,
params,
device_assigner=None,
optimizer_class=adagrad.AdagradOptimizer,
**kwargs):
self.device_assigner = (
device_assigner or tensor_forest.RandomForestDeviceAssigner())
self.params = params
self.optimizer = optimizer_class(self.params.learning_rate)
self.is_regression = params.regression
self.regularizer = None
if params.regularization == "l1":
self.regularizer = layers.l1_regularizer(
self.params.regularization_strength)
elif params.regularization == "l2":
self.regularizer = layers.l2_regularizer(
self.params.regularization_strength)
示例3: _build_regularizer
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import l1_regularizer [as 别名]
def _build_regularizer(regularizer):
"""Builds a regularizer from config.
Args:
regularizer: hyperparams_pb2.Hyperparams.regularizer proto.
Returns:
regularizer.
Raises:
ValueError: On unknown regularizer.
"""
regularizer_oneof = regularizer.WhichOneof('regularizer_oneof')
if regularizer_oneof == 'l1_regularizer':
return layers.l1_regularizer(scale=float(regularizer.l1_regularizer.weight))
if regularizer_oneof == 'l2_regularizer':
return layers.l2_regularizer(scale=float(regularizer.l2_regularizer.weight))
raise ValueError('Unknown regularizer function: {}'.format(regularizer_oneof))
示例4: prepare
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import l1_regularizer [as 别名]
def prepare(self):
""" Setup the weight initalizers and regularizers. """
config = self.config
self.conv_kernel_initializer = layers.xavier_initializer()
if self.train_cnn and config.conv_kernel_regularizer_scale > 0:
self.conv_kernel_regularizer = layers.l2_regularizer(
scale = config.conv_kernel_regularizer_scale)
else:
self.conv_kernel_regularizer = None
if self.train_cnn and config.conv_activity_regularizer_scale > 0:
self.conv_activity_regularizer = layers.l1_regularizer(
scale = config.conv_activity_regularizer_scale)
else:
self.conv_activity_regularizer = None
self.fc_kernel_initializer = tf.random_uniform_initializer(
minval = -config.fc_kernel_initializer_scale,
maxval = config.fc_kernel_initializer_scale)
if self.is_train and config.fc_kernel_regularizer_scale > 0:
self.fc_kernel_regularizer = layers.l2_regularizer(
scale = config.fc_kernel_regularizer_scale)
else:
self.fc_kernel_regularizer = None
if self.is_train and config.fc_activity_regularizer_scale > 0:
self.fc_activity_regularizer = layers.l1_regularizer(
scale = config.fc_activity_regularizer_scale)
else:
self.fc_activity_regularizer = None