は、我々は、各層のこの(source)のような何かを書くことができる:wc=0
はL2重み減衰を指すTensorFlowで個々のレイヤーの重量減衰を定義する方法は? CUDA ConvNetで
[conv32]
epsW=0.001
epsB=0.002
momW=0.9
momB=0.9
wc=0
。
TensorFlowではどのように同じことが達成できますか?
は、我々は、各層のこの(source)のような何かを書くことができる:wc=0
はL2重み減衰を指すTensorFlowで個々のレイヤーの重量減衰を定義する方法は? CUDA ConvNetで
[conv32]
epsW=0.001
epsB=0.002
momW=0.9
momB=0.9
wc=0
。
TensorFlowではどのように同じことが達成できますか?
体重減少を加えたいすべての変数をコレクション名 'variables'に追加して、コレクション全体のL2ノルム減量を計算することができます。
# Create your variables
weights = tf.get_variable('weights', collections=['variables'])
with tf.variable_scope('weights_norm') as scope:
weights_norm = tf.reduce_sum(
input_tensor = WEIGHT_DECAY_FACTOR*tf.pack(
[tf.nn.l2_loss(i) for i in tf.get_collection('weights')]
),
name='weights_norm'
)
# Add the weight decay loss to another collection called losses
tf.add_to_collection('losses', weights_norm)
# Add the other loss components to the collection losses
# ...
# To calculate your total loss
tf.add_n(tf.get_collection('losses'), name='total_loss')
get_variable(
name,
shape=None,
dtype=None,
initializer=None,
regularizer=None,
trainable=True,
collections=None,
caching_device=None,
partitioner=None,
validate_shape=True,
use_resource=None,
custom_getter=None)
これはtensorflow機能get_variable
の使用です。あなたは簡単に体重減衰を行う正規化者を指定することができます。続き
は一例です:
weight_decay = tf.constant(0.0005, dtype=tf.float32) # your weight decay rate, must be a scalar tensor.
W = tf.get_variable(name='weight', shape=[4, 4, 256, 512], regularizer=tf.contrib.layers.l2_regularizer(weight_decay))
はalexnetの重量崩壊と同等のこの量の崩壊ですか? – LKM
例の行6のテンソルフローv1.0 'tf.pack'で始まる注意は、' tf.stack'に名前が変更されました。 – Chrigi
'tf.get_collection( 'weights')の代わりに' tf.get_collection( 'variables') 'でなければなりません。 –