解决ultralytics中的YOLOv8在执行task.py文件添加模块操作出现的KeyError报错
报错详情:
在ultralytics
项目文件夹内运行/home/xxx/ultralytics/train.py
进行单GPU训练的时候训练可以正常进行
from ultralytics import YOLO
# Load a model
model = YOLO("/home/xxx/ultralytics/ultralytics/cfg/models/v8/yolov8s-FASFF.yaml") #
# Train the model
results = model.train(data="/home/xxx/ultralytics/ultralytics/cfg/datasets/VisDrone.yaml", device='1', batch=5, epochs=200, imgsz=640)
但是启动多GPU后训练就会发生KeyEroor
报错
# Train the model
results = model.train(data="/home/xxx/ultralytics/ultralytics/cfg/datasets/VisDrone.yaml", device='0,1,2', batch=15, epochs=200, imgsz=640)
解决方案:
将项目文件夹ultralytics
内的task.py
和虚拟环境模块包内的task.py
同时做类似如下的代码配置
/home/xxx/ultralytics/ultralytics/nn/tasks.py
/home/xxx/anaconda3/envs/openmmlab/lib/python3.8/site-packages/ultralytics/nn/tasks.py
问题即可迎刃而解!