我已经实现了一个CNN
数字分类模型。我的模型过度拟合了很多,为了克服过度拟合,我试图L2 Regularization
在我的成本函数中使用。我有一个小小的困惑,我该如何选择<weights>
放入成本方程(代码的最后一行)。
...
x = tf.placeholder(tf.float32, shape=[None, img_size, img_size, num_channels], name='x') # Input
y_true = tf.placeholder(tf.float32, shape=[None, num_classes], name='y_true') # Labels
<Convolution Layer 1>
<Convolution Layer 2>
<Convolution Layer 3>
<Fully Coonected 1>
<Fully Coonected 2> O/P = layer_fc2
# Loss Function
lambda = 0.01
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(logits=layer_fc2, labels=y_true)
# cost = tf.reduce_mean(cross_entropy) # Nornmal Loss
cost = tf.reduce_mean(cross_entropy + lambda * tf.nn.l2_loss(<weights>)) # Regularized Loss
...