Giter Site home page Giter Site logo

metehanyasar11 / yolov5-pip Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fcakyon/yolov5-pip

0.0 0.0 0.0 1.15 MB

Packaged version of ultralytics/yolov5 + many extra features

Home Page: https://pypi.org/project/yolov5/

License: GNU General Public License v3.0

Shell 0.46% Python 99.54%

yolov5-pip's Introduction

packaged ultralytics/yolov5

pip install yolov5

total downloads monthly downloads fcakyon twitter
pypi version ci testing package testing

Overview

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

This yolov5 package contains everything from ultralytics/yolov5 at this commit plus:
1. Easy installation via pip: `pip install yolov5`
2. Full CLI integration with fire package
3. COCO dataset format support (for training)
4. S3 support (model and dataset upload)
5. NeptuneAI logger support (metric, model and dataset logging)
6. Classwise AP logging during experiments

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 pretrained model
model = yolov5.load('yolov5s.pt')

# or load custom model
model = yolov5.load('train/best.pt')
  
# set model parameters
model.conf = 0.25  # NMS confidence threshold
model.iou = 0.45  # NMS IoU threshold
model.agnostic = False  # NMS class-agnostic
model.multi_label = False  # NMS multiple labels per box
model.max_det = 1000  # maximum number of detections per image

# 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, y1, x2, 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, y1, x2, 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
  • Start a training using a COCO formatted dataset:
# data.yml
train_json_path: "train.json"
train_image_dir: "train_image_dir/"
val_json_path: "val.json"
val_image_dir: "val_image_dir/"
$ yolov5 train --data data.yaml --weights yolov5s.pt
  • Visualize your experiments via Neptune.AI (neptune-client>=0.10.10 required):
$ yolov5 train --data data.yaml --weights yolov5s.pt --neptune_project NAMESPACE/PROJECT_NAME --neptune_token YOUR_NEPTUNE_TOKEN
  • Automatically upload weights and datasets to AWS S3 (with Neptune.AI artifact tracking integration):
export AWS_ACCESS_KEY_ID=YOUR_KEY
export AWS_SECRET_ACCESS_KEY=YOUR_KEY
$ yolov5 train --data data.yaml --weights yolov5s.pt --s3_upload_dir YOUR_S3_FOLDER_DIRECTORY --upload_dataset
  • Add yolo_s3_data_dir into data.yaml to match Neptune dataset with a present dataset in S3.
# data.yml
train_json_path: "train.json"
train_image_dir: "train_image_dir/"
val_json_path: "val.json"
val_image_dir: "val_image_dir/"
yolo_s3_data_dir: s3://bucket_name/data_dir/
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'

yolov5-pip's People

Contributors

fcakyon avatar metehanyasar11 avatar 5a7man avatar merdini avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.