Skip to content

Instantly share code, notes, and snippets.

@pythonlessons
Created April 29, 2020 19:55
Show Gist options
  • Select an option

  • Save pythonlessons/74313d6aec70b7bf1e03c38a67aa2ac5 to your computer and use it in GitHub Desktop.

Select an option

Save pythonlessons/74313d6aec70b7bf1e03c38a67aa2ac5 to your computer and use it in GitHub Desktop.
Yolo_v3_bbox_iou
iou = bbox_iou(pred_xywh [:,:,:,:, np.newaxis,:], bboxes[:, np.newaxis, np.newaxis, np.newaxis,:,:])
# Find the value of IoU with the real largest prediction box
max_iou = tf.expand_dims(tf.reduce_max(iou, axis = -1 ), axis = -1 )
# If the largest IoU is less than the threshold, it is considered that the prediction box contains no objects, then the background box
respond_bgd = (1.0-respond_bbox) * tf.cast(max_iou<IOU_LOSS_THRESH, tf.float32)
conf_focal = tf.pow(respond_bbox-pred_conf, 2)
# Calculate the loss of confidence
# we hope that if the grid contains objects, then the network output prediction box has a confidence of 1 and 0 when there is no object.
Conf_loss = conf_focal * (
respond_bbox * tf.nn.sigmoid_cross_entropy_with_logits (labels = respond_bbox, logits = conv_raw_conf)
+
respond_bgd * tf.nn.sigmoid_cross_entropy_with_logits (labels = respond_bbox, logits = conv_raw_conf)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment