# Is there anything wrong with this YOLO loss function?

I have implemented the YOLOv1 loss function as:

def yolo_loss(ytrue, ypred):
lambda_obj=5.0
lambda_noobj=0.5

ytrue_cfs = ytrue[..., 0:1]
ypred_cfs = ypred[..., 0:1]

ytrue_coord = ytrue[..., 1:3]
ypred_coord = ypred[..., 1:3]

ytrue_wh = ytrue[..., 3:5]
ypred_wh = ypred[..., 3:5]

ytrue_xy = ytrue_coord + ytrue_wh/2.0
ypred_xy = ypred_coord + ypred_wh/2.0

ytrue_class = ytrue[..., 5:]
ypred_class = ypred[..., 5:]

class_loss = K.sum(K.square(ytrue_class - ypred_class))
xy_loss = K.sum(K.square(ytrue_xy-ypred_xy)*ytrue_cfs) * lambda_obj
wh_loss = K.sum(K.square(K.sqrt(ytrue_wh)-K.sqrt(ypred_wh))*ytrue_cfs) * lambda_obj
conf_loss = K.sum(K.square(ytrue_cfs - ypred_cfs)*ytrue_cfs) + K.sum(K.square(ytrue_cfs - ypred_cfs)*(1-ytrue_cfs)) * lambda_noobj

return class_loss + xy_loss + wh_loss + conf_loss


(The yolov1 loss is defined in this paper https://arxiv.org/pdf/1506.02640.pdf)

I am trying to make a face detection model using YOLO from scratch without defining any anchor boxes i.e the dimensions of ytrue (or ypred) is (19, 19, 1, 6) (the 1 in axis 2 simply means just one predicting box per cell). I have chosen 19*19 grid cells as the output. Each bounding box has 6 numbers representing- the confidence whether it has an object, the top left x coordinate, the top left y coordinate, the width, the height, and the probability of having a face in the box.

The implementation above just computes the confidence, classification and regression losses and sums them up after weighing them with lambda_obj and lambda_noobj (the values are taken from the paper itself).

I am training on the Wider face dataset using the mobilenet v1 architecture. However, after 30-40 epochs the validation loss gets just stagnant at a loss of 359.0. On training longer, it finally starts increasing with the training loss still going down, thus clearly overfitting the dataset.

Does anyone have any suggestions on what I should do?