You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

YOLOv8自定义数据集训练无预测结果问题求助

YOLOv8 Custom Airplane Dataset Training: No Predictions & Low Metrics

Problem Overview

I got interested in YOLOv8, tried training a custom airplane dataset after watching several YouTube tutorials, but got no prediction results at all after completing all operations. The second image is val_batch0_labels, and the third is val_batch0_pred. I've tried this in both PyCharm and Google Colab with the same result.

Code Snippets

main.py

from ultralytics import YOLO

model = YOLO("yolov8n.yaml")

results = model.train(data="config.yaml", epochs=1)

config.yaml

path: Y:\coding\python\yolo_test\data_airplane\data # dataset root dir
train: images  # train images (relative to 'path')
val: images  # val images (relative to 'path')

# Classes
names:
  0: airplane

Full Training Log

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

Ultralytics YOLOv8.0.141  Python-3.10.8 torch-2.0.1+cpu CPU (Intel Core(TM) i3-10105F 3.70GHz)
engine\trainer: task=detect, mode=train, model=yolov8n.yaml, data=config.yaml, epochs=1, patience=50, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=None, 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, 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, show=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, vid_stride=1, line_width=None, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, boxes=True, 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, cfg=None, tracker=botsort.yaml, save_dir=runs\detect\train22
Overriding model.yaml nc=80 with nc=1

               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    751507  ultralytics.nn.modules.head.Detect           [1, [64, 128, 256]]
YOLOv8n summary: 225 layers, 3011043 parameters, 3011027 gradients

train: Scanning Y:\coding\python\yolo_test\data_airplane\data\labels.cache... 3 images, 0 backgrounds, 0 corrupt: 100%|██████████| 3/3 [00:00<?, ?it/s]
val: Scanning Y:\coding\python\yolo_test\data_airplane\data\labels.cache... 3 images, 0 backgrounds, 0 corrupt: 100%|██████████| 3/3 [00:00<?, ?it/s]
Plotting labels to runs\detect\train22\labels.jpg...
optimizer: AdamW(lr=0.002, momentum=0.9) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias(decay=0.0)
Image sizes 640 train, 640 val
Using 0 dataloader workers
Logging results to runs\detect\train22
Starting training for 1 epochs..

  Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
    1/1         0G      3.156      3.899      4.605         33        640: 100%|██████████| 1/1 [00:02<00:00,  2.21s/it]
             Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:01<00:00,  1.14s/it]
               all          3         16    0.00111     0.0625   0.000607   6.07e-05
1 epochs completed in 0.001 hours.
Optimizer stripped from runs\detect\train22\weights\last.pt, 6.2MB
Optimizer stripped from runs\detect\train22\weights\best.pt, 6.2MB

Validating runs\detect\train22\weights\best.pt...
Ultralytics YOLOv8.0.141  Python-3.10.8 torch-2.0.1+cpu CPU (Intel Core(TM) i3-10105F 3.70GHz)
YOLOv8n summary (fused): 168 layers, 3005843 parameters, 0 gradients
Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 1/1 [00:01<00:00,  1.08s/it]
all          3         16    0.00114     0.0625    0.00086    8.6e-05
Speed: 2.0ms preprocess, 123.7ms inference, 0.0ms loss, 1.7ms postprocess per image
Results saved to runs\detect\train22

Process finished with exit code 0

Key Issues & Fixes

  1. Tiny Dataset Size
    The log shows only 3 images for both training and validation. YOLO models need at least 100+ labeled images per class (500+ is ideal) to learn consistent features. With 3 images, the model can’t generalize to any unseen data.

  2. Insufficient Training Epochs
    Training for 1 epoch is not enough for the model to learn anything meaningful. Even small datasets require 50-100 epochs to converge. Start with 50 epochs and stop when validation loss stops improving.

  3. No Train/Validation Split
    Using the same folder for train and val data means you’re testing on the exact images you trained on. This gives misleading metrics and prevents you from evaluating real-world performance. Split your data into 80% train, 20% val folders.

  4. Starting from Blank Architecture
    Initializing from yolov8n.yaml creates a fresh, untrained model. Using pretrained weights (yolov8n.pt) leverages learned features from COCO, which drastically speeds up convergence on small datasets.

  5. Dataset Structure & Label Checks
    Confirm your dataset follows YOLO format:

    • Each image has a matching .txt label file with the same name
    • Labels use normalized coordinates: class_id x_center y_center width height (values between 0-1)
    • No missing or corrupted label files
  6. CPU Training Limitations
    Training on CPU is slow and restricts how many epochs you can run. Use a GPU (Google Colab offers free access) to speed up training and allow proper convergence.

Step-by-Step Fix

  1. Expand your dataset to at least 100 labeled airplane images
  2. Split into train/images and val/images subfolders under your data directory
  3. Update config.yaml:
    path: Y:\coding\python\yolo_test\data_airplane\data
    train: train/images
    val: val/images
    names:
      0: airplane
    
  4. Use pretrained weights and increase epochs:
    from ultralytics import YOLO
    
    model = YOLO("yolov8n.pt")
    results = model.train(data="config.yaml", epochs=50, imgsz=640, batch=8)
    
  5. Run training on a GPU for faster convergence

Content sourced from Stack Exchange, question author: zltx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 07:03:37