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

新手技术求助:如何在Google Colab上训练YOLOv3-tiny/YOLOv4-tiny用于自主无人机项目(附训练报错日志)

YOLOv4-tiny Training Guide for Drone Project (Colab)

Hey there! I see you're a new programmer working on a drone project and hitting snags training YOLOv4-tiny on Google Colab. Let's walk through fixing this and get your model up and running smoothly.

First, Let's Break Down Your Log Output

Looking at the logs you shared, the good news is that the model successfully loaded the pre-trained weights (yolov4-tiny.conv.29) and initialized the training environment. The actual crash might be happening after these setup steps—you might have missed pasting the full error trace. But let's cover the most common pitfalls for your setup right now.

Step-by-Step Training Troubleshooting & Guidance

1. Double-Check Your Dataset Format

YOLO relies on a strict structure for training—get this right and you'll avoid 80% of issues:

  • Each image (e.g., drone_001.jpg) must have a matching annotation file (drone_001.txt) in the same folder.
  • Each line in the .txt annotation must follow: class_id x_center y_center width height (all values normalized to 0-1, not raw pixel coordinates).
  • Verify your obj.data file:
    • Ensure classes matches the number of drone-related classes you're detecting. From your log, each yolo layer outputs 18 filters—since each layer uses (num_classes + 5) * 3 filters, this means you've set num_classes=1; confirm this is correct for your project.
    • Make sure train, valid, and names paths point to the correct files in your Google Drive/Colab workspace.

2. Tweak Colab & Model Config for Your GPU

Your log shows you're using a Tesla K80, which has limited VRAM—adjust these settings to avoid crashes:

  • Confirm GPU Acceleration: Go to Runtime > Change runtime type > Hardware accelerator > GPU and save. Sometimes Colab resets this, so double-check it's enabled.
  • Adjust Batch & Resolution:
    • Open your yolov4-tiny-custom.cfg file and set batch=32, subdivisions=16 (subdivisions splits the batch into smaller chunks to fit VRAM).
    • If you hit an Out-of-Memory (OOM) error later, reduce input resolution to width=320, height=320 (must be multiples of 32).
  • Recompile Darknet with GPU Support: If you haven't already, ensure Darknet is built for GPU:
    cd darknet
    sed -i 's/GPU=0/GPU=1/' Makefile
    sed -i 's/CUDNN=0/CUDNN=1/' Makefile
    sed -i 's/OPENCV=0/OPENCV=1/' Makefile
    make
    

3. Fix Your Training Command

Make sure your command points to the right files. A standard working command for your setup looks like this:

./darknet detector train data/obj.data cfg/yolov4-tiny-custom.cfg yolov4-tiny.conv.29 -dont_show -map
  • -dont_show hides the GUI (Colab doesn't support it), -map calculates mAP during training to track how well your model is performing.

If you prefer a step-by-step, video-like flow, follow these exact steps in Colab:

  1. Mount Google Drive:
    from google.colab import drive
    drive.mount('/content/drive')
    
  2. Clone the Darknet Repository:
    !git clone https://github.com/AlexeyAB/darknet.git
    
  3. Compile Darknet with GPU Support: Run the compile commands from section 2 above.
  4. Prepare Your Dataset:
    • Upload your 850 images and 1700 annotation files to a folder named obj in your Drive.
    • Create train.txt and valid.txt (split your dataset 80-20 for train/validation) with full paths to each image (e.g., /content/drive/MyDrive/dataset/obj/drone_001.jpg).
  5. Configure Model Files:
    • Copy cfg/yolov4-tiny.cfg to cfg/yolov4-tiny-custom.cfg.
    • In the custom cfg:
      • Set classes=1 (or your actual number of classes) in both [yolo] layers.
      • Set filters=(classes + 5)*3 in the [conv] layers right before each [yolo] layer (for 1 class, this is 18—matches your log, so that's correct).
      • Set batch=32, subdivisions=16 under [net].
    • Create data/obj.data:
      classes=1
      train=/content/drive/MyDrive/dataset/train.txt
      valid=/content/drive/MyDrive/dataset/valid.txt
      names=data/obj.names
      backup=/content/drive/MyDrive/dataset/backup/
      
    • Create data/obj.names with your class name (e.g., drone).
  6. Download Pre-trained Weights:
    !wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4-tiny.conv.29
    
  7. Start Training: Run the training command from section 3.

Final Quick Tips

  • Monitor the training loss: It should decrease over time—aim for a loss below 0.5 for solid performance.
  • Check the backup folder in your Drive: Darknet saves weights every few epochs; use the latest _last.weights or _best.weights for inference on your drone.

内容的提问来源于stack exchange,提问作者HalilYLMZ

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.06 06:57:34