本文整理匯總了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