将train.py文件中的:
if RANK in {-1, 0}:
# mAP
callbacks.run('on_train_epoch_end', epoch=epoch)
ema.update_attr(model, include=['yaml', 'nc', 'hyp', 'names', 'stride', 'class_weights'])
final_epoch = (epoch + 1 == epochs) or stopper.possible_stop
if not noval or final_epoch: # Calculate mAP
修改为:
if RANK in {-1, 0}:
# mAP
callbacks.run('on_train_epoch_end', epoch=epoch)
ema.update_attr(model, include=['yaml', 'nc', 'hyp', 'names', 'stride', 'class_weights'])
final_epoch = (epoch + 1 == epochs) or stopper.possible_stop
if (not noval and epoch >= 4) or final_epoch: # Calculate mAP
注意:实际上只修改了最后一行。本代码以4为例,即:前4个epoch不计算mAP,从第5个epoch开始正常计算mAP。
由于每次迭代计算mAP需要耗费时间,这样设置可以加快迭代速度。
效果如下:
前4次:
第5次: