The detect image function takes the image and uses the YOLO3 network to predict the class of objects within the image using yolo.predict. The code for this is as follows:
def detect_image(image, yolo, all_classes):
"""Use yolo v3 to detect images.
# Argument:
image: original image.
yolo: YOLO, yolo model.
all_classes: all classes name.
# Returns:
image: processed image.
"""
pimage = process_image(image)
start = time.time()
image_boxes, image_classes, image_scores = yolo.predict(pimage, image.shape)
end = time.time()
print('time: {0:.2f}s'.format(end - start))
if boxes is not None:
draw_boxes(image, image_boxes, image_scores, image_classes, image_all_classes)
return image
In the next section, we will write some code that will detect objects in videos.