mirror of
https://github.com/ultralytics/yolov5.git
synced 2025-06-03 14:49:29 +08:00
Validate best.pt
on train end (#4889)
* Validate best.pt on train end * 0.7 iou for COCO only * pass callbacks * active model.float() if not half * print Validating best.pt... * add newline
This commit is contained in:
parent
e687873436
commit
d856c48298
33
train.py
33
train.py
@ -356,9 +356,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
|
|||||||
single_cls=single_cls,
|
single_cls=single_cls,
|
||||||
dataloader=val_loader,
|
dataloader=val_loader,
|
||||||
save_dir=save_dir,
|
save_dir=save_dir,
|
||||||
save_json=is_coco and final_epoch,
|
plots=False,
|
||||||
verbose=nc < 50 and final_epoch,
|
|
||||||
plots=plots and final_epoch,
|
|
||||||
callbacks=callbacks,
|
callbacks=callbacks,
|
||||||
compute_loss=compute_loss)
|
compute_loss=compute_loss)
|
||||||
|
|
||||||
@ -404,23 +402,24 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
|
|||||||
# end training -----------------------------------------------------------------------------------------------------
|
# end training -----------------------------------------------------------------------------------------------------
|
||||||
if RANK in [-1, 0]:
|
if RANK in [-1, 0]:
|
||||||
LOGGER.info(f'\n{epoch - start_epoch + 1} epochs completed in {(time.time() - t0) / 3600:.3f} hours.')
|
LOGGER.info(f'\n{epoch - start_epoch + 1} epochs completed in {(time.time() - t0) / 3600:.3f} hours.')
|
||||||
if not evolve:
|
|
||||||
if is_coco: # COCO dataset
|
|
||||||
for m in [last, best] if best.exists() else [last]: # speed, mAP tests
|
|
||||||
results, _, _ = val.run(data_dict,
|
|
||||||
batch_size=batch_size // WORLD_SIZE * 2,
|
|
||||||
imgsz=imgsz,
|
|
||||||
model=attempt_load(m, device).half(),
|
|
||||||
iou_thres=0.7, # NMS IoU threshold for best pycocotools results
|
|
||||||
single_cls=single_cls,
|
|
||||||
dataloader=val_loader,
|
|
||||||
save_dir=save_dir,
|
|
||||||
save_json=True,
|
|
||||||
plots=False)
|
|
||||||
# Strip optimizers
|
|
||||||
for f in last, best:
|
for f in last, best:
|
||||||
if f.exists():
|
if f.exists():
|
||||||
strip_optimizer(f) # strip optimizers
|
strip_optimizer(f) # strip optimizers
|
||||||
|
if f is best:
|
||||||
|
LOGGER.info(f'\nValidating {f}...')
|
||||||
|
results, _, _ = val.run(data_dict,
|
||||||
|
batch_size=batch_size // WORLD_SIZE * 2,
|
||||||
|
imgsz=imgsz,
|
||||||
|
model=attempt_load(f, device).half(),
|
||||||
|
iou_thres=0.7 if is_coco else 0.6, # best pycocotools results at 0.7
|
||||||
|
single_cls=single_cls,
|
||||||
|
dataloader=val_loader,
|
||||||
|
save_dir=save_dir,
|
||||||
|
save_json=is_coco,
|
||||||
|
verbose=True,
|
||||||
|
plots=True,
|
||||||
|
callbacks=callbacks) # val best model with plots
|
||||||
|
|
||||||
callbacks.run('on_train_end', last, best, plots, epoch)
|
callbacks.run('on_train_end', last, best, plots, epoch)
|
||||||
LOGGER.info(f"Results saved to {colorstr('bold', save_dir)}")
|
LOGGER.info(f"Results saved to {colorstr('bold', save_dir)}")
|
||||||
|
|
||||||
|
3
val.py
3
val.py
@ -133,8 +133,7 @@ def run(data,
|
|||||||
|
|
||||||
# Half
|
# Half
|
||||||
half &= device.type != 'cpu' # half precision only supported on CUDA
|
half &= device.type != 'cpu' # half precision only supported on CUDA
|
||||||
if half:
|
model.half() if half else model.float()
|
||||||
model.half()
|
|
||||||
|
|
||||||
# Configure
|
# Configure
|
||||||
model.eval()
|
model.eval()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user