本文整理匯總了Python中config.weight_decay方法的典型用法代碼示例。如果您正苦於以下問題:Python config.weight_decay方法的具體用法?Python config.weight_decay怎麽用?Python config.weight_decay使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類config
的用法示例。
在下文中一共展示了config.weight_decay方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_train_op
# 需要導入模塊: import config [as 別名]
# 或者: from config import weight_decay [as 別名]
def get_train_op(loss, mode):
if mode != ModeKeys.TRAIN:
return None
global_step = tf.train.get_or_create_global_step()
learning_rate = tf.train.exponential_decay(config.learning_rate, global_step, config.decay_circles, config.lr_decay, staircase=True)
tf.summary.scalar('learning_rate', learning_rate)
tvars = tf.trainable_variables()
regularizer = tf.contrib.layers.l2_regularizer(config.weight_decay)
regularizer_loss = tf.contrib.layers.apply_regularization(regularizer, tvars)
loss += regularizer_loss
grads, _ = tf.clip_by_global_norm(tf.gradients(loss, tvars), config.clip_gradients)
# optimizer = tf.train.GradientDescentOptimizer(self.lr)
optimizer = tf.train.AdamOptimizer(learning_rate)
batchnorm_update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
with tf.control_dependencies(batchnorm_update_ops):
train_op = optimizer.apply_gradients(zip(grads, tvars), global_step)
return train_op
示例2: _build_network
# 需要導入模塊: import config [as 別名]
# 或者: from config import weight_decay [as 別名]
def _build_network(self):
import config
if config.model_type == MODEL_TYPE_vgg16:
from nets import vgg
with slim.arg_scope([slim.conv2d],
activation_fn=tf.nn.relu,
weights_regularizer=slim.l2_regularizer(config.weight_decay),
weights_initializer= tf.contrib.layers.xavier_initializer(),
biases_initializer = tf.zeros_initializer()):
with slim.arg_scope([slim.conv2d, slim.max_pool2d],
padding='SAME') as sc:
self.arg_scope = sc
self.net, self.end_points = vgg.basenet(
inputs = self.inputs)
elif config.model_type == MODEL_TYPE_vgg16_no_dilation:
from nets import vgg
with slim.arg_scope([slim.conv2d],
activation_fn=tf.nn.relu,
weights_regularizer=slim.l2_regularizer(config.weight_decay),
weights_initializer= tf.contrib.layers.xavier_initializer(),
biases_initializer = tf.zeros_initializer()):
with slim.arg_scope([slim.conv2d, slim.max_pool2d],
padding='SAME') as sc:
self.arg_scope = sc
self.net, self.end_points = vgg.basenet(
inputs = self.inputs, dilation = False)
else:
raise ValueError('model_type not supported:%s'%(config.model_type))