"""
# **Clone Ultralytics Yolov5 Directory**
"""
!git clone https://github.com/ultralytics/yolov5
!cd yolov5
!pip install -r ./yolov5/requirements.txt
"""
# **Check Img Size**
"""
import matplotlib.pyplot as plt
img = plt.imread('../input/car-object-detection/data/training_images/vid_4_10000.jpg')
img.shape
"""
# **Predictions**
"""
"""
We only need to run predictions since yolov5 is already trained to detect cars as one of the classes. 
"""
!python ./yolov5/detect.py --img 676 --conf 0.45 --source ../input/car-object-detection/data/testing_images --weights yolov5x.pt
"""
# **Visualize Predictions**
"""
import os
file_paths = []
flist = os.listdir('./runs/detect/exp')
for file in flist:
    fpath = os.path.join('./runs/detect/exp', file)
    file_paths.append(fpath)
import numpy as np
random = np.random.randint(0, len(file_paths) - 1)
img_path = file_paths[random]
print(img_path)
plt.figure(figsize=(30, 25))
for i in range(25):
    random = np.random.randint(0, len(file_paths) - 1)
    plt.subplot(5, 5, i + 1)
    img_path = file_paths[random]
    img = plt.imread(img_path)
    plt.imshow(img)
    plt.title('Predictions', size=10, color="black") 
    plt.xticks([])
    plt.yticks([])
    
plt.show()
"""
As we can see, yolov5 large is great at car detection and also picked up some traffic lights and a stop sign. 
"""