<p>Object detection consists of classification and regression, that is, not only do we have to correctly classify an object on the image, but also we need to correctly locate the object. </p>

<p>Although some object detection frameworks do look like a regression model (YOLO, SSD), but the loss function is not as simple as a L2 loss. In fact, the loss function consists of two parts, <code>crossentropy</code> loss for classification and <code>regression</code> loss for localization, and L2 loss is usually used for <code>regression</code> loss here.</p>

<p>Here are the loss functions of some common object detection models.</p>

<p><a href="https://arxiv.org/pdf/1512.02325.pdf" rel="nofollow noreferrer">SSD model.</a>
<a href="https://i.stack.imgur.com/oKZGF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oKZGF.png" alt="enter image description here"></a></p>

<p><a href="https://arxiv.org/pdf/1506.02640v2.pdf" rel="nofollow noreferrer">YOLO model</a></p>

<p><a href="https://i.stack.imgur.com/OE1og.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OE1og.png" alt="enter image description here"></a></p>
How can I use L2-Loss function for Object-detection CNN in Tensorflow framework?
<p>I'm studying about tensorflow (exactly Object Detection using CNN)</p>

<p>I have already studied about Classification, but Object-Detection is Regression problem, so I am confused loss function and total network implementation.</p>

<p>In classification problem, I should use-</p>

<p><strong>tf.nn.softmax_cross_entropy_with_logits(logits=result, labels=Y)</strong></p>

<p>(result is my CNN output tensor)</p>

<p>but in regression problem, like sementic-segmentation and object detection, I found that I have to use l2-loss function.</p>

<p><strong>tf.nn.l2_loss(t=result)</strong></p>

<p>I don't know how can I use this function because I cannot use tf.argmax function.</p>

<p><strong>[Source Code 1] Classification, used softmax and tf.argmax</strong></p>

<pre class="lang-py prettyprint-override"><code>cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=result, labels=Y))
print("* Cross Entropy SIZE : " + str(cross_entropy))

Result_argmax = tf.argmax(tf.nn.softmax(result), 1)
Label_argmax = tf.argmax(Y, 1)
print("* Result Argmax : ", Result_argmax)
print("* Label Argmax : ", Label_argmax)

ay = tf.argmax(tf.nn.softmax(result), 1)
ly = tf.argmax(tf.nn.softmax(Y), 1)
correct_prediction = tf.equal(Result_argmax, Label_argmax)
print("* tf.argmax : " + str(Result_argmax))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

train_step = tf.train.AdamOptimizer(0.0001 * batchsize).minimize(cross_entropy)
</code></pre>

<p>this is so easy and I totally understood.</p>

<p><strong>[Source Code 2] Regression, used l2_loss function</strong></p>

<pre class="lang-py prettyprint-override"><code>l2_loss = tf.reduce_mean(tf.nn.l2_loss(t=result))
print("** L2 Loss SIZE : " + str(l2_loss))
train_step = tf.train.AdamOptimizer(0.0001 * batchsize).minimize(l2_loss)

????????
</code></pre>

<p>Is that correct? I cannot understand how to do box location learning.</p>

<p>Also, There is my learning monitor which is captured.</p>

<p><a href="https://i.stack.imgur.com/FxRJz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FxRJz.png" alt="enter image description here"></a></p>

<p>Really, Really I can't understand. <strong>Please HELP ME!</strong></p>

<p>(last, here is my session image captured.)
<a href="https://i.stack.imgur.com/Trd7S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Trd7S.png" alt="enter image description here"></a></p>