In this section, we will predict the objects present in an image using YOLO. In the following code block we will start with importing the image:
f = 'image.jpg'
path = 'images/'+f
image = cv2.imread(path)
The input image looks as follows:
Fig 11.4: Input image
We will perform the prediction using detect_image method in the following code:
image = detect_image(image, yolo, all_classes)
cv2.imwrite('images/res/' + f, image)
This yields the following prediction:
Fig 11.5: Output image
Here, we can observe that it predicted a person with 100% accuracy and the motorbike with 100% accuracy as well. You can take different images and experiment with this yourself!