Installing Yolo V5 From the Internet

In [1]:
import os
In [2]:
# Clone repo to the (newly created) yolov5 folder
!git clone "https://github.com/ultralytics/yolov5"
Cloning into 'yolov5'...
remote: Enumerating objects: 28, done.
remote: Counting objects: 100% (28/28), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 1881 (delta 9), reused 8 (delta 4), pack-reused 1853
Receiving objects: 100% (1881/1881), 5.14 MiB | 32.46 MiB/s, done.
Resolving deltas: 100% (1217/1217), done.
In [3]:
# install dependencies (There are some errors but we can gnore them)
!pip install -qr yolov5/requirements.txt
     |████████████████████████████████| 276kB 4.7MB/s 
  Building wheel for PyYAML (setup.py) ... done
In [5]:
# Move into the yolo folder
%cd yolov5
/content/yolov5
In [6]:
# Import the libraries
import torch
from IPython.display import Image, clear_output  # to display images
from utils.google_utils import gdrive_download  # to download models/datasets

print('Setup complete. Using torch %s %s' % (torch.__version__, torch.cuda.get_device_properties(0) if torch.cuda.is_available() else 'CPU'))
Setup complete. Using torch 1.5.1+cu101 CPU

Use the command line command to predict and save the result

In [9]:
!python detect.py --weights yolov5s.pt --conf 0.4 --source ..
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.4, device='', img_size=640, iou_thres=0.5, output='inference/output', save_txt=False, source='..', update=False, view_img=False, weights=['yolov5s.pt'])
Using CPU

Fusing layers... Model Summary: 140 layers, 7.45958e+06 parameters, 6.61683e+06 gradients
image 1/7 /content/600px-Anna_Kaplan_2018.jpg: 640x640 1 persons, 1 ties, Done. (0.645s)
image 2/7 /content/6_GFCA_2018_Myim_Bialik.jpg: 640x640 1 persons, Done. (0.450s)
image 3/7 /content/AHSRichard.jpg: 448x640 1 persons, Done. (0.381s)
image 4/7 /content/Alain_St._Ange,_October_2014.jpg: 576x640 1 persons, 1 sports balls, Done. (0.526s)
image 5/7 /content/Alex_Smith_TEDx_Speech.png: 640x512 1 persons, Done. (0.468s)
image 6/7 /content/Andrei_codrescu.jpg: 640x512 1 persons, Done. (0.380s)
image 7/7 /content/Astronaut_candidate_Jeremy_Hansen_speaks_to_a_crowd_at_Johnson_Space_Center.jpg: 640x576 1 persons, 1 ties, Done. (0.494s)
Results saved to /content/yolov5/inference/output
Done. (3.505s)
In [10]:
# Yolo has annotated each picture with boudning boxes and written the outputs in the yolov5/inference/output directory
os.listdir("/content/yolov5/inference/output")
Out[10]:
['AHSRichard.jpg',
 'Alain_St._Ange,_October_2014.jpg',
 'Andrei_codrescu.jpg',
 '600px-Anna_Kaplan_2018.jpg',
 '6_GFCA_2018_Myim_Bialik.jpg',
 'Astronaut_candidate_Jeremy_Hansen_speaks_to_a_crowd_at_Johnson_Space_Center.jpg',
 'Alex_Smith_TEDx_Speech.png']

Let's inspect the results

In [12]:
Image("/content/yolov5/inference/output/AHSRichard.jpg")
Out[12]:
In [13]:
Image("/content/yolov5/inference/output/Alain_St._Ange,_October_2014.jpg")
Out[13]:
In [19]:
Image("/content/yolov5/inference/output/Andrei_codrescu.jpg")
Out[19]:
In [20]:
Image("/content/yolov5/inference/output/600px-Anna_Kaplan_2018.jpg")
Out[20]:
In [21]:
Image("/content/yolov5/inference/output/6_GFCA_2018_Myim_Bialik.jpg")
Out[21]:
In [24]:
Image("/content/yolov5/inference/output/Astronaut_candidate_Jeremy_Hansen_speaks_to_a_crowd_at_Johnson_Space_Center.jpg")
Out[24]:
In [25]:
 Image("/content/yolov5/inference/output/Alex_Smith_TEDx_Speech.png")
Out[25]: