Skip to content

Instantly share code, notes, and snippets.

@f-rumblefish
Last active October 23, 2018 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save f-rumblefish/80340ce65ab497f95e21f1d5fbb17f4e to your computer and use it in GitHub Desktop.
Save f-rumblefish/80340ce65ab497f95e21f1d5fbb17f4e to your computer and use it in GitHub Desktop.
YOLOv2 Prediction
# loop 845 bounding boxes
for i in range(Net_YOLO_pred.shape[0]):
# get the confidence on the object
confidence_on_box = Net_YOLO_pred[i][4]
# find the class index with the highest probability
probability_list = Net_YOLO_pred[i][5:]
class_index = probability_list.argmax(axis=0)
probability_on_class = probability_list[class_index]
# get the score
score = confidence_on_box * probability_on_class
# draw the bounding box
if (score > threshold):
x_center = Net_YOLO_pred[i][0] * cols
y_center = Net_YOLO_pred[i][1] * rows
width = Net_YOLO_pred[i][2] * cols
height = Net_YOLO_pred[i][3] * rows
left = int(x_center - width * 0.5)
top = int(y_center - height * 0.5)
right = int(x_center + width * 0.5)
bottom = int(y_center + height * 0.5)
box = patch.Rectangle((int(left), int(top)),
width,
height,
linewidth=2, edgecolor='r', facecolor='none')
ax2.add_patch(box)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment