Skip to main content

Packaged version of the Yolov5 object detector

Project description

packaged ultralytics/yolov5

pip install yolov5

total downloads monthly downloads pypi version
ci testing package testing

Overview

You can finally install YOLOv5 object detector using pip and integrate into your project easily.

Install

Install yolov5 using pip (for Python >=3.7)
pip install yolov5
Install yolov5 using pip `(for Python 3.6)`
pip install "numpy>=1.18.5,<1.20" "matplotlib>=3.2.2,<4"
pip install yolov5

Use from Python

Basic
import yolov5

# load model
model = yolov5.load('yolov5s')

# set image
img = 'https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg'

# perform inference
results = model(img)

# inference with larger input size
results = model(img, size=1280)

# inference with test time augmentation
results = model(img, augment=True)

# parse results
predictions = results.pred[0]
boxes = predictions[:, :4] # x1, x2, y1, y2
scores = predictions[:, 4]
categories = predictions[:, 5]

# show detection bounding boxes on image
results.show()

# save results into "results/" folder
results.save(save_dir='results/')
Alternative
from yolov5 import YOLOv5

# set model params
model_path = "yolov5/weights/yolov5s.pt"
device = "cuda:0" # or "cpu"

# init yolov5 model
yolov5 = YOLOv5(model_path, device)

# load images
image1 = 'https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg'
image2 = 'https://github.com/ultralytics/yolov5/blob/master/data/images/bus.jpg'

# perform inference
results = yolov5.predict(image1)

# perform inference with larger input size
results = yolov5.predict(image1, size=1280)

# perform inference with test time augmentation
results = yolov5.predict(image1, augment=True)

# perform inference on multiple images
results = yolov5.predict([image1, image2], size=1280, augment=True)

# parse results
predictions = results.pred[0]
boxes = predictions[:, :4] # x1, x2, y1, y2
scores = predictions[:, 4]
categories = predictions[:, 5]

# show detection bounding boxes on image
results.show()

# save results into "results/" folder
results.save(save_dir='results/')
Train/Detect/Test/Export
  • You can directly use these functions by importing them:
from yolov5 import train, val, detect, export

train.run(imgsz=640, data='coco128.yaml')
val.run(imgsz=640, data='coco128.yaml', weights='yolov5s.pt')
detect.run(imgsz=640)
export.run(imgsz=640, weights='yolov5s.pt')
  • You can pass any argument as input:
from yolov5 import detect

img_url = 'https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg'

detect.run(source=img_url, weights="yolov5s6.pt", conf_thres=0.25, imgsz=640)

Use from CLI

You can call yolov5 train, yolov5 detect, yolov5 val and yolov5 export commands after installing the package via pip:

Training

Finetune one of the pretrained YOLOv5 models using your custom data.yaml:

$ yolov5 train --data data.yaml --weights yolov5s.pt --batch-size 16 --img 640
                                          yolov5m.pt              8
                                          yolov5l.pt              4
                                          yolov5x.pt              2

Visualize your experiments via Neptune.AI:

$ yolov5 train --data data.yaml --weights yolov5s.pt --neptune_project NAMESPACE/PROJECT_NAME --neptune_token YOUR_NEPTUNE_TOKEN
Inference

yolov5 detect command runs inference on a variety of sources, downloading models automatically from the latest YOLOv5 release and saving results to runs/detect.

$ yolov5 detect --source 0  # webcam
                         file.jpg  # image
                         file.mp4  # video
                         path/  # directory
                         path/*.jpg  # glob
                         rtsp://170.93.143.139/rtplive/470011e600ef003a004ee33696235daa  # rtsp stream
                         rtmp://192.168.1.105/live/test  # rtmp stream
                         http://112.50.243.8/PLTV/88888888/224/3221225900/1.m3u8  # http stream
Export

You can export your fine-tuned YOLOv5 weights to any format such as torchscript, onnx, coreml, pb, tflite, tfjs:

$ yolov5 export --weights yolov5s.pt --include 'torchscript,onnx,coreml,pb,tfjs'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yolov5-6.0.1.tar.gz (795.5 kB view details)

Uploaded Source

Built Distribution

yolov5-6.0.1-py36.py37.py38-none-any.whl (828.5 kB view details)

Uploaded Python 3.6Python 3.7Python 3.8

File details

Details for the file yolov5-6.0.1.tar.gz.

File metadata

  • Download URL: yolov5-6.0.1.tar.gz
  • Upload date:
  • Size: 795.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for yolov5-6.0.1.tar.gz
Algorithm Hash digest
SHA256 ab9b7b2efd7fe784f68c1b635b6bfc3e084daca079668151d4936e7365559362
MD5 33fadf3af7b4ef2e63d5723bef216274
BLAKE2b-256 c547ae4e134cc6854dff644de845e520abf124e1cd8c4afa4bd155fe0799ab6e

See more details on using hashes here.

File details

Details for the file yolov5-6.0.1-py36.py37.py38-none-any.whl.

File metadata

  • Download URL: yolov5-6.0.1-py36.py37.py38-none-any.whl
  • Upload date:
  • Size: 828.5 kB
  • Tags: Python 3.6, Python 3.7, Python 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for yolov5-6.0.1-py36.py37.py38-none-any.whl
Algorithm Hash digest
SHA256 9e00c4b7413b005700f3f41fb5163ddfb80c77597a09e35e14a6fec420603bc1
MD5 6dee277e054f6ea5a0ab1b6baf59b045
BLAKE2b-256 4aa02e249cbf578f45e0a24f6807a5abe5bb01e00ff57524303d230bb105054b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page