<jupyter_start><jupyter_text>Tip. Click here to view this notebook on nbviewer.jupyter.org.     These notebooks are better read there, as Github default viewer ignores some of the formatting and interactive content.                             Hands-on Computer Vision with TensorFlow 2by <NAME> & <NAME> (Packt Pub.)        > Chapter 5: Object Detection Models    Notebook 1:Inference with YOLO    We introduced the inner workings of You Only Look Once (YOLO), a fast object detection model.    In this first notebook, we will use the model for inference.     Requirements     To run this notebook, download the YOLO V3 weights and convert them using the command:wget https://pjreddie.com/media/files/yolov3.weights -O weights/yolov3.weightspython convert.py --weights weights/yolov3.weights --output weights/yolov3.tf     Acknowledgements     This implementation is based on Zihao Zhang's implementation. Thanks to him!    Tip. The notebooks shared on this git repository illustrate some notions from the book "Hands-on Computer Vision with TensorFlow 2" written by <NAME> and <NAME>, published by Packt. If you enjoyed the insights shared here, please consider acquiring the book!The book provides further guidance for those eager to learn about computer vision and to harness the power of TensorFlow 2 and Keras to build efficient recognition systems for object detection, segmentation, video processing, smartphone applications, and more.                                    Leverage deep learning to create powerful image processing apps with TensorFlow 2 and Keras. Get the book for more insights!                                                                                                  Imports<jupyter_code>import time
from absl import app, flags, logging
from absl.flags import FLAGS
import cv2
import numpy as np
import tensorflow as tf
from models import YoloV3
from utils import draw_outputs, transform_images
import matplotlib.pyplot as plt

CLASSES_PATH = './coco.names'
WEIGHTS_PATH = './weights/yolov3.tf'
IMAGE_SIZE = 416<jupyter_output><empty_output><jupyter_text>Load the model, the classes and the example image<jupyter_code>yolo = YoloV3()
yolo.load_weights(WEIGHTS_PATH)
class_names = [c.strip() for c in open(CLASSES_PATH).readlines()]

img = tf.image.decode_image(open('./dog_example.jpg', 'rb').read(), channels=3)
plt.imshow(img)
plt.show()

input_img = tf.expand_dims(img, 0)
input_img = transform_images(input_img, IMAGE_SIZE)<jupyter_output><empty_output><jupyter_text>Run inference and display result<jupyter_code>boxes, scores, classes, nums = yolo(input_img)


logging.info('detections:')
for i in range(nums[0]):
    print('\t{}, {}, {}'.format(class_names[int(classes[0][i])],
                                       np.array(scores[0][i]),
                                       np.array(boxes[0][i])))

prediction_img = draw_outputs(img.numpy(), (boxes, scores, classes, nums), class_names)
plt.figure(figsize=(10, 20))
plt.imshow(prediction_img)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08151093439363817, 'fraction_numerical': 0.00927766732935719, 'mean_word_length': 3.5398496240601505, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '333599', 'license': 'MIT', 'n_tokens_mistral': 872, 'n_tokens_neox': 827, 'n_words': 302, 'path': 'Chapter05/ch5_nb1_yolo_inference.ipynb', 'repo_name': 'yellowjs0304/tf_computer_vision', 'size': '3050'}