YOLOV8在coco128上的训练

coco128是coco数据集的子集只有128张图片

训练代码main.py

from ultralytics import YOLO

# Load a model
model = YOLO("yolov8n.yaml")  # build a new model from scratch
model = YOLO("yolov8n.pt")  # load a pretrained model (recommended for training)

# Use the model
model.train(data="coco128.yaml", epochs=3)  # train the model
metrics = model.val()  # evaluate model performance on the validation set
results = model("https://ultralytics.com/images/bus.jpg")  # predict on an image
path = model.export(format="onnx")  # export the model to ONNX format

(yolov8) nvidia@nvidia-desktop:~/yolov8$ python main.py

                   from  n    params  module                                       arguments
  0                  -1  1       464  ultralytics.nn.modules.conv.Conv             [3, 16, 3, 2]
  1                  -1  1      4672  ultralytics.nn.modules.conv.Conv             [16, 32, 3, 2]
  2                  -1  1      7360  ultralytics.nn.modules.block.C2f             [32, 32, 1, True]
  3                  -1  1     18560  ultralytics.nn.modules.conv.Conv             [32, 64, 3, 2]
  4                  -1  2     49664  ultralytics.nn.modules.block.C2f             [64, 64, 2, True]
  5                  -1  1     73984  ultralytics.nn.modules.conv.Conv             [64, 128, 3, 2]
  6                  -1  2    197632  ultralytics.nn.modules.block.C2f             [128, 128, 2, True]
  7                  -1  1    295424  ultralytics.nn.modules.conv.Conv             [128, 256, 3, 2]
  8                  -1  1    460288  ultralytics.nn.modules.block.C2f             [256, 256, 1, True]
  9                  -1  1    164608  ultralytics.nn.modules.block.SPPF            [256, 256, 5]
 10                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 11             [-1, 6]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 12                  -1  1    148224  ultralytics.nn.modules.block.C2f             [384, 128, 1]
 13                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 14             [-1, 4]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 15                  -1  1     37248  ultralytics.nn.modules.block.C2f             [192, 64, 1]
 16                  -1  1     36992  ultralytics.nn.modules.conv.Conv             [64, 64, 3, 2]
 17            [-1, 12]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 18                  -1  1    123648  ultralytics.nn.modules.block.C2f             [192, 128, 1]
 19                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]
 20             [-1, 9]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 21                  -1  1    493056  ultralytics.nn.modules.block.C2f             [384, 256, 1]
 22        [15, 18, 21]  1    897664  ultralytics.nn.modules.head.Detect           [80, [64, 128, 256]]
YOLOv8n summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPs

New https://pypi.org/project/ultralytics/8.1.1 available Update with 'pip install -U ultralytics'
Ultralytics YOLOv8.1.0 Python-3.10.13 torch-2.0.1+cu117 CUDA:0 (NVIDIA GeForce RTX 4060 Ti, 16081MiB)
engine/trainer: task=detect, mode=train, model=yolov8n.pt, data=coco128.yaml, epochs=3, time=None, patience=50, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=train3, exist_ok=False, pretrained=True, optimizer=auto, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, amp=True, fraction=1.0, profile=False, freeze=None, multi_scale=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, vid_stride=1, stream_buffer=False, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, embed=None, show=False, save_frames=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, show_boxes=True, line_width=None, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=None, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0, auto_augment=randaugment, erasing=0.4, crop_fraction=1.0, cfg=None, tracker=botsort.yaml, save_dir=runs/detect/train3

                   from  n    params  module                                       arguments
  0                  -1  1       464  ultralytics.nn.modules.conv.Conv             [3, 16, 3, 2]
  1                  -1  1      4672  ultralytics.nn.modules.conv.Conv             [16, 32, 3, 2]
  2                  -1  1      7360  ultralytics.nn.modules.block.C2f             [32, 32, 1, True]
  3                  -1  1     18560  ultralytics.nn.modules.conv.Conv             [32, 64, 3, 2]
  4                  -1  2     49664  ultralytics.nn.modules.block.C2f             [64, 64, 2, True]
  5                  -1  1     73984  ultralytics.nn.modules.conv.Conv             [64, 128, 3, 2]
  6                  -1  2    197632  ultralytics.nn.modules.block.C2f             [128, 128, 2, True]
  7                  -1  1    295424  ultralytics.nn.modules.conv.Conv             [128, 256, 3, 2]
  8                  -1  1    460288  ultralytics.nn.modules.block.C2f             [256, 256, 1, True]
  9                  -1  1    164608  ultralytics.nn.modules.block.SPPF            [256, 256, 5]
 10                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 11             [-1, 6]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 12                  -1  1    148224  ultralytics.nn.modules.block.C2f             [384, 128, 1]
 13                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 14             [-1, 4]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 15                  -1  1     37248  ultralytics.nn.modules.block.C2f             [192, 64, 1]
 16                  -1  1     36992  ultralytics.nn.modules.conv.Conv             [64, 64, 3, 2]
 17            [-1, 12]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 18                  -1  1    123648  ultralytics.nn.modules.block.C2f             [192, 128, 1]
 19                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]
 20             [-1, 9]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 21                  -1  1    493056  ultralytics.nn.modules.block.C2f             [384, 256, 1]
 22        [15, 18, 21]  1    897664  ultralytics.nn.modules.head.Detect           [80, [64, 128, 256]]
Model summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPs

Transferred 355/355 items from pretrained weights
Freezing layer 'model.22.dfl.conv.weight'
AMP: running Automatic Mixed Precision (AMP) checks with YOLOv8n...
AMP: checks passed ✅
train: Scanning /home/nvidia/datasets/coco128/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/12
val: Scanning /home/nvidia/datasets/coco128/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/128
Plotting labels to runs/detect/train3/labels.jpg...
optimizer: 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining best 'optimizer', 'lr0' and 'momentum' automatically...
optimizer: AdamW(lr=0.000119, momentum=0.9) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias(decay=0.0)
3 epochs...

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
        1/3      2.66G      1.226      1.615      1.274        178        640: 100%|██████████| 8/8 [00:03<00:00,  2.63it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 4/4 [00:00<00:00,  4.44it/
                   all        128        929      0.645      0.533      0.614      0.455

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
        2/3      2.67G      1.225      1.514      1.268        231        640: 100%|██████████| 8/8 [00:01<00:00,  5.24it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 4/4 [00:00<00:00,  5.06it/
                   all        128        929      0.675      0.538      0.626      0.467

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
        3/3      2.71G      1.209      1.448      1.222        178        640: 100%|██████████| 8/8 [00:01<00:00,  5.52it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 4/4 [00:00<00:00,  4.99it/
                   all        128        929      0.676      0.548      0.632       0.47

3 epochs completed in 0.003 hours.
Optimizer stripped from runs/detect/train3/weights/last.pt, 6.5MB
Optimizer stripped from runs/detect/train3/weights/best.pt, 6.5MB

Validating runs/detect/train3/weights/best.pt...
Ultralytics YOLOv8.1.0 Python-3.10.13 torch-2.0.1+cu117 CUDA:0 (NVIDIA GeForce RTX 4060 Ti, 16081MiB)
Model summary (fused): 168 layers, 3151904 parameters, 0 gradients, 8.7 GFLOPs
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 4/4 [00:03<00:00,  1.13it/
                   all        128        929      0.675      0.549      0.632      0.469
                person        128        254      0.802      0.671      0.769      0.542
               bicycle        128          6      0.581      0.333      0.332      0.286
                   car        128         46      0.844      0.217      0.285      0.178
            motorcycle        128          5      0.687      0.886      0.938      0.721
              airplane        128          6      0.826      0.799      0.903      0.673
                   bus        128          7      0.745      0.714      0.736      0.648
                 train        128          3      0.556      0.667       0.83      0.731
                 truck        128         12          1      0.353      0.498      0.304
                  boat        128          6      0.293      0.167      0.351      0.225
         traffic light        128         14      0.696      0.168      0.202      0.139
             stop sign        128          2      0.966          1      0.995      0.711
                 bench        128          9      0.838      0.575      0.637        0.4
                  bird        128         16      0.923      0.748       0.88       0.53
                   cat        128          4      0.866          1      0.995      0.835
                   dog        128          9      0.704      0.778      0.821      0.633
                 horse        128          2      0.536          1      0.995      0.511
              elephant        128         17      0.851      0.765      0.879      0.669
                  bear        128          1      0.631          1      0.995      0.995
                 zebra        128          4      0.857          1      0.995      0.965
               giraffe        128          9      0.899      0.993      0.973      0.714
              backpack        128          6      0.605      0.333      0.392      0.234
              umbrella        128         18       0.71        0.5      0.663      0.453
               handbag        128         19      0.518     0.0582       0.18     0.0947
                   tie        128          7       0.69      0.642      0.641      0.457
              suitcase        128          4      0.641          1      0.828      0.596
               frisbee        128          5      0.567        0.8      0.759      0.663
                  skis        128          1      0.473          1      0.995      0.497
             snowboard        128          7      0.661      0.714      0.755      0.486
           sports ball        128          6      0.703      0.406      0.503       0.29
                  kite        128         10      0.811        0.5      0.595      0.208
          baseball bat        128          4      0.574      0.362      0.414      0.174
        baseball glove        128          7      0.672      0.429      0.429      0.295
            skateboard        128          5      0.776        0.6        0.6       0.44
         tennis racket        128          7      0.742      0.415      0.529      0.367
                bottle        128         18      0.508      0.389      0.394       0.24
            wine glass        128         16      0.584      0.562      0.581      0.361
                   cup        128         36      0.632      0.287        0.4      0.279
                  fork        128          6      0.597      0.167      0.264      0.193
                 knife        128         16      0.643        0.5      0.612      0.351
                 spoon        128         22      0.554      0.182      0.332       0.18
                  bowl        128         28      0.676      0.571      0.615      0.495
                banana        128          1          0          0      0.166      0.048
              sandwich        128          2      0.394        0.5      0.497      0.497
                orange        128          4          1      0.313      0.995      0.666
              broccoli        128         11      0.471      0.182      0.247      0.221
                carrot        128         24      0.739      0.458      0.658      0.411
               hot dog        128          2       0.65       0.95      0.828      0.796
                 pizza        128          5      0.689          1      0.995       0.86
                 donut        128         14      0.639          1      0.946      0.859
                  cake        128          4      0.658          1      0.995       0.88
                 chair        128         35      0.514      0.514      0.468      0.262
                 couch        128          6      0.746      0.493      0.673      0.497
          potted plant        128         14      0.739      0.643      0.722      0.484
                   bed        128          3      0.768      0.667      0.806      0.636
          dining table        128         13      0.484      0.615      0.504      0.415
                toilet        128          2          1      0.869      0.995      0.946
                    tv        128          2      0.384        0.5      0.695      0.656
                laptop        128          3          1          0      0.696      0.544
                 mouse        128          2          1          0     0.0527    0.00527
                remote        128          8      0.849        0.5      0.583      0.507
            cell phone        128          8          0          0     0.0688     0.0465
             microwave        128          3       0.63      0.667      0.863      0.719
                  oven        128          5      0.472        0.4      0.338      0.269
                  sink        128          6      0.367      0.167      0.232      0.159
          refrigerator        128          5      0.688        0.4      0.647      0.525
                  book        128         29      0.621      0.114      0.328      0.187
                 clock        128          9      0.779      0.781      0.893      0.713
                  vase        128          2      0.418          1      0.828      0.745
              scissors        128          1          1          0      0.249     0.0746
            teddy bear        128         21      0.884      0.381       0.64      0.429
            toothbrush        128          5        0.9        0.6      0.786      0.503
Speed: 3.0ms preprocess, 1.8ms inference, 0.0ms loss, 1.2ms postprocess per image
Results saved to runs/detect/train3
Ultralytics YOLOv8.1.0 Python-3.10.13 torch-2.0.1+cu117 CUDA:0 (NVIDIA GeForce RTX 4060 Ti, 16081MiB)
Model summary (fused): 168 layers, 3151904 parameters, 0 gradients, 8.7 GFLOPs
val: Scanning /home/nvidia/datasets/coco128/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/128
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 8/8 [00:03<00:00,  2.06it/
                   all        128        929      0.658      0.548      0.627      0.466
                person        128        254      0.808       0.68      0.773      0.542
               bicycle        128          6      0.569      0.333      0.326      0.283
                   car        128         46      0.805      0.217      0.285      0.178
            motorcycle        128          5      0.689      0.896      0.898      0.697
              airplane        128          6      0.827      0.803      0.903      0.681
                   bus        128          7      0.681      0.714      0.736      0.648
                 train        128          3      0.551      0.667       0.83      0.731
                 truck        128         12          1      0.374      0.494      0.295
                  boat        128          6      0.261      0.167      0.324       0.14
         traffic light        128         14      0.696      0.168      0.202      0.139
             stop sign        128          2       0.93          1      0.995      0.711
                 bench        128          9      0.842      0.596      0.636        0.4
                  bird        128         16      0.853       0.75      0.866        0.5
                   cat        128          4      0.863          1      0.995      0.835
                   dog        128          9      0.682      0.778      0.821      0.626
                 horse        128          2       0.53          1      0.995      0.515
              elephant        128         17      0.849      0.765      0.879      0.669
                  bear        128          1      0.626          1      0.995      0.995
                 zebra        128          4      0.854          1      0.995      0.965
               giraffe        128          9      0.744      0.971      0.943      0.732
              backpack        128          6      0.613      0.333      0.391      0.238
              umbrella        128         18      0.675        0.5      0.657      0.453
               handbag        128         19      0.554     0.0698      0.173     0.0932
                   tie        128          7      0.698      0.665      0.641      0.457
              suitcase        128          4      0.633          1      0.828      0.596
               frisbee        128          5      0.563        0.8      0.759      0.663
                  skis        128          1      0.461          1      0.995      0.497
             snowboard        128          7      0.657      0.714      0.757      0.484
           sports ball        128          6      0.705      0.411      0.502      0.274
                  kite        128         10      0.801        0.5      0.598      0.206
          baseball bat        128          4      0.577       0.25      0.348      0.174
        baseball glove        128          7      0.638      0.429      0.429      0.295
            skateboard        128          5      0.871        0.6        0.6       0.44
         tennis racket        128          7      0.744      0.419      0.529      0.365
                bottle        128         18      0.469      0.389      0.358      0.217
            wine glass        128         16      0.574      0.562      0.554      0.347
                   cup        128         36      0.566      0.278      0.401      0.286
                  fork        128          6       0.59      0.167      0.228      0.195
                 knife        128         16      0.563        0.5      0.587      0.358
                 spoon        128         22      0.633      0.182      0.331      0.186
                  bowl        128         28      0.737      0.643      0.658      0.498
                banana        128          1          0          0     0.0995      0.042
              sandwich        128          2      0.161      0.241      0.497      0.497
                orange        128          4          1      0.321      0.995      0.666
              broccoli        128         11      0.501      0.182      0.257      0.207
                carrot        128         24      0.728      0.558      0.653      0.418
               hot dog        128          2      0.649      0.946      0.828      0.796
                 pizza        128          5      0.717          1      0.995       0.86
                 donut        128         14      0.637          1       0.94      0.854
                  cake        128          4       0.61          1      0.945      0.845
                 chair        128         35      0.484      0.543      0.472      0.258
                 couch        128          6      0.613        0.5      0.745      0.578
          potted plant        128         14      0.716      0.643      0.723      0.481
                   bed        128          3      0.757      0.667      0.913      0.661
          dining table        128         13      0.457      0.615      0.496      0.391
                toilet        128          2          1      0.875      0.995      0.946
                    tv        128          2      0.378        0.5      0.695      0.656
                laptop        128          3          1          0      0.605      0.484
                 mouse        128          2          1          0     0.0698    0.00698
                remote        128          8      0.845        0.5      0.605      0.514
            cell phone        128          8          0          0     0.0696     0.0469
             microwave        128          3      0.617      0.667      0.863      0.733
                  oven        128          5      0.431        0.4      0.339       0.27
                  sink        128          6      0.378      0.167       0.18      0.131
          refrigerator        128          5      0.684        0.4       0.65      0.517
                  book        128         29      0.637      0.122      0.343      0.195
                 clock        128          9       0.78      0.788      0.894      0.734
                  vase        128          2      0.407          1      0.828      0.745
              scissors        128          1          1          0      0.249     0.0746
            teddy bear        128         21      0.883      0.381      0.634       0.42
            toothbrush        128          5      0.636        0.6      0.736      0.468
Speed: 3.4ms preprocess, 13.3ms inference, 0.0ms loss, 3.5ms postprocess per image
Results saved to runs/detect/train32

Found https://ultralytics.com/images/bus.jpg locally at bus.jpg
image 1/1 /home/nvidia/yolov8/bus.jpg: 640x480 4 persons, 1 bus, 1 stop sign, 17.2ms
Speed: 4.8ms preprocess, 17.2ms inference, 3.0ms postprocess per image at shape (1, 3, 640, 480)
Ultralytics YOLOv8.1.0 Python-3.10.13 torch-2.0.1+cu117 CPU (Intel Xeon E5-2686 v4 2.30GHz)

PyTorch: starting from 'runs/detect/train3/weights/best.pt' with input shape (1, 3, 640, 640) BCHW and output shape(s) (1, 84, 8400) (6.2 MB)

ONNX: starting export with onnx 1.15.0 opset 17...
============= Diagnostic Run torch.onnx.export version 2.0.1+cu117 =============
verbose: False, log level: Level.ERROR
======================= 0 NONE 0 NOTE 0 WARNING 0 ERROR ========================

ONNX: export success ✅ 0.9s, saved as 'runs/detect/train3/weights/best.onnx' (12.2 MB)

Export complete (2.4s)
Results saved to /home/nvidia/yolov8/runs/detect/train3/weights
Predict:         yolo predict task=detect model=runs/detect/train3/weights/best.onnx imgsz=640
Validate:        yolo val task=detect model=runs/detect/train3/weights/best.onnx imgsz=640 data=/home/nvidia/anaconda3/envs/yolov8/lib/python3.10/site-packages/ultralytics/cfg/datasets/coco128.yaml
Visualize:       https://netron.app 可视化网站

你可能感兴趣的:(AI笔记,YOLO,python,人工智能)