Loss Function for smaller values


I would like to discuss a topic related to Loss Functions.

I have an object detection model that predicts 3 things (class, bbox, and distance). I am using 2 input images for the model.

I would like to discss about the last predicted value, i.e. distance. The input is the depth image which is normalized between 0 and 1. This value ranges between 0 and 1 as an output and then is multiplied by 200 in the eval stage to get the correct prediction. Currently I am using the following loss function:

dist_loss_funciton = nn.SmoothL1Loss(reduction='none')
dist_loss = torch.sum(dist_loss_funciton (pred_dist, gt_dist)) / batch_size

Note that here the value is predicted for each bounding box detected. I get the depth loss as 0 after a few epochs, however the values aren’t correct.

I think this is because the model thinks that because the output value is between 0 and 1, anything between that range is okay and is not bad.

How can I change this loss function so as to accommodate the aforementioned? i.e. penalize the loss function if the value is between 0.3 and 1.0, or something?