💻 源码

Run on Gradient Open In Colab Open In Kaggle
This YOLOv5 🚀 notebook by Ultralytics presents simple train, validate and predict examples to help start your AI adventure.
See GitHub for community support or contact us for professional support.

Setup

Clone GitHub repository, install dependencies and check PyTorch and GPU.

!git clone https://github.com/ultralytics/yolov5  # clone
%cd yolov5
%pip install -qr requirements.txt  # install

import torch
import utils
display = utils.notebook_init()  # checks
YOLOv5 🚀 v7.0-3-g61ebf5e Python-3.7.15 torch-1.12.1+cu113 CUDA:0 (Tesla T4, 15110MiB)
Setup complete ✅ (2 CPUs, 12.7 GB RAM, 22.6/78.2 GB disk)

1. Predict

classify/predict.py runs YOLOv5 Classification inference on a variety of sources, downloading models automatically from the latest YOLOv5 release, and saving results to runs/predict-cls. Example inference sources are:

python classify/predict.py --source 0  # webcam
                              img.jpg  # image 
                              vid.mp4  # video
                              screen  # screenshot
                              path/  # directory
                              'path/*.jpg'  # glob
                              'https://youtu.be/LNwODJXcvt4'  # YouTube
                              'rtsp://example.com/media.mp4'  # RTSP, RTMP, HTTP stream
!python classify/predict.py --weights yolov5s-cls.pt --img 224 --source data/images
# display.Image(filename='runs/predict-cls/exp/zidane.jpg', width=600)
classify/predict: weights=['yolov5s-cls.pt'], source=data/images, data=data/coco128.yaml, imgsz=[224, 224], device=, view_img=False, save_txt=False, nosave=False, augment=False, visualize=False, update=False, project=runs/predict-cls, name=exp, exist_ok=False, half=False, dnn=False, vid_stride=1
YOLOv5 🚀 v7.0-3-g61ebf5e Python-3.7.15 torch-1.12.1+cu113 CUDA:0 (Tesla T4, 15110MiB)

Downloading https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s-cls.pt to yolov5s-cls.pt...
100% 10.5M/10.5M [00:00<00:00, 12.3MB/s]

Fusing layers... 
Model summary: 117 layers, 5447688 parameters, 0 gradients, 11.4 GFLOPs
image 1/2 /content/yolov5/data/images/bus.jpg: 224x224 minibus 0.39, police van 0.24, amphibious vehicle 0.05, recreational vehicle 0.04, trolleybus 0.03, 3.9ms
image 2/2 /content/yolov5/data/images/zidane.jpg: 224x224 suit 0.38, bow tie 0.19, bridegroom 0.18, rugby ball 0.04, stage 0.02, 4.6ms
Speed: 0.3ms pre-process, 4.3ms inference, 1.5ms NMS per image at shape (1, 3, 224, 224)
Results saved to runs/predict-cls/exp

        

2. Validate

Validate a model's accuracy on the Imagenet dataset's val or test splits. Models are downloaded automatically from the latest YOLOv5 release. To show results by class use the --verbose flag.

# Download Imagenet val (6.3G, 50000 images)
!bash data/scripts/get_imagenet.sh --val
--2022-11-22 19:53:40--  https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_val.tar
Resolving image-net.org (image-net.org)... 171.64.68.16
Connecting to image-net.org (image-net.org)|171.64.68.16|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6744924160 (6.3G) [application/x-tar]
Saving to: ‘ILSVRC2012_img_val.tar’

ILSVRC2012_img_val. 100%[===================>]   6.28G  16.1MB/s    in 10m 52s 

2022-11-22 20:04:32 (9.87 MB/s) - ‘ILSVRC2012_img_val.tar’ saved [6744924160/6744924160]

# Validate YOLOv5s on Imagenet val
!python classify/val.py --weights yolov5s-cls.pt --data ../datasets/imagenet --img 224 --half
classify/val: data=../datasets/imagenet, weights=['yolov5s-cls.pt'], batch_size=128, imgsz=224, device=, workers=8, verbose=True, project=runs/val-cls, name=exp, exist_ok=False, half=True, dnn=False
YOLOv5 🚀 v7.0-3-g61ebf5e Python-3.7.15 torch-1.12.1+cu113 CUDA:0 (Tesla T4, 15110MiB)

Fusing layers... 
Model summary: 117 layers, 5447688 parameters, 0 gradients, 11.4 GFLOPs
validating: 100% 391/391 [04:57<00:00,  1.31it/s]
                   Class      Images    top1_acc    top5_acc
                     all       50000       0.715       0.902
                   tench          50        0.94        0.98
                goldfish          50        0.88        0.92
       great white shark          50        0.78        0.96
             tiger shark          50        0.68        0.96
        hammerhead shark          50        0.82        0.92
            electric ray          50        0.76         0.9
                stingray          50         0.7         0.9
                    cock          50        0.78        0.92
                     hen          50        0.84        0.96
                 ostrich          50        0.98           1
               brambling          50         0.9        0.96
               goldfinch          50        0.92        0.98
             house finch          50        0.88        0.96
                   junco          50        0.94        0.98
          indigo bunting          50        0.86        0.88
          American robin          50         0.9        0.96
                  bulbul          50        0.84        0.96
                     jay          50         0.9        0.96
                  magpie          50        0.84        0.96
               chickadee          50         0.9           1
         American dipper          50        0.82        0.92
                    kite          50        0.76        0.94
              bald eagle          50        0.92           1
                 vulture          50        0.96           1
          great grey owl          50        0.94        0.98
         fire salamander          50        0.96        0.98
             smooth newt          50        0.58        0.94
                    newt          50        0.74         0.9
      spotted salamander          50        0.86        0.94
                 axolotl          50        0.86        0.96
       American bullfrog          50        0.78        0.92
               tree frog          50        0.84        0.96
             tailed frog          50        0.48         0.8
   loggerhead sea turtle          50        0.68        0.94
  leatherback sea turtle          50         0.5         0.8
              mud turtle          50        0.64        0.84
                terrapin          50        0.52        0.98
              box turtle          50        0.84        0.98
            banded gecko          50         0.7        0.88
            green iguana          50        0.76        0.94
          Carolina anole          50        0.58        0.96
desert grassland whiptail lizard          50        0.82        0.94
                   agama          50        0.74        0.92
   frilled-necked lizard          50        0.84        0.86
        alligator lizard          50        0.58        0.78
            Gila monster          50        0.72         0.8
   European green lizard          50        0.42         0.9
               chameleon          50        0.76        0.84
           Komodo dragon          50        0.86        0.96
          Nile crocodile          50         0.7        0.84
      American alligator          50        0.76        0.96
             triceratops          50         0.9        0.94
              worm snake          50        0.76        0.88
       ring-necked snake          50         0.8        0.92
 eastern hog-nosed snake          50        0.58        0.88
      smooth green snake          50         0.6        0.94
               kingsnake          50        0.82         0.9
            garter snake          50        0.88        0.94
             water snake          50         0.7        0.94
              vine snake          50        0.66        0.76
             night snake          50        0.34        0.82
         boa constrictor          50         0.8        0.96
     African rock python          50        0.48        0.76
            Indian cobra          50        0.82        0.94
             green mamba          50        0.54        0.86
               sea snake          50        0.62         0.9
    Saharan horned viper          50        0.56        0.86
eastern diamondback rattlesnake          50         0.6        0.86
              sidewinder          50        0.28        0.86
               trilobite          50        0.98        0.98
              harvestman          50        0.86        0.94
                scorpion          50        0.86        0.94
    yellow garden spider          50        0.92        0.96
             barn spider          50        0.38        0.98
  European garden spider          50        0.62        0.98
    southern black widow          50        0.88        0.94
               tarantula          50        0.94           1
             wolf spider          50        0.82        0.92
                    tick          50        0.74        0.84
               centipede          50        0.68        0.82
            black grouse          50        0.88        0.98
               ptarmigan          50        0.78        0.94
           ruffed grouse          50        0.88           1
          prairie grouse          50        0.92           1
                 peacock          50        0.88         0.9
                   quail          50         0.9        0.94
               partridge          50        0.74        0.96
             grey parrot          50         0.9        0.96
                   macaw          50        0.88        0.98
sulphur-crested cockatoo          50        0.86        0.92
                lorikeet          50        0.96           1
                  coucal          50        0.82        0.88
               bee eater          50        0.96        0.98
                hornbill          50         0.9        0.96
             hummingbird          50        0.88        0.96
                 jacamar          50        0.92        0.94
                  toucan          50        0.84        0.94
                    duck          50        0.76        0.94
  red-breasted merganser          50        0.86        0.96
                   goose          50        0.74        0.96
              black swan          50        0.94        0.98
                  tusker          50        0.54        0.92
                 echidna          50        0.98           1
                platypus          50        0.72        0.84
                 wallaby          50        0.78        0.88
                   koala          50        0.84        0.92
                  wombat          50        0.78        0.84
               jellyfish          50        0.88        0.96
             sea anemone          50        0.72         0.9
             brain coral          50        0.88        0.96
                flatworm          50         0.8        0.98
                nematode          50        0.86         0.9
                   conch          50        0.74        0.88
                   snail          50        0.78        0.88
                    slug          50        0.74        0.82
                sea slug          50        0.88        0.98
                  chiton          50        0.88        0.98
      chambered nautilus          50        0.88        0.92
          Dungeness crab          50        0.78        0.94
               rock crab          50        0.68        0.86
            fiddler crab          50        0.64        0.86
           red king crab          50        0.76        0.96
        American lobster          50        0.78        0.96
           spiny lobster          50        0.74        0.88
                crayfish          50        0.56        0.86
             hermit crab          50        0.78        0.96
                  isopod          50        0.66        0.78
             white stork          50        0.88        0.96
             black stork          50        0.84        0.98
               spoonbill          50        0.96           1
                flamingo          50        0.94           1
       little blue heron          50        0.92        0.98
             great egret          50         0.9        0.96
                 bittern          50        0.86        0.94
            crane (bird)          50        0.62         0.9
                 limpkin          50        0.98           1
        common gallinule          50        0.92        0.96
           American coot          50         0.9        0.98
                 bustard          50        0.92        0.96
         ruddy turnstone          50        0.94           1
                  dunlin          50        0.86        0.94
         common redshank          50         0.9        0.96
               dowitcher          50        0.84        0.96
           oystercatcher          50        0.86        0.94
                 pelican          50        0.92        0.96
            king penguin          50        0.88        0.96
               albatross          50         0.9           1
              grey whale          50        0.84        0.92
            killer whale          50        0.92           1
                  dugong          50        0.84        0.96
                sea lion          50        0.82        0.92
               Chihuahua          50        0.66        0.84
           Japanese Chin          50        0.72        0.98
                 Maltese          50        0.76        0.94
               Pekingese          50        0.84        0.94
                Shih Tzu          50        0.74        0.96
    King Charles Spaniel          50        0.88        0.98
                Papillon          50        0.86        0.94
             toy terrier          50        0.48        0.94
     Rhodesian Ridgeback          50        0.76        0.98
            Afghan Hound          50        0.84           1
            Basset Hound          50         0.8        0.92
                  Beagle          50        0.82        0.96
              Bloodhound          50        0.48        0.72
      Bluetick Coonhound          50        0.86        0.94
 Black and Tan Coonhound          50        0.54         0.8
Treeing Walker Coonhound          50        0.66        0.98
        English foxhound          50        0.32        0.84
       Redbone Coonhound          50        0.62        0.94
                  borzoi          50        0.92           1
         Irish Wolfhound          50        0.48        0.88
       Italian Greyhound          50        0.76        0.98
                 Whippet          50        0.74        0.92
            Ibizan Hound          50         0.6        0.86
      Norwegian Elkhound          50        0.88        0.98
              Otterhound          50        0.62         0.9
                  Saluki          50        0.72        0.92
      Scottish Deerhound          50        0.86        0.98
              Weimaraner          50        0.88        0.94
Staffordshire Bull Terrier          50        0.66        0.98
American Staffordshire Terrier          50        0.64        0.92
      Bedlington Terrier          50         0.9        0.92
          Border Terrier          50        0.86        0.92
      Kerry Blue Terrier          50        0.78        0.98
           Irish Terrier          50         0.7        0.96
         Norfolk Terrier          50        0.68         0.9
         Norwich Terrier          50        0.72           1
       Yorkshire Terrier          50        0.66         0.9
        Wire Fox Terrier          50        0.64        0.98
        Lakeland Terrier          50        0.74        0.92
        Sealyham Terrier          50        0.76         0.9
        Airedale Terrier          50        0.82        0.92
           Cairn Terrier          50        0.76         0.9
      Australian Terrier          50        0.48        0.84
  Dandie Dinmont Terrier          50        0.82        0.92
          Boston Terrier          50        0.92           1
     Miniature Schnauzer          50        0.68         0.9
         Giant Schnauzer          50        0.72        0.98
      Standard Schnauzer          50        0.74           1
        Scottish Terrier          50        0.76        0.96
         Tibetan Terrier          50        0.48           1
Australian Silky Terrier          50        0.66        0.96
Soft-coated Wheaten Terrier          50        0.74        0.96
West Highland White Terrier          50        0.88        0.96
              Lhasa Apso          50        0.68        0.96
   Flat-Coated Retriever          50        0.72        0.94
  Curly-coated Retriever          50        0.82        0.94
        Golden Retriever          50        0.86        0.94
      Labrador Retriever          50        0.82        0.94
Chesapeake Bay Retriever          50        0.76        0.96
German Shorthaired Pointer          50         0.8        0.96
                  Vizsla          50        0.68        0.96
          English Setter          50         0.7           1
            Irish Setter          50         0.8         0.9
           Gordon Setter          50        0.84        0.92
                Brittany          50        0.84        0.96
         Clumber Spaniel          50        0.92        0.96
English Springer Spaniel          50        0.88           1
  Welsh Springer Spaniel          50        0.92           1
         Cocker Spaniels          50         0.7        0.94
          Sussex Spaniel          50        0.72        0.92
     Irish Water Spaniel          50        0.88        0.98
                  Kuvasz          50        0.66         0.9
              Schipperke          50         0.9        0.98
             Groenendael          50         0.8        0.94
                Malinois          50        0.86        0.98
                  Briard          50        0.52         0.8
       Australian Kelpie          50         0.6        0.88
                Komondor          50        0.88        0.94
    Old English Sheepdog          50        0.94        0.98
       Shetland Sheepdog          50        0.74         0.9
                  collie          50         0.6        0.96
           Border Collie          50        0.74        0.96
    Bouvier des Flandres          50        0.78        0.94
              Rottweiler          50        0.88        0.96
     German Shepherd Dog          50         0.8        0.98
               Dobermann          50        0.68        0.96
      Miniature Pinscher          50        0.76        0.88
Greater Swiss Mountain Dog          50        0.68        0.94
    Bernese Mountain Dog          50        0.96           1
  Appenzeller Sennenhund          50        0.22           1
  Entlebucher Sennenhund          50        0.64        0.98
                   Boxer          50         0.7        0.92
             Bullmastiff          50        0.78        0.98
         Tibetan Mastiff          50        0.88        0.96
          French Bulldog          50        0.84        0.94
              Great Dane          50        0.54         0.9
             St. Bernard          50        0.92           1
                   husky          50        0.46        0.98
        Alaskan Malamute          50        0.76        0.96
          Siberian Husky          50        0.46        0.98
               Dalmatian          50        0.94        0.98
           Affenpinscher          50        0.78         0.9
                 Basenji          50        0.92        0.94
                     pug          50        0.94        0.98
              Leonberger          50           1           1
            Newfoundland          50        0.78        0.96
   Pyrenean Mountain Dog          50        0.78        0.96
                 Samoyed          50        0.96           1
              Pomeranian          50        0.98           1
               Chow Chow          50         0.9        0.96
                Keeshond          50        0.88        0.94
      Griffon Bruxellois          50        0.84        0.98
    Pembroke Welsh Corgi          50        0.82        0.94
    Cardigan Welsh Corgi          50        0.66        0.98
              Toy Poodle          50        0.52        0.88
        Miniature Poodle          50        0.52        0.92
         Standard Poodle          50         0.8           1
    Mexican hairless dog          50        0.88        0.98
               grey wolf          50        0.82        0.92
     Alaskan tundra wolf          50        0.78        0.98
                red wolf          50        0.48         0.9
                  coyote          50        0.64        0.86
                   dingo          50        0.76        0.88
                   dhole          50         0.9        0.98
        African wild dog          50        0.98           1
                   hyena          50        0.88        0.96
                 red fox          50        0.54        0.92
                 kit fox          50        0.72        0.98
              Arctic fox          50        0.94           1
                grey fox          50         0.7        0.94
               tabby cat          50        0.54        0.92
               tiger cat          50        0.22        0.94
             Persian cat          50         0.9        0.98
             Siamese cat          50        0.96           1
            Egyptian Mau          50        0.54         0.8
                  cougar          50         0.9           1
                    lynx          50        0.72        0.88
                 leopard          50        0.78        0.98
            snow leopard          50         0.9        0.98
                  jaguar          50         0.7        0.94
                    lion          50         0.9        0.98
                   tiger          50        0.92        0.98
                 cheetah          50        0.94        0.98
              brown bear          50        0.94        0.98
     American black bear          50         0.8           1
              polar bear          50        0.84        0.96
              sloth bear          50        0.72        0.92
                mongoose          50         0.7        0.92
                 meerkat          50        0.82        0.92
            tiger beetle          50        0.92        0.94
                 ladybug          50        0.86        0.94
           ground beetle          50        0.64        0.94
         longhorn beetle          50        0.62        0.88
             leaf beetle          50        0.64        0.98
             dung beetle          50        0.86        0.98
       rhinoceros beetle          50        0.86        0.94
                  weevil          50         0.9           1
                     fly          50        0.78        0.94
                     bee          50        0.68        0.94
                     ant          50        0.68        0.78
             grasshopper          50         0.5        0.92
                 cricket          50        0.64        0.92
            stick insect          50        0.64        0.92
               cockroach          50        0.72         0.8
                  mantis          50        0.64        0.86
                  cicada          50         0.9        0.96
              leafhopper          50        0.88        0.94
        

3. Train

Close the active learning loop by sampling images from your inference conditions with the roboflow pip package


Train a YOLOv5s Classification model on the Imagenette dataset with --data imagenet, starting from pretrained --pretrained yolov5s-cls.pt.

  • Pretrained Models are downloaded
    automatically from the latest YOLOv5 release
  • Training Results are saved to runs/train-cls/ with incrementing run directories, i.e. runs/train-cls/exp2, runs/train-cls/exp3 etc.


A Mosaic Dataloader is used for training which combines 4 images into 1 mosaic.

Train on Custom Data with Roboflow 🌟 NEW

Roboflow enables you to easily organize, label, and prepare a high quality dataset with your own custom data. Roboflow also makes it easy to establish an active learning pipeline, collaborate with your team on dataset improvement, and integrate directly into your model building workflow with the roboflow pip package.

Label images lightning fast (including with model-assisted labeling)

#@title Select YOLOv5 🚀 logger {run: 'auto'}
logger = 'Comet' #@param ['Comet', 'ClearML', 'TensorBoard']

if logger == 'Comet':
  %pip install -q comet_ml
  import comet_ml; comet_ml.init()
elif logger == 'ClearML':
  %pip install -q clearml
  import clearml; clearml.browser_login()
elif logger == 'TensorBoard':
  %load_ext tensorboard
  %tensorboard --logdir runs/train
# Train YOLOv5s Classification on Imagenette160 for 3 epochs
!python classify/train.py --model yolov5s-cls.pt --data imagenette160 --epochs 5 --img 224 --cache
classify/train: model=yolov5s-cls.pt, data=imagenette160, epochs=5, batch_size=64, imgsz=224, nosave=False, cache=ram, device=, workers=8, project=runs/train-cls, name=exp, exist_ok=False, pretrained=True, optimizer=Adam, lr0=0.001, decay=5e-05, label_smoothing=0.1, cutoff=None, dropout=None, verbose=False, seed=0, local_rank=-1
github: up to date with https://github.com/ultralytics/yolov5 ✅
YOLOv5 🚀 v7.0-3-g61ebf5e Python-3.7.15 torch-1.12.1+cu113 CUDA:0 (Tesla T4, 15110MiB)

TensorBoard: Start with 'tensorboard --logdir runs/train-cls', view at http://localhost:6006/

Dataset not found ⚠️, missing path /content/datasets/imagenette160, attempting download...
Downloading https://github.com/ultralytics/yolov5/releases/download/v1.0/imagenette160.zip to /content/datasets/imagenette160.zip...
100% 103M/103M [00:00<00:00, 347MB/s] 
Unzipping /content/datasets/imagenette160.zip...
Dataset download success ✅ (3.3s), saved to /content/datasets/imagenette160

albumentations: RandomResizedCrop(p=1.0, height=224, width=224, scale=(0.08, 1.0), ratio=(0.75, 1.3333333333333333), interpolation=1), HorizontalFlip(p=0.5), ColorJitter(p=0.5, brightness=[0.6, 1.4], contrast=[0.6, 1.4], saturation=[0.6, 1.4], hue=[0, 0]), Normalize(p=1.0, mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225), max_pixel_value=255.0), ToTensorV2(always_apply=True, p=1.0, transpose_mask=False)
Model summary: 149 layers, 4185290 parameters, 4185290 gradients, 10.5 GFLOPs
optimizer: Adam(lr=0.001) with parameter groups 32 weight(decay=0.0), 33 weight(decay=5e-05), 33 bias
Image sizes 224 train, 224 test
Using 1 dataloader workers
Logging results to runs/train-cls/exp
Starting yolov5s-cls.pt training on imagenette160 dataset with 10 classes for 5 epochs...

     Epoch   GPU_mem  train_loss    val_loss    top1_acc    top5_acc
       1/5     1.47G        1.05       0.974       0.828       0.975: 100% 148/148 [00:38<00:00,  3.82it/s]
       2/5     1.73G       0.895       0.766       0.911       0.994: 100% 148/148 [00:36<00:00,  4.03it/s]
       3/5     1.73G        0.82       0.704       0.934       0.996: 100% 148/148 [00:35<00:00,  4.20it/s]
       4/5     1.73G       0.766       0.664       0.951       0.998: 100% 148/148 [00:36<00:00,  4.05it/s]
       5/5     1.73G       0.724       0.634       0.959       0.997: 100% 148/148 [00:37<00:00,  3.94it/s]

Training complete (0.052 hours)
Results saved to runs/train-cls/exp
Predict:         python classify/predict.py --weights runs/train-cls/exp/weights/best.pt --source im.jpg
Validate:        python classify/val.py --weights runs/train-cls/exp/weights/best.pt --data /content/datasets/imagenette160
Export:          python export.py --weights runs/train-cls/exp/weights/best.pt --include onnx
PyTorch Hub:     model = torch.hub.load('ultralytics/yolov5', 'custom', 'runs/train-cls/exp/weights/best.pt')
Visualize:       https://netron.app

4. Visualize

Comet Logging and Visualization 🌟 NEW

Comet is now fully integrated with YOLOv5. Track and visualize model metrics in real time, save your hyperparameters, datasets, and model checkpoints, and visualize your model predictions with Comet Custom Panels! Comet makes sure you never lose track of your work and makes it easy to share results and collaborate across teams of all sizes!

Getting started is easy:

pip install comet_ml  # 1. install
export COMET_API_KEY=<Your API Key>  # 2. paste API key
python train.py --img 640 --epochs 3 --data coco128.yaml --weights yolov5s.pt  # 3. train

To learn more about all of the supported Comet features for this integration, check out the Comet Tutorial. If you'd like to learn more about Comet, head over to our documentation. Get started by trying out the Comet Colab Notebook:
Open In Colab


Comet Dashboard

ClearML Logging and Automation 🌟 NEW

ClearML is completely integrated into YOLOv5 to track your experimentation, manage dataset versions and even remotely execute training runs. To enable ClearML (check cells above):

You'll get all the great expected features from an experiment manager: live updates, model upload, experiment comparison etc. but ClearML also tracks uncommitted changes and installed packages for example. Thanks to that ClearML Tasks (which is what we call experiments) are also reproducible on different machines! With only 1 extra line, we can schedule a YOLOv5 training task on a queue to be executed by any number of ClearML Agents (workers).

You can use ClearML Data to version your dataset and then pass it to YOLOv5 simply using its unique ID. This will help you keep track of your data without adding extra hassle. Explore the ClearML Tutorial for details!


ClearML Experiment Management UI

Local Logging

Training results are automatically logged with Tensorboard and CSV loggers to runs/train, with a new experiment directory created for each new training as runs/train/exp2, runs/train/exp3, etc.

This directory contains train and val statistics, mosaics, labels, predictions and augmentated mosaics, as well as metrics and charts including precision-recall (PR) curves and confusion matrices.

Local logging results

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), testing (val.py), inference (detect.py) and export (export.py) on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Appendix

Additional content below.

# YOLOv5 PyTorch HUB Inference (DetectionModels only)
import torch

model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True, trust_repo=True)  # or yolov5n - yolov5x6 or custom
im = 'https://ultralytics.com/images/zidane.jpg'  # file, Path, PIL.Image, OpenCV, nparray, list
results = model(im)  # inference
results.print()  # or .show(), .save(), .crop(), .pandas(), etc.