python3.10,pytorch1.13,显卡1650 , yolov8版本 __version__ = '8.0.117'
yolov8n在train时,出现box_loss、cls_loss、dfl_loss为nan
model.train设置amp=False
model.train(data='VOC.yaml', epochs=100, imgsz=640, device=[0], batch=4, workers=0, amp=False)
修改后 box_loss、cls_loss、dfl_loss显示数值,不是nan
Box(P R mAP50 mAP50-95)为0 的问题
解决办法:
修改
ultralytics/yolo/cfg/default.yaml 第49行 half 为 False
half: False # use half precision (FP16)
并注释掉ultralytics/yolo/engine/validator.py 中第102行代码 # self.args.half = self.device.type != 'cpu' 将self.args.half的值设置为False
self.training = trainer is not None
if self.training:
self.device = trainer.device
self.data = trainer.data
model = trainer.ema.ema or trainer.model
# self.args.half = self.device.type != 'cpu' # force FP16 val during training
self.model = model
self.loss = torch.zeros_like(trainer.loss_items, device=trainer.device)
self.args.plots = trainer.stopper.poss